mirror of
https://github.com/Zippland/Snap-Solver.git
synced 2026-02-08 08:52:07 +08:00
ai factory
This commit is contained in:
391
static/js/main.js
Normal file
391
static/js/main.js
Normal file
@@ -0,0 +1,391 @@
|
||||
class SnapSolver {
|
||||
constructor() {
|
||||
this.initializeElements();
|
||||
this.initializeState();
|
||||
this.setupEventListeners();
|
||||
this.initializeConnection();
|
||||
|
||||
// Initialize managers
|
||||
window.uiManager = new UIManager();
|
||||
window.settingsManager = new SettingsManager();
|
||||
}
|
||||
|
||||
initializeElements() {
|
||||
// Capture elements
|
||||
this.captureBtn = document.getElementById('captureBtn');
|
||||
this.cropBtn = document.getElementById('cropBtn');
|
||||
this.connectionStatus = document.getElementById('connectionStatus');
|
||||
this.screenshotImg = document.getElementById('screenshotImg');
|
||||
this.cropContainer = document.getElementById('cropContainer');
|
||||
this.imagePreview = document.getElementById('imagePreview');
|
||||
this.sendToClaudeBtn = document.getElementById('sendToClaude');
|
||||
this.responseContent = document.getElementById('responseContent');
|
||||
this.claudePanel = document.getElementById('claudePanel');
|
||||
}
|
||||
|
||||
initializeState() {
|
||||
this.socket = null;
|
||||
this.cropper = null;
|
||||
this.croppedImage = null;
|
||||
this.history = JSON.parse(localStorage.getItem('snapHistory') || '[]');
|
||||
}
|
||||
|
||||
updateConnectionStatus(connected) {
|
||||
this.connectionStatus.textContent = connected ? 'Connected' : 'Disconnected';
|
||||
this.connectionStatus.className = `status ${connected ? 'connected' : 'disconnected'}`;
|
||||
this.captureBtn.disabled = !connected;
|
||||
|
||||
if (!connected) {
|
||||
this.imagePreview.classList.add('hidden');
|
||||
this.cropBtn.classList.add('hidden');
|
||||
this.sendToClaudeBtn.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
initializeConnection() {
|
||||
try {
|
||||
this.socket = io(window.location.origin);
|
||||
|
||||
this.socket.on('connect', () => {
|
||||
console.log('Connected to server');
|
||||
this.updateConnectionStatus(true);
|
||||
});
|
||||
|
||||
this.socket.on('disconnect', () => {
|
||||
console.log('Disconnected from server');
|
||||
this.updateConnectionStatus(false);
|
||||
this.socket = null;
|
||||
setTimeout(() => this.initializeConnection(), 5000);
|
||||
});
|
||||
|
||||
this.setupSocketEventHandlers();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Connection error:', error);
|
||||
this.updateConnectionStatus(false);
|
||||
setTimeout(() => this.initializeConnection(), 5000);
|
||||
}
|
||||
}
|
||||
|
||||
setupSocketEventHandlers() {
|
||||
this.socket.on('screenshot_response', (data) => {
|
||||
if (data.success) {
|
||||
this.screenshotImg.src = `data:image/png;base64,${data.image}`;
|
||||
this.imagePreview.classList.remove('hidden');
|
||||
this.cropBtn.classList.remove('hidden');
|
||||
this.captureBtn.disabled = false;
|
||||
this.captureBtn.innerHTML = '<i class="fas fa-camera"></i><span>Capture</span>';
|
||||
this.sendToClaudeBtn.classList.add('hidden');
|
||||
window.showToast('Screenshot captured successfully');
|
||||
} else {
|
||||
window.showToast('Failed to capture screenshot: ' + data.error, 'error');
|
||||
this.captureBtn.disabled = false;
|
||||
this.captureBtn.innerHTML = '<i class="fas fa-camera"></i><span>Capture</span>';
|
||||
}
|
||||
});
|
||||
|
||||
this.socket.on('claude_response', (data) => {
|
||||
console.log('Received claude_response:', data);
|
||||
|
||||
switch (data.status) {
|
||||
case 'started':
|
||||
console.log('Analysis started');
|
||||
this.responseContent.textContent = 'Starting analysis...\n';
|
||||
this.sendToClaudeBtn.disabled = true;
|
||||
break;
|
||||
|
||||
case 'streaming':
|
||||
if (data.content) {
|
||||
console.log('Received content:', data.content);
|
||||
if (this.responseContent.textContent === 'Starting analysis...\n') {
|
||||
this.responseContent.textContent = data.content;
|
||||
} else {
|
||||
this.responseContent.textContent += data.content;
|
||||
}
|
||||
this.responseContent.scrollTo({
|
||||
top: this.responseContent.scrollHeight,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
case 'completed':
|
||||
console.log('Analysis completed');
|
||||
this.responseContent.textContent += '\n\nAnalysis complete.';
|
||||
this.sendToClaudeBtn.disabled = false;
|
||||
this.addToHistory(this.croppedImage, this.responseContent.textContent);
|
||||
window.showToast('Analysis completed successfully');
|
||||
this.responseContent.scrollTo({
|
||||
top: this.responseContent.scrollHeight,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
console.error('Claude analysis error:', data.error);
|
||||
const errorMessage = data.error || 'Unknown error occurred';
|
||||
this.responseContent.textContent += '\n\nError: ' + errorMessage;
|
||||
this.sendToClaudeBtn.disabled = false;
|
||||
this.responseContent.scrollTop = this.responseContent.scrollHeight;
|
||||
window.showToast('Analysis failed: ' + errorMessage, 'error');
|
||||
break;
|
||||
|
||||
default:
|
||||
console.warn('Unknown response status:', data.status);
|
||||
if (data.error) {
|
||||
this.responseContent.textContent += '\n\nError: ' + data.error;
|
||||
this.sendToClaudeBtn.disabled = false;
|
||||
this.responseContent.scrollTop = this.responseContent.scrollHeight;
|
||||
window.showToast('Unknown error occurred', 'error');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.socket.on('connect_error', (error) => {
|
||||
console.error('Connection error:', error);
|
||||
this.updateConnectionStatus(false);
|
||||
this.socket = null;
|
||||
setTimeout(() => this.initializeConnection(), 5000);
|
||||
});
|
||||
}
|
||||
|
||||
initializeCropper() {
|
||||
if (this.cropper) {
|
||||
this.cropper.destroy();
|
||||
this.cropper = null;
|
||||
}
|
||||
|
||||
const cropArea = document.querySelector('.crop-area');
|
||||
cropArea.innerHTML = '';
|
||||
const clonedImage = this.screenshotImg.cloneNode(true);
|
||||
clonedImage.style.display = 'block';
|
||||
cropArea.appendChild(clonedImage);
|
||||
|
||||
this.cropContainer.classList.remove('hidden');
|
||||
|
||||
this.cropper = new Cropper(clonedImage, {
|
||||
viewMode: 1,
|
||||
dragMode: 'move',
|
||||
autoCropArea: 1,
|
||||
restore: false,
|
||||
modal: true,
|
||||
guides: true,
|
||||
highlight: true,
|
||||
cropBoxMovable: true,
|
||||
cropBoxResizable: true,
|
||||
toggleDragModeOnDblclick: false,
|
||||
minContainerWidth: window.innerWidth,
|
||||
minContainerHeight: window.innerHeight - 100,
|
||||
minCropBoxWidth: 100,
|
||||
minCropBoxHeight: 100,
|
||||
background: true,
|
||||
responsive: true,
|
||||
checkOrientation: true,
|
||||
ready: function() {
|
||||
this.cropper.crop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addToHistory(imageData, response) {
|
||||
const historyItem = {
|
||||
id: Date.now(),
|
||||
timestamp: new Date().toISOString(),
|
||||
image: imageData,
|
||||
response: response
|
||||
};
|
||||
this.history.unshift(historyItem);
|
||||
if (this.history.length > 10) this.history.pop();
|
||||
localStorage.setItem('snapHistory', JSON.stringify(this.history));
|
||||
window.renderHistory();
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
// Capture button
|
||||
this.captureBtn.addEventListener('click', async () => {
|
||||
if (!this.socket || !this.socket.connected) {
|
||||
window.showToast('Not connected to server', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.captureBtn.disabled = true;
|
||||
this.captureBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i><span>Capturing...</span>';
|
||||
this.socket.emit('request_screenshot');
|
||||
} catch (error) {
|
||||
window.showToast('Error requesting screenshot: ' + error.message, 'error');
|
||||
this.captureBtn.disabled = false;
|
||||
this.captureBtn.innerHTML = '<i class="fas fa-camera"></i><span>Capture</span>';
|
||||
}
|
||||
});
|
||||
|
||||
// Crop button
|
||||
this.cropBtn.addEventListener('click', () => {
|
||||
if (this.screenshotImg.src) {
|
||||
this.initializeCropper();
|
||||
}
|
||||
});
|
||||
|
||||
// Crop confirm button
|
||||
document.getElementById('cropConfirm').addEventListener('click', () => {
|
||||
if (this.cropper) {
|
||||
try {
|
||||
const canvas = this.cropper.getCroppedCanvas({
|
||||
maxWidth: 4096,
|
||||
maxHeight: 4096,
|
||||
fillColor: '#fff',
|
||||
imageSmoothingEnabled: true,
|
||||
imageSmoothingQuality: 'high',
|
||||
});
|
||||
|
||||
if (!canvas) {
|
||||
throw new Error('Failed to create cropped canvas');
|
||||
}
|
||||
|
||||
this.croppedImage = canvas.toDataURL('image/png');
|
||||
|
||||
this.cropper.destroy();
|
||||
this.cropper = null;
|
||||
this.cropContainer.classList.add('hidden');
|
||||
document.querySelector('.crop-area').innerHTML = '';
|
||||
this.settingsPanel.classList.add('hidden');
|
||||
|
||||
this.screenshotImg.src = this.croppedImage;
|
||||
this.imagePreview.classList.remove('hidden');
|
||||
this.cropBtn.classList.remove('hidden');
|
||||
this.sendToClaudeBtn.classList.remove('hidden');
|
||||
window.showToast('Image cropped successfully');
|
||||
} catch (error) {
|
||||
console.error('Cropping error:', error);
|
||||
window.showToast('Error while cropping image', 'error');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Crop cancel button
|
||||
document.getElementById('cropCancel').addEventListener('click', () => {
|
||||
if (this.cropper) {
|
||||
this.cropper.destroy();
|
||||
this.cropper = null;
|
||||
}
|
||||
this.cropContainer.classList.add('hidden');
|
||||
this.sendToClaudeBtn.classList.add('hidden');
|
||||
document.querySelector('.crop-area').innerHTML = '';
|
||||
});
|
||||
|
||||
// Send to Claude button
|
||||
this.sendToClaudeBtn.addEventListener('click', () => {
|
||||
if (!this.croppedImage) {
|
||||
window.showToast('Please crop the image first', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const settings = window.settingsManager.getSettings();
|
||||
if (!settings.apiKey) {
|
||||
window.showToast('Please enter your API key in settings', 'error');
|
||||
this.settingsPanel.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
this.claudePanel.classList.remove('hidden');
|
||||
this.responseContent.textContent = 'Preparing to analyze image...\n';
|
||||
this.sendToClaudeBtn.disabled = true;
|
||||
|
||||
try {
|
||||
this.socket.emit('analyze_image', {
|
||||
image: this.croppedImage.split(',')[1],
|
||||
settings: {
|
||||
apiKey: settings.apiKey,
|
||||
model: settings.model || 'claude-3-5-sonnet-20241022',
|
||||
temperature: parseFloat(settings.temperature) || 0.7,
|
||||
systemPrompt: settings.systemPrompt || 'You are an expert at analyzing questions and providing detailed solutions.',
|
||||
proxyEnabled: settings.proxyEnabled || false,
|
||||
proxyHost: settings.proxyHost || '127.0.0.1',
|
||||
proxyPort: settings.proxyPort || '4780'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
this.responseContent.textContent += '\nError: Failed to send image for analysis - ' + error.message;
|
||||
this.sendToClaudeBtn.disabled = false;
|
||||
window.showToast('Failed to send image for analysis', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
// Keyboard shortcuts for capture and crop
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.ctrlKey || e.metaKey) {
|
||||
switch(e.key) {
|
||||
case 'c':
|
||||
if (!this.captureBtn.disabled) this.captureBtn.click();
|
||||
break;
|
||||
case 'x':
|
||||
if (!this.cropBtn.disabled) this.cropBtn.click();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the application when the DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
window.app = new SnapSolver();
|
||||
});
|
||||
|
||||
// Global function for history rendering
|
||||
window.renderHistory = function() {
|
||||
const content = document.querySelector('.history-content');
|
||||
const history = JSON.parse(localStorage.getItem('snapHistory') || '[]');
|
||||
|
||||
if (history.length === 0) {
|
||||
content.innerHTML = `
|
||||
<div class="history-empty">
|
||||
<i class="fas fa-history"></i>
|
||||
<p>No history yet</p>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
content.innerHTML = history.map(item => `
|
||||
<div class="history-item" data-id="${item.id}">
|
||||
<div class="history-item-header">
|
||||
<span>${new Date(item.timestamp).toLocaleString()}</span>
|
||||
<button class="btn-icon delete-history" data-id="${item.id}">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
<img src="${item.image}" alt="Historical screenshot" class="history-image">
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
// Add click handlers for history items
|
||||
content.querySelectorAll('.delete-history').forEach(btn => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
const id = parseInt(btn.dataset.id);
|
||||
const updatedHistory = history.filter(item => item.id !== id);
|
||||
localStorage.setItem('snapHistory', JSON.stringify(updatedHistory));
|
||||
window.renderHistory();
|
||||
window.showToast('History item deleted');
|
||||
});
|
||||
});
|
||||
|
||||
content.querySelectorAll('.history-item').forEach(item => {
|
||||
item.addEventListener('click', () => {
|
||||
const historyItem = history.find(h => h.id === parseInt(item.dataset.id));
|
||||
if (historyItem) {
|
||||
window.app.screenshotImg.src = historyItem.image;
|
||||
window.app.imagePreview.classList.remove('hidden');
|
||||
document.getElementById('historyPanel').classList.add('hidden');
|
||||
window.app.cropBtn.classList.add('hidden');
|
||||
window.app.captureBtn.classList.add('hidden');
|
||||
window.app.sendToClaudeBtn.classList.add('hidden');
|
||||
if (historyItem.response) {
|
||||
window.app.claudePanel.classList.remove('hidden');
|
||||
window.app.responseContent.textContent = historyItem.response;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
100
static/js/settings.js
Normal file
100
static/js/settings.js
Normal file
@@ -0,0 +1,100 @@
|
||||
class SettingsManager {
|
||||
constructor() {
|
||||
this.initializeElements();
|
||||
this.loadSettings();
|
||||
this.setupEventListeners();
|
||||
}
|
||||
|
||||
initializeElements() {
|
||||
// Settings panel elements
|
||||
this.settingsPanel = document.getElementById('settingsPanel');
|
||||
this.apiKeyInput = document.getElementById('apiKey');
|
||||
this.modelSelect = document.getElementById('modelSelect');
|
||||
this.temperatureInput = document.getElementById('temperature');
|
||||
this.temperatureValue = document.getElementById('temperatureValue');
|
||||
this.systemPromptInput = document.getElementById('systemPrompt');
|
||||
this.proxyEnabledInput = document.getElementById('proxyEnabled');
|
||||
this.proxyHostInput = document.getElementById('proxyHost');
|
||||
this.proxyPortInput = document.getElementById('proxyPort');
|
||||
this.proxySettings = document.getElementById('proxySettings');
|
||||
|
||||
// Settings toggle elements
|
||||
this.settingsToggle = document.getElementById('settingsToggle');
|
||||
this.closeSettings = document.getElementById('closeSettings');
|
||||
this.toggleApiKey = document.getElementById('toggleApiKey');
|
||||
}
|
||||
|
||||
loadSettings() {
|
||||
const settings = JSON.parse(localStorage.getItem('aiSettings') || '{}');
|
||||
|
||||
if (settings.apiKey) this.apiKeyInput.value = settings.apiKey;
|
||||
if (settings.model) this.modelSelect.value = settings.model;
|
||||
if (settings.temperature) {
|
||||
this.temperatureInput.value = settings.temperature;
|
||||
this.temperatureValue.textContent = settings.temperature;
|
||||
}
|
||||
if (settings.systemPrompt) this.systemPromptInput.value = settings.systemPrompt;
|
||||
if (settings.proxyEnabled !== undefined) {
|
||||
this.proxyEnabledInput.checked = settings.proxyEnabled;
|
||||
}
|
||||
if (settings.proxyHost) this.proxyHostInput.value = settings.proxyHost;
|
||||
if (settings.proxyPort) this.proxyPortInput.value = settings.proxyPort;
|
||||
|
||||
this.proxySettings.style.display = this.proxyEnabledInput.checked ? 'block' : 'none';
|
||||
}
|
||||
|
||||
saveSettings() {
|
||||
const settings = {
|
||||
apiKey: this.apiKeyInput.value,
|
||||
model: this.modelSelect.value,
|
||||
temperature: this.temperatureInput.value,
|
||||
systemPrompt: this.systemPromptInput.value,
|
||||
proxyEnabled: this.proxyEnabledInput.checked,
|
||||
proxyHost: this.proxyHostInput.value,
|
||||
proxyPort: this.proxyPortInput.value
|
||||
};
|
||||
localStorage.setItem('aiSettings', JSON.stringify(settings));
|
||||
window.showToast('Settings saved successfully');
|
||||
}
|
||||
|
||||
getSettings() {
|
||||
return JSON.parse(localStorage.getItem('aiSettings') || '{}');
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
// Save settings on change
|
||||
this.apiKeyInput.addEventListener('change', () => this.saveSettings());
|
||||
this.modelSelect.addEventListener('change', () => this.saveSettings());
|
||||
this.temperatureInput.addEventListener('input', (e) => {
|
||||
this.temperatureValue.textContent = e.target.value;
|
||||
this.saveSettings();
|
||||
});
|
||||
this.systemPromptInput.addEventListener('change', () => this.saveSettings());
|
||||
this.proxyEnabledInput.addEventListener('change', (e) => {
|
||||
this.proxySettings.style.display = e.target.checked ? 'block' : 'none';
|
||||
this.saveSettings();
|
||||
});
|
||||
this.proxyHostInput.addEventListener('change', () => this.saveSettings());
|
||||
this.proxyPortInput.addEventListener('change', () => this.saveSettings());
|
||||
|
||||
// Toggle API key visibility
|
||||
this.toggleApiKey.addEventListener('click', () => {
|
||||
const type = this.apiKeyInput.type === 'password' ? 'text' : 'password';
|
||||
this.apiKeyInput.type = type;
|
||||
this.toggleApiKey.innerHTML = `<i class="fas fa-${type === 'password' ? 'eye' : 'eye-slash'}"></i>`;
|
||||
});
|
||||
|
||||
// Panel visibility
|
||||
this.settingsToggle.addEventListener('click', () => {
|
||||
window.closeAllPanels();
|
||||
this.settingsPanel.classList.toggle('hidden');
|
||||
});
|
||||
|
||||
this.closeSettings.addEventListener('click', () => {
|
||||
this.settingsPanel.classList.add('hidden');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Export for use in other modules
|
||||
window.SettingsManager = SettingsManager;
|
||||
140
static/js/ui.js
Normal file
140
static/js/ui.js
Normal file
@@ -0,0 +1,140 @@
|
||||
class UIManager {
|
||||
constructor() {
|
||||
this.initializeElements();
|
||||
this.setupTheme();
|
||||
this.setupEventListeners();
|
||||
}
|
||||
|
||||
initializeElements() {
|
||||
// Theme elements
|
||||
this.themeToggle = document.getElementById('themeToggle');
|
||||
|
||||
// Panel elements
|
||||
this.settingsPanel = document.getElementById('settingsPanel');
|
||||
this.historyPanel = document.getElementById('historyPanel');
|
||||
this.claudePanel = document.getElementById('claudePanel');
|
||||
|
||||
// History elements
|
||||
this.historyToggle = document.getElementById('historyToggle');
|
||||
this.closeHistory = document.getElementById('closeHistory');
|
||||
|
||||
// Claude panel elements
|
||||
this.closeClaudePanel = document.getElementById('closeClaudePanel');
|
||||
|
||||
// Toast container
|
||||
this.toastContainer = document.getElementById('toastContainer');
|
||||
}
|
||||
|
||||
setupTheme() {
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
|
||||
// Initialize theme
|
||||
const savedTheme = localStorage.getItem('theme');
|
||||
if (savedTheme) {
|
||||
this.setTheme(savedTheme === 'dark');
|
||||
} else {
|
||||
this.setTheme(prefersDark.matches);
|
||||
}
|
||||
|
||||
// Listen for system theme changes
|
||||
prefersDark.addEventListener('change', (e) => this.setTheme(e.matches));
|
||||
}
|
||||
|
||||
setTheme(isDark) {
|
||||
document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
|
||||
this.themeToggle.innerHTML = `<i class="fas fa-${isDark ? 'sun' : 'moon'}"></i>`;
|
||||
localStorage.setItem('theme', isDark ? 'dark' : 'light');
|
||||
}
|
||||
|
||||
showToast(message, type = 'success') {
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast ${type}`;
|
||||
toast.innerHTML = `
|
||||
<i class="fas fa-${type === 'success' ? 'check-circle' : 'exclamation-circle'}"></i>
|
||||
<span>${message}</span>
|
||||
`;
|
||||
this.toastContainer.appendChild(toast);
|
||||
|
||||
setTimeout(() => {
|
||||
toast.style.opacity = '0';
|
||||
setTimeout(() => toast.remove(), 300);
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
closeAllPanels() {
|
||||
this.settingsPanel.classList.add('hidden');
|
||||
this.historyPanel.classList.add('hidden');
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
// Theme toggle
|
||||
this.themeToggle.addEventListener('click', () => {
|
||||
const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
|
||||
this.setTheme(!isDark);
|
||||
});
|
||||
|
||||
// History panel
|
||||
this.historyToggle.addEventListener('click', () => {
|
||||
this.closeAllPanels();
|
||||
this.historyPanel.classList.toggle('hidden');
|
||||
window.renderHistory(); // Call global renderHistory function
|
||||
});
|
||||
|
||||
this.closeHistory.addEventListener('click', () => {
|
||||
this.historyPanel.classList.add('hidden');
|
||||
});
|
||||
|
||||
// Claude panel
|
||||
this.closeClaudePanel.addEventListener('click', () => {
|
||||
this.claudePanel.classList.add('hidden');
|
||||
});
|
||||
|
||||
// Mobile touch events
|
||||
let touchStartX = 0;
|
||||
let touchEndX = 0;
|
||||
|
||||
document.addEventListener('touchstart', (e) => {
|
||||
touchStartX = e.changedTouches[0].screenX;
|
||||
});
|
||||
|
||||
document.addEventListener('touchend', (e) => {
|
||||
touchEndX = e.changedTouches[0].screenX;
|
||||
this.handleSwipe(touchStartX, touchEndX);
|
||||
});
|
||||
|
||||
// Keyboard shortcuts
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.ctrlKey || e.metaKey) {
|
||||
switch(e.key) {
|
||||
case ',':
|
||||
this.settingsPanel.classList.toggle('hidden');
|
||||
break;
|
||||
case 'h':
|
||||
this.historyPanel.classList.toggle('hidden');
|
||||
window.renderHistory();
|
||||
break;
|
||||
}
|
||||
} else if (e.key === 'Escape') {
|
||||
this.closeAllPanels();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
handleSwipe(startX, endX) {
|
||||
const swipeThreshold = 50;
|
||||
const diff = endX - startX;
|
||||
|
||||
if (Math.abs(diff) > swipeThreshold) {
|
||||
if (diff > 0) {
|
||||
this.closeAllPanels();
|
||||
} else {
|
||||
this.settingsPanel.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Export for use in other modules
|
||||
window.UIManager = UIManager;
|
||||
window.showToast = (message, type) => window.uiManager.showToast(message, type);
|
||||
window.closeAllPanels = () => window.uiManager.closeAllPanels();
|
||||
316
static/script.js
316
static/script.js
@@ -1,316 +0,0 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const captureBtn = document.getElementById('captureBtn');
|
||||
const cropBtn = document.getElementById('cropBtn');
|
||||
const connectBtn = document.getElementById('connectBtn');
|
||||
const ipInput = document.getElementById('ipInput');
|
||||
const connectionStatus = document.getElementById('connectionStatus');
|
||||
const screenshotImg = document.getElementById('screenshotImg');
|
||||
const cropContainer = document.getElementById('cropContainer');
|
||||
const claudeActions = document.getElementById('claudeActions');
|
||||
const claudeResponse = document.getElementById('claudeResponse');
|
||||
const responseContent = document.getElementById('responseContent');
|
||||
const aiSettingsToggle = document.getElementById('aiSettingsToggle');
|
||||
const aiSettings = document.getElementById('aiSettings');
|
||||
const temperatureInput = document.getElementById('temperature');
|
||||
const temperatureValue = document.getElementById('temperatureValue');
|
||||
|
||||
let socket = null;
|
||||
let cropper = null;
|
||||
let croppedImage = null;
|
||||
|
||||
// Load saved AI settings
|
||||
function loadAISettings() {
|
||||
const settings = JSON.parse(localStorage.getItem('aiSettings') || '{}');
|
||||
if (settings.apiKey) document.getElementById('apiKey').value = settings.apiKey;
|
||||
if (settings.model) document.getElementById('modelSelect').value = settings.model;
|
||||
if (settings.temperature) {
|
||||
temperatureInput.value = settings.temperature;
|
||||
temperatureValue.textContent = settings.temperature;
|
||||
}
|
||||
if (settings.systemPrompt) document.getElementById('systemPrompt').value = settings.systemPrompt;
|
||||
}
|
||||
|
||||
// Save AI settings
|
||||
function saveAISettings() {
|
||||
const settings = {
|
||||
apiKey: document.getElementById('apiKey').value,
|
||||
model: document.getElementById('modelSelect').value,
|
||||
temperature: temperatureInput.value,
|
||||
systemPrompt: document.getElementById('systemPrompt').value
|
||||
};
|
||||
localStorage.setItem('aiSettings', JSON.stringify(settings));
|
||||
}
|
||||
|
||||
// Initialize settings
|
||||
loadAISettings();
|
||||
|
||||
// AI Settings panel toggle
|
||||
aiSettingsToggle.addEventListener('click', () => {
|
||||
aiSettings.classList.toggle('hidden');
|
||||
});
|
||||
|
||||
// Save settings when changed
|
||||
document.getElementById('apiKey').addEventListener('change', saveAISettings);
|
||||
document.getElementById('modelSelect').addEventListener('change', saveAISettings);
|
||||
temperatureInput.addEventListener('input', (e) => {
|
||||
temperatureValue.textContent = e.target.value;
|
||||
saveAISettings();
|
||||
});
|
||||
document.getElementById('systemPrompt').addEventListener('change', saveAISettings);
|
||||
|
||||
function updateConnectionStatus(connected) {
|
||||
connectionStatus.textContent = connected ? 'Connected' : 'Disconnected';
|
||||
connectionStatus.className = `status ${connected ? 'connected' : 'disconnected'}`;
|
||||
captureBtn.disabled = !connected;
|
||||
cropBtn.disabled = !screenshotImg.src;
|
||||
connectBtn.textContent = connected ? 'Disconnect' : 'Connect';
|
||||
}
|
||||
|
||||
function connectToServer(serverUrl) {
|
||||
if (socket) {
|
||||
socket.disconnect();
|
||||
socket = null;
|
||||
updateConnectionStatus(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
socket = io(serverUrl);
|
||||
|
||||
socket.on('connect', () => {
|
||||
console.log('Connected to server');
|
||||
updateConnectionStatus(true);
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('Disconnected from server');
|
||||
updateConnectionStatus(false);
|
||||
socket = null;
|
||||
});
|
||||
|
||||
socket.on('screenshot_response', (data) => {
|
||||
if (data.success) {
|
||||
screenshotImg.src = `data:image/png;base64,${data.image}`;
|
||||
cropBtn.disabled = false;
|
||||
captureBtn.disabled = false;
|
||||
captureBtn.textContent = 'Capture Screenshot';
|
||||
claudeActions.classList.add('hidden');
|
||||
} else {
|
||||
alert('Failed to capture screenshot: ' + data.error);
|
||||
captureBtn.disabled = false;
|
||||
captureBtn.textContent = 'Capture Screenshot';
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('claude_response', (data) => {
|
||||
if (data.error) {
|
||||
responseContent.textContent += '\nError: ' + data.error;
|
||||
} else {
|
||||
responseContent.textContent += data.content;
|
||||
}
|
||||
responseContent.scrollTop = responseContent.scrollHeight;
|
||||
});
|
||||
|
||||
socket.on('connect_error', (error) => {
|
||||
console.error('Connection error:', error);
|
||||
alert('Failed to connect to server. Please check the IP address and ensure the server is running.');
|
||||
updateConnectionStatus(false);
|
||||
socket = null;
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Connection error:', error);
|
||||
alert('Failed to connect to server: ' + error.message);
|
||||
updateConnectionStatus(false);
|
||||
}
|
||||
}
|
||||
|
||||
function initializeCropper() {
|
||||
if (cropper) {
|
||||
cropper.destroy();
|
||||
cropper = null;
|
||||
}
|
||||
|
||||
// Reset the image container and move it to crop area
|
||||
const cropArea = document.querySelector('.crop-area');
|
||||
cropArea.innerHTML = '';
|
||||
const clonedImage = screenshotImg.cloneNode(true);
|
||||
clonedImage.style.maxWidth = '100%';
|
||||
clonedImage.style.maxHeight = '100%';
|
||||
cropArea.appendChild(clonedImage);
|
||||
|
||||
// Show crop container
|
||||
cropContainer.classList.remove('hidden');
|
||||
|
||||
// Initialize cropper with mobile-friendly settings
|
||||
cropper = new Cropper(clonedImage, {
|
||||
viewMode: 1,
|
||||
dragMode: 'move',
|
||||
autoCropArea: 0.8,
|
||||
restore: false,
|
||||
modal: true,
|
||||
guides: true,
|
||||
highlight: true,
|
||||
cropBoxMovable: true,
|
||||
cropBoxResizable: true,
|
||||
toggleDragModeOnDblclick: false,
|
||||
minContainerWidth: 100,
|
||||
minContainerHeight: 100,
|
||||
minCropBoxWidth: 50,
|
||||
minCropBoxHeight: 50,
|
||||
background: true,
|
||||
responsive: true,
|
||||
checkOrientation: true,
|
||||
ready: function() {
|
||||
// Ensure the cropper is properly sized
|
||||
this.cropper.crop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Capture and Crop Event Listeners
|
||||
connectBtn.addEventListener('click', () => {
|
||||
const serverUrl = ipInput.value.trim();
|
||||
if (!serverUrl) {
|
||||
alert('Please enter the server IP address');
|
||||
return;
|
||||
}
|
||||
if (!serverUrl.startsWith('http://')) {
|
||||
connectToServer('http://' + serverUrl);
|
||||
} else {
|
||||
connectToServer(serverUrl);
|
||||
}
|
||||
});
|
||||
|
||||
cropBtn.addEventListener('click', () => {
|
||||
if (screenshotImg.src) {
|
||||
initializeCropper();
|
||||
}
|
||||
});
|
||||
|
||||
captureBtn.addEventListener('click', async () => {
|
||||
if (!socket || !socket.connected) {
|
||||
alert('Not connected to server');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
captureBtn.disabled = true;
|
||||
captureBtn.textContent = 'Capturing...';
|
||||
socket.emit('request_screenshot');
|
||||
} catch (error) {
|
||||
alert('Error requesting screenshot: ' + error.message);
|
||||
captureBtn.disabled = false;
|
||||
captureBtn.textContent = 'Capture Screenshot';
|
||||
}
|
||||
});
|
||||
|
||||
// Crop confirmation
|
||||
document.getElementById('cropConfirm').addEventListener('click', () => {
|
||||
if (cropper) {
|
||||
try {
|
||||
const canvas = cropper.getCroppedCanvas({
|
||||
maxWidth: 4096,
|
||||
maxHeight: 4096,
|
||||
fillColor: '#fff',
|
||||
imageSmoothingEnabled: true,
|
||||
imageSmoothingQuality: 'high',
|
||||
});
|
||||
|
||||
if (!canvas) {
|
||||
throw new Error('Failed to create cropped canvas');
|
||||
}
|
||||
|
||||
croppedImage = canvas.toDataURL('image/png');
|
||||
|
||||
// Clean up
|
||||
cropper.destroy();
|
||||
cropper = null;
|
||||
cropContainer.classList.add('hidden');
|
||||
document.querySelector('.crop-area').innerHTML = '';
|
||||
|
||||
// Show the cropped image and Claude actions
|
||||
screenshotImg.src = croppedImage;
|
||||
cropBtn.disabled = false;
|
||||
claudeActions.classList.remove('hidden');
|
||||
} catch (error) {
|
||||
console.error('Cropping error:', error);
|
||||
alert('Error while cropping image. Please try again.');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Crop cancellation
|
||||
document.getElementById('cropCancel').addEventListener('click', () => {
|
||||
if (cropper) {
|
||||
cropper.destroy();
|
||||
cropper = null;
|
||||
}
|
||||
cropContainer.classList.add('hidden');
|
||||
claudeActions.classList.add('hidden');
|
||||
document.querySelector('.crop-area').innerHTML = '';
|
||||
});
|
||||
|
||||
// Send to Claude
|
||||
document.getElementById('sendToClaude').addEventListener('click', () => {
|
||||
if (!croppedImage) {
|
||||
alert('Please crop the image first');
|
||||
return;
|
||||
}
|
||||
|
||||
const settings = JSON.parse(localStorage.getItem('aiSettings') || '{}');
|
||||
if (!settings.apiKey) {
|
||||
alert('Please enter your Claude API key in the settings');
|
||||
aiSettings.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
claudeResponse.classList.remove('hidden');
|
||||
responseContent.textContent = 'Analyzing image...';
|
||||
|
||||
socket.emit('analyze_image', {
|
||||
image: croppedImage.split(',')[1],
|
||||
settings: {
|
||||
apiKey: settings.apiKey,
|
||||
model: settings.model || 'claude-3-opus',
|
||||
temperature: parseFloat(settings.temperature) || 0.7,
|
||||
systemPrompt: settings.systemPrompt || 'You are a helpful AI assistant. Analyze the image and provide detailed explanations.'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Close Claude response
|
||||
document.getElementById('closeResponse').addEventListener('click', () => {
|
||||
claudeResponse.classList.add('hidden');
|
||||
responseContent.textContent = '';
|
||||
});
|
||||
|
||||
// Handle touch events for mobile
|
||||
let touchStartX = 0;
|
||||
let touchEndX = 0;
|
||||
|
||||
document.addEventListener('touchstart', (e) => {
|
||||
touchStartX = e.changedTouches[0].screenX;
|
||||
});
|
||||
|
||||
document.addEventListener('touchend', (e) => {
|
||||
touchEndX = e.changedTouches[0].screenX;
|
||||
handleSwipe();
|
||||
});
|
||||
|
||||
function handleSwipe() {
|
||||
const swipeThreshold = 50;
|
||||
const diff = touchEndX - touchStartX;
|
||||
|
||||
if (Math.abs(diff) > swipeThreshold) {
|
||||
if (diff > 0) {
|
||||
// Swipe right - hide panels
|
||||
aiSettings.classList.add('hidden');
|
||||
claudeResponse.classList.add('hidden');
|
||||
} else {
|
||||
// Swipe left - show AI settings
|
||||
aiSettings.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
856
static/style.css
856
static/style.css
@@ -1,226 +1,480 @@
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
:root {
|
||||
/* Light theme colors */
|
||||
--primary-color: #2196F3;
|
||||
--primary-dark: #1976D2;
|
||||
--secondary-color: #4CAF50;
|
||||
--secondary-dark: #45a049;
|
||||
--background: #f8f9fa;
|
||||
--surface: #ffffff;
|
||||
--text-primary: #212121;
|
||||
--text-secondary: #666666;
|
||||
--border-color: #e0e0e0;
|
||||
--shadow-color: rgba(0, 0, 0, 0.1);
|
||||
--error-color: #f44336;
|
||||
--success-color: #4CAF50;
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--primary-color: #64B5F6;
|
||||
--primary-dark: #42A5F5;
|
||||
--secondary-color: #81C784;
|
||||
--secondary-dark: #66BB6A;
|
||||
--background: #121212;
|
||||
--surface: #1E1E1E;
|
||||
--text-primary: #FFFFFF;
|
||||
--text-secondary: #B0B0B0;
|
||||
--border-color: #333333;
|
||||
--shadow-color: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
/* Base Styles */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
background-color: #f0f0f0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
background-color: var(--background);
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
transition: background-color 0.3s, color 0.3s;
|
||||
touch-action: manipulation;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
.app-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.connection-panel {
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 20px;
|
||||
/* Header Styles */
|
||||
.app-header {
|
||||
background-color: var(--surface);
|
||||
padding: 1rem;
|
||||
box-shadow: 0 2px 4px var(--shadow-color);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.header-left h1 {
|
||||
font-size: 1.5rem;
|
||||
color: var(--primary-color);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.connection-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.connection-form {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.status {
|
||||
padding: 8px 16px;
|
||||
border-radius: 20px;
|
||||
font-weight: bold;
|
||||
font-size: 14px;
|
||||
padding: 0.4rem 0.8rem;
|
||||
border-radius: 1rem;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.status.connected {
|
||||
background-color: #4CAF50;
|
||||
background-color: var(--success-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.status.disconnected {
|
||||
background-color: #f44336;
|
||||
background-color: var(--error-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
#ipInput {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
#connectBtn {
|
||||
padding: 8px 16px;
|
||||
font-size: 14px;
|
||||
background-color: #2196F3;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
#connectBtn:hover {
|
||||
background-color: #1976D2;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
.header-right {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
/* Main Content */
|
||||
.app-main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
padding: 1rem;
|
||||
gap: 1rem;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.content-panel {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Capture Section */
|
||||
.capture-section {
|
||||
background-color: var(--surface);
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 2px 4px var(--shadow-color);
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
padding: 0.5rem;
|
||||
background-color: var(--surface);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.toolbar-buttons {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(min-content, max-content));
|
||||
gap: 1rem;
|
||||
justify-content: start;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.analysis-button {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
justify-content: center;
|
||||
margin-bottom: 20px;
|
||||
margin-top: 1rem;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
#captureBtn, #cropBtn {
|
||||
padding: 12px 24px;
|
||||
font-size: 16px;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
min-width: 160px;
|
||||
}
|
||||
|
||||
#captureBtn {
|
||||
background-color: #4CAF50;
|
||||
}
|
||||
|
||||
#captureBtn:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
|
||||
#cropBtn {
|
||||
background-color: #2196F3;
|
||||
}
|
||||
|
||||
#cropBtn:hover {
|
||||
background-color: #1976D2;
|
||||
}
|
||||
|
||||
#captureBtn:disabled, #cropBtn:disabled {
|
||||
background-color: #cccccc;
|
||||
cursor: not-allowed;
|
||||
.image-preview {
|
||||
position: relative;
|
||||
border-radius: 0.5rem;
|
||||
overflow: hidden;
|
||||
background-color: var(--background);
|
||||
margin: 0;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.image-container {
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
min-height: 300px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
#screenshotImg {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#screenshotImg[src] {
|
||||
display: block;
|
||||
width: auto;
|
||||
height: auto;
|
||||
max-width: 100%;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.toggle-button {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
z-index: 1000;
|
||||
padding: 10px;
|
||||
border-radius: 50%;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background: #2196F3;
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
||||
@media (max-width: 768px) {
|
||||
.toolbar-buttons {
|
||||
flex-direction: row;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* Claude Panel */
|
||||
.claude-panel {
|
||||
background-color: var(--surface);
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 2px 4px var(--shadow-color);
|
||||
padding: 1rem;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 20px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.ai-settings {
|
||||
.panel-header h2 {
|
||||
font-size: 1.25rem;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.response-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 1rem;
|
||||
background-color: var(--background);
|
||||
border-radius: 0.5rem;
|
||||
white-space: pre-wrap;
|
||||
font-size: 0.9375rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* Settings Panel */
|
||||
.settings-panel {
|
||||
position: fixed;
|
||||
top: 70px;
|
||||
right: 20px;
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||
z-index: 999;
|
||||
width: 300px;
|
||||
max-width: 90vw;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: 400px;
|
||||
max-width: 100vw;
|
||||
background-color: var(--surface);
|
||||
box-shadow: -2px 0 4px var(--shadow-color);
|
||||
z-index: 1000;
|
||||
transform: translateX(100%);
|
||||
transition: transform 0.3s ease;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ai-settings.hidden {
|
||||
transform: translateX(120%);
|
||||
.settings-panel:not(.hidden) {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.settings-section {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.settings-section h3 {
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 1rem;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
/* Form Elements */
|
||||
.setting-group {
|
||||
margin-bottom: 15px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.setting-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 0.5rem;
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.setting-group input[type="password"],
|
||||
.setting-group input[type="text"],
|
||||
.setting-group select,
|
||||
.setting-group textarea {
|
||||
input[type="text"],
|
||||
input[type="password"],
|
||||
input[type="number"],
|
||||
select,
|
||||
textarea {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
padding: 0.75rem;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 0.375rem;
|
||||
background-color: var(--background);
|
||||
color: var(--text-primary);
|
||||
font-size: 0.9375rem;
|
||||
transition: border-color 0.3s, box-shadow 0.3s;
|
||||
}
|
||||
|
||||
.setting-group input[type="range"] {
|
||||
width: 80%;
|
||||
vertical-align: middle;
|
||||
input:focus,
|
||||
select:focus,
|
||||
textarea:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1);
|
||||
}
|
||||
|
||||
#temperatureValue {
|
||||
display: inline-block;
|
||||
width: 15%;
|
||||
text-align: right;
|
||||
.input-group {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.input-group input {
|
||||
padding-right: 2.5rem;
|
||||
}
|
||||
|
||||
.input-group .btn-icon {
|
||||
position: absolute;
|
||||
right: 0.5rem;
|
||||
}
|
||||
|
||||
.range-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
input[type="range"] {
|
||||
flex: 1;
|
||||
height: 4px;
|
||||
-webkit-appearance: none;
|
||||
background: var(--primary-color);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
input[type="range"]::-webkit-slider-thumb {
|
||||
-webkit-appearance: none;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 50%;
|
||||
background: var(--primary-color);
|
||||
cursor: pointer;
|
||||
border: 2px solid var(--surface);
|
||||
box-shadow: 0 1px 3px var(--shadow-color);
|
||||
}
|
||||
|
||||
.checkbox-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.btn-primary,
|
||||
.btn-secondary,
|
||||
.btn-icon {
|
||||
padding: 0.75rem 1.5rem;
|
||||
border: none;
|
||||
border-radius: 0.375rem;
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: var(--primary-dark);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: var(--background);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background-color: var(--border-color);
|
||||
}
|
||||
|
||||
.btn-icon {
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.375rem;
|
||||
background: transparent;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.btn-icon:hover {
|
||||
background-color: var(--background);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Floating Action Button */
|
||||
.fab {
|
||||
position: fixed;
|
||||
right: 2rem;
|
||||
bottom: 2rem;
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
border-radius: 50%;
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 2px 8px var(--shadow-color);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 1.5rem;
|
||||
transition: transform 0.2s, background-color 0.2s;
|
||||
z-index: 900;
|
||||
}
|
||||
|
||||
.fab:hover {
|
||||
transform: scale(1.05);
|
||||
background-color: var(--primary-dark);
|
||||
}
|
||||
|
||||
/* Toast Notifications */
|
||||
.toast-container {
|
||||
position: fixed;
|
||||
bottom: 2rem;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
z-index: 1000;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.toast {
|
||||
background-color: var(--surface);
|
||||
color: var(--text-primary);
|
||||
padding: 1rem 1.5rem;
|
||||
border-radius: 0.375rem;
|
||||
box-shadow: 0 4px 6px var(--shadow-color);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
pointer-events: auto;
|
||||
animation: toast-in 0.3s ease;
|
||||
}
|
||||
|
||||
.toast.success {
|
||||
border-left: 4px solid var(--success-color);
|
||||
}
|
||||
|
||||
.toast.error {
|
||||
border-left: 4px solid var(--error-color);
|
||||
}
|
||||
|
||||
/* Crop Container */
|
||||
.crop-container {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0,0,0,0.9);
|
||||
background-color: rgba(0, 0, 0, 0.9);
|
||||
z-index: 1000;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
touch-action: none;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.crop-wrapper {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: calc(100% - 80px);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.crop-area {
|
||||
@@ -231,183 +485,193 @@ body {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* Cropper.js custom styles */
|
||||
.cropper-container {
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
max-width: none !important;
|
||||
max-height: none !important;
|
||||
}
|
||||
|
||||
.cropper-wrap-box {
|
||||
background-color: rgba(0,0,0,0.8);
|
||||
}
|
||||
|
||||
.cropper-view-box,
|
||||
.cropper-face {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.cropper-point {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.cropper-point.point-se,
|
||||
.cropper-point.point-sw,
|
||||
.cropper-point.point-ne,
|
||||
.cropper-point.point-nw {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.cropper-line,
|
||||
.cropper-point {
|
||||
background-color: #2196F3;
|
||||
}
|
||||
|
||||
.crop-container.hidden {
|
||||
display: none;
|
||||
.crop-area img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.crop-actions {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 1rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 15px;
|
||||
z-index: 1001;
|
||||
background: rgba(0,0,0,0.8);
|
||||
gap: 10px;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
background-color: var(--surface);
|
||||
}
|
||||
|
||||
.crop-actions .action-button {
|
||||
flex: 1;
|
||||
max-width: 200px;
|
||||
margin: 0 5px;
|
||||
font-size: 16px;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
/* Animations */
|
||||
@keyframes toast-in {
|
||||
from {
|
||||
transform: translateY(100%);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateY(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.crop-actions .action-button.confirm {
|
||||
background-color: #4CAF50;
|
||||
/* Responsive Design */
|
||||
@media (max-width: 768px) {
|
||||
.app-header {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.connection-status {
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.connection-form {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.connection-form input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.settings-panel {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.fab {
|
||||
right: 1rem;
|
||||
bottom: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.crop-actions .action-button.confirm:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 12px 24px;
|
||||
font-size: 16px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
background: #2196F3;
|
||||
color: white;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.action-button:hover {
|
||||
background: #1976D2;
|
||||
}
|
||||
|
||||
.claude-actions {
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.claude-actions.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.claude-response {
|
||||
/* History Panel */
|
||||
.history-panel {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px 8px 0 0;
|
||||
box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
|
||||
z-index: 998;
|
||||
max-height: 50vh;
|
||||
overflow-y: auto;
|
||||
bottom: 0;
|
||||
width: 400px;
|
||||
max-width: 100vw;
|
||||
background-color: var(--surface);
|
||||
box-shadow: -2px 0 4px var(--shadow-color);
|
||||
z-index: 1000;
|
||||
transform: translateX(100%);
|
||||
transition: transform 0.3s ease;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.claude-response.hidden {
|
||||
transform: translateY(100%);
|
||||
.history-panel:not(.hidden) {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.response-header {
|
||||
.history-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.history-empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
color: var(--text-secondary);
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.history-empty i {
|
||||
font-size: 3rem;
|
||||
}
|
||||
|
||||
.history-item {
|
||||
background-color: var(--background);
|
||||
border-radius: 0.5rem;
|
||||
padding: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
position: relative;
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.history-item:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 2px 8px var(--shadow-color);
|
||||
}
|
||||
|
||||
.history-item[data-has-response="true"]::after {
|
||||
content: "Has Analysis";
|
||||
position: absolute;
|
||||
top: 0.5rem;
|
||||
right: 0.5rem;
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 1rem;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.history-item-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
margin-bottom: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.response-header h3 {
|
||||
.history-image {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
border-radius: 0.25rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.history-response {
|
||||
background-color: var(--background);
|
||||
border-radius: 0.5rem;
|
||||
padding: 1rem;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.history-response h4 {
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 0.5rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.history-response pre {
|
||||
white-space: pre-wrap;
|
||||
font-family: inherit;
|
||||
font-size: 0.9375rem;
|
||||
line-height: 1.6;
|
||||
color: var(--text-secondary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.close-button {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
color: #666;
|
||||
/* Utility Classes */
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.response-content {
|
||||
white-space: pre-wrap;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
body {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.connection-panel {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
#ipInput {
|
||||
/* Additional Responsive Styles */
|
||||
@media (max-width: 768px) {
|
||||
.history-panel {
|
||||
width: 100%;
|
||||
max-width: 300px;
|
||||
}
|
||||
|
||||
.toggle-button {
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
}
|
||||
|
||||
.ai-settings {
|
||||
top: 60px;
|
||||
right: 10px;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.crop-actions {
|
||||
bottom: 10px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
padding: 10px 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.claude-response {
|
||||
padding: 15px;
|
||||
max-height: 60vh;
|
||||
.history-item {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user