|
|
|
|
|
|
|
|
|
|
|
import { Logger } from '../core/logger.js'; |
|
|
|
|
|
export class DOMManager { |
|
|
constructor() { |
|
|
this.elements = {}; |
|
|
} |
|
|
|
|
|
setupDOMReferences() { |
|
|
|
|
|
this.elements = { |
|
|
|
|
|
questionInput: document.getElementById('questionInput'), |
|
|
imageInput: document.getElementById('imageInput'), |
|
|
imagePreview: document.getElementById('imagePreview'), |
|
|
|
|
|
|
|
|
solveBtn: document.getElementById('solveBtn'), |
|
|
interruptBtn: document.getElementById('interruptBtn'), |
|
|
settingsBtn: document.getElementById('settingsBtn'), |
|
|
downloadBtn: document.getElementById('downloadBtn'), |
|
|
newSessionBtn: document.getElementById('newSessionBtn'), |
|
|
|
|
|
|
|
|
chatArea: document.getElementById('chatArea'), |
|
|
statusIndicator: document.getElementById('statusIndicator'), |
|
|
progressContainer: document.getElementById('progressContainer'), |
|
|
progressFill: document.getElementById('progressFill'), |
|
|
sessionInfo: document.getElementById('sessionInfo'), |
|
|
|
|
|
|
|
|
settingsModal: document.getElementById('settingsModal'), |
|
|
settingsForm: document.getElementById('settingsForm'), |
|
|
closeBtn: document.querySelector('.close'), |
|
|
|
|
|
|
|
|
modelSelect: document.getElementById('modelSelect'), |
|
|
generatorModelSelect: document.getElementById('generatorModelSelect'), |
|
|
criticModelSelect: document.getElementById('criticModelSelect'), |
|
|
openaiApiKeyInput: document.getElementById('openaiApiKeyInput'), |
|
|
googleApiKeyInput: document.getElementById('googleApiKeyInput'), |
|
|
anthropicApiKeyInput: document.getElementById('anthropicApiKeyInput'), |
|
|
maxIterations: document.getElementById('maxIterations'), |
|
|
temperature: document.getElementById('temperature'), |
|
|
maxTokens: document.getElementById('maxTokens'), |
|
|
maxExecutionTime: document.getElementById('maxExecutionTime'), |
|
|
pipsModeSwitch: document.getElementById('pipsModeSwitch'), |
|
|
pipsModeAgent: document.getElementById('pipsModeAgent'), |
|
|
pipsModeInteractive: document.getElementById('pipsModeInteractive'), |
|
|
modeDescription: document.getElementById('modeDescription'), |
|
|
customRules: document.getElementById('customRules'), |
|
|
customRulesSettings: document.getElementById('customRulesSettings'), |
|
|
|
|
|
|
|
|
sessionsToggle: document.getElementById('sessionsToggle'), |
|
|
sessionsContainer: document.getElementById('sessionsContainer'), |
|
|
sessionsList: document.getElementById('sessionsList'), |
|
|
clearSessionsBtn: document.getElementById('clearSessionsBtn'), |
|
|
exportSessionsBtn: document.getElementById('exportSessionsBtn'), |
|
|
importSessionsBtn: document.getElementById('importSessionsBtn'), |
|
|
importSessionsInput: document.getElementById('importSessionsInput'), |
|
|
|
|
|
|
|
|
imageUpload: document.querySelector('.image-upload'), |
|
|
imageUploadBtn: document.querySelector('.image-upload-btn') |
|
|
}; |
|
|
|
|
|
|
|
|
const criticalElements = [ |
|
|
'questionInput', 'solveBtn', 'chatArea', 'statusIndicator' |
|
|
]; |
|
|
|
|
|
for (const elementName of criticalElements) { |
|
|
if (!this.elements[elementName]) { |
|
|
Logger.error(`Critical element missing: ${elementName}`); |
|
|
} |
|
|
} |
|
|
|
|
|
Logger.debug('DOM', 'DOM references set up successfully'); |
|
|
} |
|
|
|
|
|
async initializeIcons() { |
|
|
try { |
|
|
if (typeof feather !== 'undefined') { |
|
|
feather.replace(); |
|
|
Logger.log('Feather icons initialized successfully'); |
|
|
} else { |
|
|
Logger.warn('Feather icons library not found'); |
|
|
} |
|
|
} catch (e) { |
|
|
Logger.error('Error initializing Feather icons:', e); |
|
|
} |
|
|
} |
|
|
|
|
|
updateStatus(message, type = 'info') { |
|
|
this.elements.statusIndicator.textContent = message; |
|
|
this.elements.statusIndicator.className = `status-bar show ${type}`; |
|
|
|
|
|
|
|
|
if (type !== 'error') { |
|
|
setTimeout(() => { |
|
|
this.elements.statusIndicator.classList.remove('show'); |
|
|
}, 5000); |
|
|
} |
|
|
} |
|
|
|
|
|
updateSessionInfo(text) { |
|
|
this.elements.sessionInfo.textContent = text; |
|
|
} |
|
|
|
|
|
resetSolvingState() { |
|
|
this.elements.solveBtn.style.display = 'inline-flex'; |
|
|
this.elements.interruptBtn.style.display = 'none'; |
|
|
this.elements.questionInput.disabled = false; |
|
|
this.elements.progressContainer.classList.remove('show'); |
|
|
this.elements.progressFill.style.width = '0%'; |
|
|
} |
|
|
|
|
|
setSolvingState() { |
|
|
this.elements.solveBtn.style.display = 'none'; |
|
|
this.elements.interruptBtn.style.display = 'inline-flex'; |
|
|
this.elements.questionInput.disabled = true; |
|
|
this.elements.progressContainer.classList.add('show'); |
|
|
} |
|
|
|
|
|
updateProgress(progress) { |
|
|
if (progress !== undefined) { |
|
|
this.elements.progressFill.style.width = `${progress}%`; |
|
|
} |
|
|
} |
|
|
|
|
|
clearInputs() { |
|
|
this.elements.questionInput.value = ''; |
|
|
this.elements.imagePreview.style.display = 'none'; |
|
|
} |
|
|
|
|
|
getElement(name) { |
|
|
return this.elements[name]; |
|
|
} |
|
|
|
|
|
getAllElements() { |
|
|
return this.elements; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export const domManager = new DOMManager(); |
|
|
|