const setActiveMode = (mode) => { const isFrame = mode === 'frame'; if (frameModeBtn) { frameModeBtn.classList.toggle('is-active', isFrame); frameModeBtn.setAttribute('aria-pressed', isFrame ? 'true' : 'false'); } if (colorModeBtn) { colorModeBtn.classList.toggle('is-active', !isFrame); colorModeBtn.setAttribute('aria-pressed', !isFrame ? 'true' : 'false'); } if (modeIndicator) { modeIndicator.textContent = isFrame ? 'Работаем с рамкой' : 'Изменяем цвет рамки'; } }; colorButtons.forEach((button) => { button.addEventListener('click', () => handleSwatchClick(button)); }); if (resetButton) { resetButton.addEventListener('click', resetColors); } if (themeToggle) { themeToggle.addEventListener('change', () => { applyTheme(themeToggle.checked ? 'dark' : 'light'); }); } if (colorModeBtn) { colorModeBtn.addEventListener('click', () => { setActiveMode('color'); }); } if (rotateButton) { rotateButton.addEventListener('click', (event) => { event.preventDefault(); const nextState = !framePreview?.classList.contains('is-rotated'); applyRotation(nextState); }); } const storedImage = storage.get('selectedImage'); if (storedImage) { setImage(storedImage); } else { setImage(''); } const storedColor = storage.get(STORAGE_KEYS.color); if (storedColor) { const normalized = normalizeHex(storedColor); applyColor(normalized, { persist: false }); setActiveSwatchByColor(normalized); } else { applyColor(DEFAULTS.color, { persist: false }); setActiveSwatchByColor(normalizeHex(DEFAULTS.color)); } const storedTheme = storage.get(STORAGE_KEYS.theme); applyTheme(storedTheme === 'dark' ? 'dark' : DEFAULTS.theme, { persist: false }); const storedRotation = storage.get(STORAGE_KEYS.rotation); applyRotation(storedRotation === 'rotated', { persist: false }); setActiveMode('color'); });