Spaces:
Running
Running
File size: 6,059 Bytes
bfb2f26 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | // Shared JavaScript across all pages
class ThemeManager {
constructor() {
this.currentTheme = localStorage.getItem('theme') || 'light';
this.currentPalette = localStorage.getItem('palette') || 'her';
this.init();
}
init() {
this.applyTheme(this.currentTheme);
this.applyPalette(this.currentPalette);
this.setupEventListeners();
}
applyTheme(theme) {
document.documentElement.classList.remove('light', 'dark');
document.documentElement.classList.add(theme);
localStorage.setItem('theme', theme);
}
applyPalette(palette) {
document.documentElement.classList.remove('theme-her', 'theme-lost', 'theme-blade');
document.documentElement.classList.add(`theme-${palette}`);
localStorage.setItem('palette', palette);
}
setupEventListeners() {
// Theme toggles will be handled by individual components
}
toggleTheme() {
const newTheme = this.currentTheme === 'light' ? 'dark' : 'light';
this.currentTheme = newTheme;
this.applyTheme(newTheme);
}
setPalette(palette) {
this.currentPalette = palette;
this.applyPalette(palette);
}
}
// Initialize theme manager
const themeManager = new ThemeManager();
// Chat functionality
class ChatManager {
constructor() {
this.messages = [];
this.isStreaming = false;
}
addMessage(content, isUser = false) {
const message = {
id: Date.now(),
content,
isUser,
timestamp: new Date()
};
this.messages.push(message);
this.renderMessage(message);
}
renderMessage(message) {
// Implementation will be page-specific
}
streamMessage(content, callback) {
this.isStreaming = true;
// Simulate streaming for demo
const words = content.split(' ');
let currentContent = '';
const streamInterval = setInterval(() => {
if (words.length === 0) {
clearInterval(streamInterval);
this.isStreaming = false;
if (callback) callback();
return;
}
currentContent += words.shift() + ' ';
// Update message content in UI
const messageElement = document.querySelector(`[data-message-id="${message.id}"]`);
if (messageElement) {
messageElement.textContent = currentContent;
}
}, 50);
}
}
// Responsive utilities
class ResponsiveManager {
constructor() {
this.currentBreakpoint = this.getBreakpoint();
this.init();
}
init() {
this.setupResizeListener();
}
getBreakpoint() {
const width = window.innerWidth;
if (width <= 480) return 'xs';
if (width <= 768) return 'sm';
if (width <= 1024) return 'md';
if (width <= 1440) return 'lg';
return 'xl';
}
setupResizeListener() {
let resizeTimeout;
window.addEventListener('resize', () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(() => {
const newBreakpoint = this.getBreakpoint();
if (newBreakpoint !== this.currentBreakpoint) {
this.currentBreakpoint = newBreakpoint;
this.onBreakpointChange(newBreakpoint);
}
}, 100);
});
}
onBreakpointChange(breakpoint) {
// Dispatch custom event for components to listen to
window.dispatchEvent(new CustomEvent('breakpointChange', {
detail: { breakpoint }
}));
}
}
// Initialize responsive manager
const responsiveManager = new ResponsiveManager();
// Utility functions
const utils = {
debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
},
throttle(func, limit) {
let inThrottle;
return function() {
const args = arguments;
const context = this;
if (!inThrottle) {
func.apply(context, args);
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
};
},
formatTime(seconds) {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${mins}:${secs.toString().padStart(2, '0')}`;
},
generateId() {
return Date.now().toString(36) + Math.random().toString(36).substr(2);
}
};
// API integration
class APIManager {
constructor() {
this.baseURL = 'https://api.auraforge.ai/v1';
}
async makeRequest(endpoint, options = {}) {
try {
const response = await fetch(`${this.baseURL}${endpoint}`, {
headers: {
'Content-Type': 'application/json',
...options.headers
},
...options
});
if (!response.ok) {
throw new Error(`API request failed: ${response.statusText}`);
}
return await response.json();
}
async getInterviews() {
return this.makeRequest('/interviews');
}
async getVoices() {
return this.makeRequest('/voices');
}
async startInterview(type, options = {}) {
return this.makeRequest(`/interviews/${type}/start`, {
method: 'POST',
body: JSON.stringify(options)
});
}
}
// Initialize API manager
const apiManager = new APIManager();
// Export for use in components
window.ThemeManager = themeManager;
window.ChatManager = ChatManager;
window.ResponsiveManager = responsiveManager;
window.APIManager = apiManager;
window.utils = utils;
console.log('AuraForge AI loaded successfully'); |