MD
MD2Card
Theme Design

MD2Card Theme System Design and Implementation

J
JsonChao
MD2Card Theme System Specialist
January 20, 2025
15 min read
Theme SystemCSSDesign PatternsUser ExperienceCustomization

MD2Card Theme System Design and Implementation

The MD2Card theme system is one of the most popular features, supporting over 20 beautiful themes that allow users to create unique knowledge cards with personal style. This article takes you through the design philosophy and implementation details of this powerful system.

🎨 Design Philosophy

Core Principles

The MD2Card theme system is built on four essential principles:

  1. High Customizability: Every aspect of a theme can be modified
  2. High Performance: Theme switching must occur in real-time
  3. Consistency: All themes follow the same standards
  4. Aesthetics: Focus on beautiful and modern design

Theme Categorization

// Theme categorization
const themeCategories = {
  business: ['executive', 'corporate', 'minimal'],
  creative: ['neon', 'gradient', 'artistic'],
  academic: ['paper', 'scholarly', 'clean'],
  modern: ['glassmorphism', 'neumorphism', 'dark'],
  vintage: ['retro', 'classic', 'aged']
};

🏗️ System Architecture

Theme Structure

Each theme consists of essential components:

// Standard theme structure
const themeStructure = {
  // Metadata
  id: 'unique-theme-id',
  name: 'Display Theme Name',
  category: 'Category',
  description: 'Theme Description',
  
  // Main styles
  background: 'Background',
  color: 'Text Color',
  fontFamily: 'Font',
  
  // Layout
  borderRadius: 'Border Radius',
  padding: 'Padding',
  margin: 'Margin',
  
  // Effects
  boxShadow: 'Shadow',
  backdropFilter: 'Backdrop Filter',
  border: 'Border',
  
  // Custom CSS
  customCSS: 'Special Styles'
};

Example Theme: Glassmorphism

// Glassmorphism Theme - Popular modern theme
const glassmorphismTheme = {
  id: 'glassmorphism',
  name: 'Glassmorphism',
  category: 'Modern',
  description: 'Modern glass theme with blur effect and transparency',
  
  // Gradient background
  background: `
    linear-gradient(135deg, 
      rgba(255, 255, 255, 0.1), 
      rgba(255, 255, 255, 0.05)
    )
  `,
  
  // Clear text color
  color: '#ffffff',
  
  // Modern font
  fontFamily: `
    "SF Pro Display", 
    -apple-system, 
    BlinkMacSystemFont, 
    "Segoe UI", 
    Roboto, 
    sans-serif
  `,
  
  // Layout
  borderRadius: '20px',
  padding: '2rem',
  
  // Special effects
  backdropFilter: 'blur(20px) saturate(180%)',
  boxShadow: `
    0 8px 32px 0 rgba(31, 38, 135, 0.37),
    inset 0 1px 0 rgba(255, 255, 255, 0.1)
  `,
  border: '1px solid rgba(255, 255, 255, 0.18)',
  
  // Special CSS for specific elements
  customCSS: `
    .card-header {
      background: rgba(255, 255, 255, 0.1);
      backdrop-filter: blur(10px);
      border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .card-content {
      background: rgba(255, 255, 255, 0.05);
    }
    
    .card-footer {
      background: linear-gradient(
        90deg, 
        rgba(255, 255, 255, 0.1), 
        rgba(255, 255, 255, 0.05)
      );
    }
  `
};

🔧 Theme System Implementation

Theme Engine

// Theme processing engine
class ThemeEngine {
  constructor() {
    this.currentTheme = null;
    this.observers = [];
  }
  
  // Apply theme
  applyTheme(theme) {
    this.currentTheme = theme;
    this.processTheme(theme);
    this.notifyObservers(theme);
  }
  
  // Process theme
  processTheme(theme) {
    const element = document.getElementById('card-preview');
    
    // Apply base styles
    this.applyBaseStyles(element, theme);
    
    // Apply special effects
    this.applyEffects(element, theme);
    
    // Inject custom CSS
    this.injectCustomCSS(theme.customCSS);
    
    // Add animation
    this.addTransitionEffect(element);
  }
  
  // Apply base styles
  applyBaseStyles(element, theme) {
    Object.assign(element.style, {
      background: theme.background,
      color: theme.color,
      fontFamily: theme.fontFamily,
      borderRadius: theme.borderRadius,
      padding: theme.padding,
      boxShadow: theme.boxShadow,
      border: theme.border,
      backdropFilter: theme.backdropFilter
    });
  }
  
  // Add transition effect
  addTransitionEffect(element) {
    element.style.transition = 'all 0.3s cubic-bezier(0.4, 0, 0.2, 1)';
    element.style.transform = 'scale(0.98)';
    
    requestAnimationFrame(() => {
      element.style.transform = 'scale(1)';
    });
  }
  
  // Observe theme changes
  subscribe(callback) {
    this.observers.push(callback);
  }
  
  notifyObservers(theme) {
    this.observers.forEach(callback => callback(theme));
  }
}

1. Executive Theme

const executiveTheme = {
  id: 'executive',
  name: 'Executive',
  category: 'Business',
  description: 'Professional theme for executives and business presentations',
  
  background: `
    linear-gradient(145deg, 
      #1a1a2e 0%, 
      #16213e 50%, 
      #0f3460 100%
    )
  `,
  color: '#ffffff',
  fontFamily: '"Georgia", "Times New Roman", serif',
  
  borderRadius: '12px',
  padding: '2.5rem',
  
  boxShadow: `
    0 25px 50px -12px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.1)
  `,
  
  customCSS: `
    .card-title {
      font-size: 2.5rem;
      font-weight: 700;
      margin-bottom: 1rem;
      background: linear-gradient(45deg, #ffd700, #ffed4e);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
    
    .card-content {
      line-height: 1.8;
      font-size: 1.1rem;
    }
  `
};

2. Neon Theme

const neonTheme = {
  id: 'neon',
  name: 'Neon',
  category: 'Creative',
  description: 'Bright neon colors for standout design',
  
  background: `
    radial-gradient(
      ellipse at center,
      #0a0a0a 0%,
      #1a1a1a 50%,
      #000 100%
    )
  `,
  color: '#00ffff',
  fontFamily: '"Orbitron", "Courier New", monospace',
  
  borderRadius: '15px',
  padding: '2rem',
  
  border: '2px solid #00ffff',
  boxShadow: `
    0 0 20px #00ffff,
    0 0 40px #00ffff,
    0 0 60px #00ffff,
    inset 0 0 20px rgba(0, 255, 255, 0.1)
  `,
  
  customCSS: `
    .card-title {
      text-shadow: 
        0 0 10px #00ffff,
        0 0 20px #00ffff,
        0 0 30px #00ffff;
      animation: neonGlow 2s ease-in-out infinite alternate;
    }
    
    @keyframes neonGlow {
      from {
        text-shadow: 
          0 0 10px #00ffff,
          0 0 20px #00ffff,
          0 0 30px #00ffff;
      }
      to {
        text-shadow: 
          0 0 5px #00ffff,
          0 0 10px #00ffff,
          0 0 15px #00ffff;
      }
    }
    
    .card-content {
      border-left: 3px solid #ff00ff;
      padding-left: 1rem;
      box-shadow: -5px 0 10px rgba(255, 0, 255, 0.3);
    }
  `
};

🛠️ Custom Theme Creation

Theme Builder

// Theme Builder - Tool for creating themes
class ThemeBuilder {
  constructor() {
    this.theme = this.getDefaultTheme();
  }
  
  getDefaultTheme() {
    return {
      id: '',
      name: '',
      category: 'custom',
      description: '',
      background: '#ffffff',
      color: '#000000',
      fontFamily: 'Arial, sans-serif',
      borderRadius: '8px',
      padding: '1rem',
      customCSS: ''
    };
  }
  
  // Set background
  setBackground(background) {
    this.theme.background = background;
    return this;
  }
  
  // Set text color
  setTextColor(color) {
    this.theme.color = color;
    return this;
  }
  
  // Set font
  setFont(fontFamily) {
    this.theme.fontFamily = fontFamily;
    return this;
  }
  
  // Add effect
  addEffect(property, value) {
    this.theme[property] = value;
    return this;
  }
  
  // Add custom CSS
  addCustomCSS(css) {
    this.theme.customCSS += css;
    return this;
  }
  
  // Build theme
  build() {
    return { ...this.theme };
  }
  
  // Usage example
  static createGradientTheme() {
    return new ThemeBuilder()
      .setBackground('linear-gradient(45deg, #ff6b6b, #4ecdc4)')
      .setTextColor('#ffffff')
      .setFont('"Roboto", sans-serif')
      .addEffect('borderRadius', '15px')
      .addEffect('boxShadow', '0 10px 30px rgba(0,0,0,0.3)')
      .addCustomCSS(`
        .card-title {
          text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }
      `)
      .build();
  }
}

📱 Responsive Design

Responsive Theme System

// Responsive Theme System
class ResponsiveThemeSystem {
  constructor() {
    this.breakpoints = {
      mobile: '(max-width: 768px)',
      tablet: '(min-width: 769px) and (max-width: 1024px)',
      desktop: '(min-width: 1025px)'
    };
  }
  
  createResponsiveTheme(baseTheme) {
    return {
      ...baseTheme,
      responsive: {
        mobile: this.getMobileVariant(baseTheme),
        tablet: this.getTabletVariant(baseTheme),
        desktop: baseTheme
      }
    };
  }
  
  getMobileVariant(theme) {
    return {
      ...theme,
      padding: '1rem',
      borderRadius: '10px',
      customCSS: theme.customCSS + `
        @media ${this.breakpoints.mobile} {
          .card-title {
            font-size: 1.5rem !important;
          }
          .card-content {
            font-size: 0.9rem !important;
            line-height: 1.5 !important;
          }
        }
      `
    };
  }
}

🔍 Performance Optimization

Theme Cache System

// Theme Cache System
class ThemeCacheSystem {
  constructor() {
    this.cache = new Map();
    this.maxCacheSize = 50;
  }
  
  // Cache theme
  cacheTheme(themeId, compiledTheme) {
    if (this.cache.size >= this.maxCacheSize) {
      // Remove oldest theme
      const firstKey = this.cache.keys().next().value;
      this.cache.delete(firstKey);
    }
    
    this.cache.set(themeId, {
      theme: compiledTheme,
      timestamp: Date.now()
    });
  }
  
  // Get theme from cache
  getCachedTheme(themeId) {
    const cached = this.cache.get(themeId);
    if (cached) {
      // Check cache age (1 hour)
      const isExpired = Date.now() - cached.timestamp > 3600000;
      if (!isExpired) {
        return cached.theme;
      } else {
        this.cache.delete(themeId);
      }
    }
    return null;
  }
  
  // Clear cache
  clearCache() {
    this.cache.clear();
  }
}

📊 Analytics and Tracking

Theme Analytics

// Theme usage analytics system
class ThemeAnalytics {
  constructor() {
    this.usage = new Map();
    this.sessions = [];
  }
  
  // Track theme usage
  trackThemeUsage(themeId, userId = null) {
    const current = this.usage.get(themeId) || { count: 0, users: new Set() };
    current.count++;
    
    if (userId) {
      current.users.add(userId);
    }
    
    this.usage.set(themeId, current);
    
    // Record session
    this.sessions.push({
      themeId,
      userId,
      timestamp: Date.now()
    });
  }
  
  // Get popular themes
  getPopularThemes(limit = 10) {
    return Array.from(this.usage.entries())
      .sort((a, b) => b[1].count - a[1].count)
      .slice(0, limit)
      .map(([themeId, data]) => ({
        themeId,
        usage: data.count,
        uniqueUsers: data.users.size
      }));
  }
  
  // Trend analysis
  getTrendAnalysis() {
    const last24h = Date.now() - 86400000;
    const recentSessions = this.sessions.filter(s => s.timestamp > last24h);
    
    const trending = {};
    recentSessions.forEach(session => {
      trending[session.themeId] = (trending[session.themeId] || 0) + 1;
    });
    
    return Object.entries(trending)
      .sort((a, b) => b[1] - a[1])
      .map(([themeId, count]) => ({ themeId, recentUsage: count }));
  }
}

🚀 Future Developments

AI-Generated Themes

// AI Theme Generator (future concept)
class AIThemeGenerator {
  constructor() {
    this.colorPalettes = [
      ['#FF6B6B', '#4ECDC4', '#45B7D1'],
      ['#96CEB4', '#FFEAA7', '#DDA0DD'],
      ['#74B9FF', '#A29BFE', '#FD79A8']
    ];
  }
  
  // Generate theme from description
  async generateFromDescription(description) {
    // For production use, this would connect to an AI API
    const mockTheme = this.createMockThemeFromDescription(description);
    return mockTheme;
  }
  
  createMockThemeFromDescription(description) {
    const keywords = description.toLowerCase();
    let palette = this.colorPalettes[0];
    
    if (keywords.includes('nature') || keywords.includes('green')) {
      palette = ['#2E8B57', '#90EE90', '#228B22'];
    } else if (keywords.includes('ocean') || keywords.includes('blue')) {
      palette = ['#1E90FF', '#87CEEB', '#4682B4'];
    }
    
    return {
      id: `ai-${Date.now()}`,
      name: `AI Generated: ${description}`,
      category: 'ai-generated',
      background: `linear-gradient(135deg, ${palette[0]}, ${palette[1]})`,
      color: '#ffffff',
      fontFamily: '"Inter", sans-serif',
      borderRadius: '15px'
    };
  }
}

Conclusion

The MD2Card theme system provides users with endless possibilities for creating beautiful and unique knowledge cards. Through the combination of:

System Strengths:

  1. High Flexibility: Every detail can be customized
  2. Good Performance: Real-time theme switching
  3. User-Friendly: Intuitive interface for all user levels
  4. Diversity: Over 20 themes in various categories

Outstanding Innovations:

  • Dynamic CSS System: Real-time style injection and removal
  • Smart Caching: Optimized theme loading times
  • Responsive Design: Themes that look good on all devices
  • Theme Builder Tool: Enables easy custom theme creation

Future plans include:

  • AI-assisted theme generation
  • Theme sharing between users
  • Visual theme editor
  • Support for animated themes

The MD2Card theme system is not just a decoration tool, but a platform that allows users to express their creativity and create truly unique content.

Back to articles