UNPKG

mcp-quiz-server

Version:

🧠 AI-Powered Quiz Management via Model Context Protocol (MCP) - Create, manage, and take quizzes directly from VS Code, Claude, and other AI agents.

335 lines • 13.1 kB
import { SettingsManager } from './SettingsManager'; export class DemoConfigService { static async initialize() { if (this.initialized) return; await this.loadBuiltInConfigs(); this.loadFromURLParams(); this.initialized = true; console.log('🎬 DemoConfigService initialized with configs:', Array.from(this.configs.keys())); } static async loadBuiltInConfigs() { const builtInConfigs = [ { name: 'accessibility-demo', description: 'Settings optimized for accessibility and screen reader testing', settings: { ui: { theme: 'high-contrast', fontSize: 'large', navigationVisible: true, reducedMotion: true, animations: false, celebration: false, announceChanges: true, }, accessibility: { screenReaderMode: true, keyboardNavigation: true, skipLinks: true, highContrast: true, }, quiz: { viewMode: 'single', autoAdvance: { enabled: false, delaySeconds: 5, showCountdown: true, }, showProgress: true, largeButtons: true, preloadQuestions: true, minimalUI: false, }, }, metadata: { createdBy: 'UX Team', purpose: 'Accessibility compliance testing', tags: ['accessibility', 'demo', 'testing', 'screen-reader'], lastUpdated: '2025-07-25', version: '1.0', }, }, { name: 'performance-demo', description: 'Lightweight settings optimized for speed and minimal resource usage', settings: { ui: { theme: 'light', fontSize: 'medium', navigationVisible: false, reducedMotion: true, animations: false, celebration: false, announceChanges: false, }, quiz: { viewMode: 'single', autoAdvance: { enabled: true, delaySeconds: 1, showCountdown: false, }, showProgress: false, largeButtons: false, preloadQuestions: false, minimalUI: true, }, performance: { lazyLoading: true, compactMode: true, disableAnalytics: true, cacheOptimized: true, }, }, metadata: { createdBy: 'Performance Team', purpose: 'Performance testing and benchmarking', tags: ['performance', 'demo', 'speed', 'minimal'], lastUpdated: '2025-07-25', version: '1.0', }, }, { name: 'educator-demo', description: 'Settings optimized for educational environments', settings: { ui: { theme: 'light', fontSize: 'large', navigationVisible: true, reducedMotion: false, animations: true, celebration: true, announceChanges: true, }, quiz: { viewMode: 'single', autoAdvance: { enabled: false, delaySeconds: 5, showCountdown: true, }, showProgress: true, largeButtons: true, preloadQuestions: true, minimalUI: false, }, accessibility: { screenReaderMode: false, keyboardNavigation: true, skipLinks: true, highContrast: false, }, }, metadata: { createdBy: 'Education Team', purpose: 'Classroom and educational environment usage', tags: ['education', 'demo', 'classroom', 'teaching'], lastUpdated: '2025-07-25', version: '1.0', }, }, { name: 'mobile-demo', description: 'Settings optimized for mobile devices', settings: { ui: { theme: 'system', fontSize: 'large', navigationVisible: false, reducedMotion: false, animations: true, celebration: true, announceChanges: false, }, quiz: { viewMode: 'single', autoAdvance: { enabled: false, delaySeconds: 3, showCountdown: true, }, showProgress: true, largeButtons: true, preloadQuestions: true, minimalUI: false, }, performance: { lazyLoading: true, compactMode: false, disableAnalytics: false, cacheOptimized: true, }, }, metadata: { createdBy: 'Mobile Team', purpose: 'Mobile device optimization', tags: ['mobile', 'demo', 'touch', 'responsive'], lastUpdated: '2025-07-25', version: '1.0', }, }, ]; builtInConfigs.forEach(config => { this.configs.set(config.name, config); }); await this.loadExternalConfigs(); } static async loadExternalConfigs() { const configFiles = [ '/config/demo-configs/accessibility-demo.json', '/config/demo-configs/performance-demo.json', ]; for (const file of configFiles) { try { const response = await fetch(file); if (response.ok) { const config = await response.json(); this.configs.set(config.name, config); console.log(`📋 Loaded external config: ${config.name}`); } } catch (error) { console.warn(`Failed to load external config: ${file}`, error); } } } static loadFromURLParams() { const urlParams = new URLSearchParams(window.location.search); const configParam = urlParams.get('config'); const settingsParam = urlParams.get('settings'); if (configParam) { try { if (configParam.startsWith('{')) { const inlineConfig = JSON.parse(decodeURIComponent(configParam)); this.applyConfigurationNow(inlineConfig); console.log('🔗 Applied inline URL configuration'); } else { const config = this.configs.get(configParam); if (config) { this.applyDemoConfig(configParam); console.log(`🔗 Applied URL demo config: ${configParam}`); } else { console.warn(`🔗 URL config not found: ${configParam}`); } } } catch (error) { console.error('🔗 Failed to parse URL configuration:', error); } } if (settingsParam) { try { const settings = JSON.parse(decodeURIComponent(settingsParam)); this.applyConfigurationNow(settings); console.log('🔗 Applied URL settings parameter'); } catch (error) { console.error('🔗 Failed to parse URL settings:', error); } } } static applyDemoConfig(configName) { const config = this.configs.get(configName); if (!config) { console.error(`Demo config not found: ${configName}`); return false; } return this.applyConfigurationNow(config.settings); } static applyConfigurationNow(settings) { try { const settingsManager = SettingsManager.getInstance(); settingsManager.applyBulkSettings(settings); return true; } catch (error) { console.error('Failed to apply configuration:', error); return false; } } static getAvailableConfigs() { return Array.from(this.configs.values()); } static getConfig(name) { return this.configs.get(name); } static addCustomConfig(config) { this.configs.set(config.name, config); console.log(`➕ Added custom demo config: ${config.name}`); } static removeConfig(name) { const removed = this.configs.delete(name); if (removed) { console.log(`➖ Removed demo config: ${name}`); } return removed; } static generateShareableURL(baseURL) { const settingsManager = SettingsManager.getInstance(); const currentSettings = settingsManager.getSettings(); const url = new URL(baseURL || window.location.href); url.searchParams.set('settings', encodeURIComponent(JSON.stringify(currentSettings))); return url.toString(); } static generateDemoURL(configName, baseURL) { const url = new URL(baseURL || window.location.href); url.searchParams.set('config', configName); return url.toString(); } static generateInlineConfigURL(settings, baseURL) { const url = new URL(baseURL || window.location.href); url.searchParams.set('config', encodeURIComponent(JSON.stringify(settings))); return url.toString(); } static exportConfig(configName) { const config = this.configs.get(configName); if (!config) { return null; } return JSON.stringify(config, null, 2); } static importConfig(jsonString) { try { const config = JSON.parse(jsonString); if (this.validateConfig(config)) { this.addCustomConfig(config); return true; } return false; } catch (error) { console.error('Failed to import demo config:', error); return false; } } static validateConfig(config) { return (typeof config === 'object' && typeof config.name === 'string' && typeof config.description === 'string' && typeof config.settings === 'object' && config.settings !== null); } static clearURLParams() { const url = new URL(window.location.href); url.searchParams.delete('config'); url.searchParams.delete('settings'); window.history.replaceState({}, document.title, url.toString()); console.log('🔗 Cleared URL configuration parameters'); } static getConfigsByTag(tag) { return Array.from(this.configs.values()).filter(config => config.metadata?.tags?.includes(tag)); } static searchConfigs(query) { const lowerQuery = query.toLowerCase(); return Array.from(this.configs.values()).filter(config => config.name.toLowerCase().includes(lowerQuery) || config.description.toLowerCase().includes(lowerQuery) || config.metadata?.tags?.some(tag => tag.toLowerCase().includes(lowerQuery))); } } DemoConfigService.configs = new Map(); DemoConfigService.initialized = false; //# sourceMappingURL=DemoConfigService.js.map