# Generation Scripts Reference

Complete reference for HTML slideshow generation and output processing.

## generate_slideshow.py

Main script for generating complete HTML slideshows.

### Basic Usage

```bash
# Generate basic slideshow
python scripts/generate_slideshow.py project-path \
  --content content/slides.json \
  --output dist/

# Generate with specific style
python scripts/generate_slideshow.py project-path \
  --content content/slides.json \
  --styles styles/ \
  --brand ce \
  --output dist/

# Generate optimized for production
python scripts/generate_slideshow.py project-path \
  --content content/slides.json \
  --production \
  --minify \
  --optimize-assets \
  --output dist/
```

### Advanced Generation

```bash
# Generate with custom template
python scripts/generate_slideshow.py project-path \
  --template custom-slideshow.html \
  --content content/slides.json \
  --output dist/

# Generate multiple formats
python scripts/generate_slideshow.py project-path \
  --content content/slides.json \
  --formats "html,pdf,pptx" \
  --output dist/

# Generate with interactive features
python scripts/generate_slideshow.py project-path \
  --content content/slides.json \
  --interactive \
  --animations \
  --navigation \
  --presenter-mode \
  --output dist/
```

## HTML Generation Engine

### Core Generator

```python
from generators import HTMLGenerator

generator = HTMLGenerator(project_path)

# Basic slideshow generation
slideshow = generator.generate(
    content_file='content/slides.json',
    style_files=['styles/brand.css', 'styles/layout.css'],
    output_dir='dist/'
)

# Advanced generation with options
slideshow = generator.generate(
    content_file='content/slides.json',
    template='templates/corporate.html',
    features=[
        'navigation',
        'animations', 
        'presenter_mode',
        'print_support'
    ],
    optimization={
        'minify_html': True,
        'inline_critical_css': True,
        'lazy_load_images': True,
        'preload_fonts': True
    }
)
```

### Template System

```python
from generators import TemplateEngine

engine = TemplateEngine()

# Register custom slide layouts
engine.register_layout('split-hero', {
    'template': 'layouts/split-hero.html',
    'css': 'layouts/split-hero.css',
    'js': 'layouts/split-hero.js'
})

# Generate with custom layouts
html = engine.generate_slide(
    slide_data=slide,
    layout='split-hero',
    context={'brand': 'ce', 'theme': 'corporate'}
)
```

## Output Formats

### HTML Slideshow

```python
from generators import HTMLSlideshow

generator = HTMLSlideshow()

# Generate responsive HTML slideshow
html_output = generator.generate({
    'content': content_data,
    'responsive': True,
    'navigation': 'keyboard+touch',
    'transitions': 'smooth',
    'theme': 'ce-corporate'
})

# Features configuration
features = {
    'presenter_mode': True,  # Dual-screen presenter view
    'slide_notes': True,     # Speaker notes display
    'progress_bar': True,    # Progress indicator
    'slide_numbers': True,   # Slide numbering
    'overview_mode': True,   # Grid overview
    'print_support': True,   # CSS for printing
    'fullscreen': True,      # Fullscreen API support
    'auto_play': False,      # Automatic progression
    'lazy_loading': True     # Lazy load images/content
}
```

### PDF Export

```python
from generators import PDFGenerator

pdf_generator = PDFGenerator()

# Generate PDF from HTML slideshow
pdf_output = pdf_generator.generate_from_html(
    html_file='dist/index.html',
    output_file='dist/slideshow.pdf',
    options={
        'page_size': 'A4',
        'orientation': 'landscape',
        'margin': '0.5in',
        'print_background': True,
        'wait_for_fonts': True
    }
)

# Generate high-quality PDF
pdf_output = pdf_generator.generate_high_quality(
    content='content/slides.json',
    output_file='dist/slideshow-hq.pdf',
    options={
        'dpi': 300,
        'color_space': 'RGB',
        'embed_fonts': True,
        'optimize_size': False
    }
)
```

### PowerPoint Export

```python
from generators import PowerPointGenerator

pptx_generator = PowerPointGenerator()

# Generate PowerPoint from content
pptx_output = pptx_generator.generate(
    content_file='content/slides.json',
    template='templates/corporate.pptx',
    output_file='dist/slideshow.pptx',
    options={
        'preserve_formatting': True,
        'embed_images': True,
        'speaker_notes': True
    }
)

# Convert HTML slideshow to PowerPoint
pptx_output = pptx_generator.convert_from_html(
    html_file='dist/index.html',
    output_file='dist/converted.pptx',
    slide_size='16:9'
)
```

## Interactive Features

### Navigation System

```javascript
// Generated navigation code
class SlideshowNavigation {
    constructor(container) {
        this.container = container;
        this.currentSlide = 0;
        this.slides = container.querySelectorAll('.slide');
        this.setupKeyboardNav();
        this.setupTouchNav();
        this.setupMouseNav();
    }
    
    setupKeyboardNav() {
        document.addEventListener('keydown', (e) => {
            switch(e.key) {
                case 'ArrowRight':
                case ' ':
                    this.nextSlide();
                    break;
                case 'ArrowLeft':
                    this.previousSlide();
                    break;
                case 'Home':
                    this.goToSlide(0);
                    break;
                case 'End':
                    this.goToSlide(this.slides.length - 1);
                    break;
                case 'Escape':
                    this.toggleOverview();
                    break;
            }
        });
    }
}
```

### Presenter Mode

```python
from generators import PresenterModeGenerator

presenter_gen = PresenterModeGenerator()

# Generate presenter mode interface
presenter_mode = presenter_gen.generate({
    'dual_screen': True,
    'speaker_notes': True,
    'slide_preview': True,
    'timer': True,
    'audience_view_control': True
})

# Features for presenter mode
presenter_features = {
    'current_slide': 'Main presentation view',
    'next_slide': 'Preview of next slide',
    'notes': 'Speaker notes for current slide',
    'timer': 'Elapsed/remaining time display',
    'progress': 'Slide progress indicator',
    'audience_view': 'Control what audience sees',
    'laser_pointer': 'Virtual laser pointer',
    'drawing_tools': 'Annotation tools'
}
```

### Animation System

```css
/* Generated animation CSS */
.slide {
    --animation-duration: var(--slide-animation-duration, 0.6s);
    --animation-easing: var(--slide-animation-easing, cubic-bezier(0.4, 0, 0.2, 1));
}

/* Slide transitions */
.slide.slide-in-right {
    animation: slideInRight var(--animation-duration) var(--animation-easing);
}

.slide.slide-out-left {
    animation: slideOutLeft var(--animation-duration) var(--animation-easing);
}

/* Content animations */
.animate-fade-in {
    opacity: 0;
    animation: fadeIn 0.8s ease-out forwards;
}

.animate-slide-up {
    transform: translateY(30px);
    opacity: 0;
    animation: slideUp 0.6s ease-out forwards;
}

/* Staggered animations */
.slide.active .animate-stagger:nth-child(1) { animation-delay: 0.1s; }
.slide.active .animate-stagger:nth-child(2) { animation-delay: 0.2s; }
.slide.active .animate-stagger:nth-child(3) { animation-delay: 0.3s; }
```

## Build and Optimization

### build_production.py

Build optimized production version.

```bash
# Production build
python scripts/build_production.py project-path \
  --optimize \
  --minify \
  --compress-assets \
  --generate-service-worker \
  --output dist/

# Build with specific optimizations
python scripts/build_production.py project-path \
  --critical-css-inline \
  --preload-fonts \
  --lazy-load-images \
  --progressive-web-app \
  --output dist/

# Build for specific deployment
python scripts/build_production.py project-path \
  --target vercel \
  --cdn-assets \
  --serverless-optimized \
  --output dist/
```

### Production Optimizations

```python
from generators import ProductionOptimizer

optimizer = ProductionOptimizer()

# Optimize HTML output
optimized_html = optimizer.optimize_html(
    html_content=raw_html,
    optimizations=[
        'minify',
        'inline_critical_css',
        'preload_resources',
        'remove_unused_css',
        'optimize_images'
    ]
)

# Generate service worker
service_worker = optimizer.generate_service_worker({
    'cache_strategy': 'cache_first',
    'cache_assets': ['styles.css', 'slideshow.js'],
    'offline_fallback': 'offline.html',
    'update_strategy': 'immediate'
})

# Build manifest for PWA
manifest = optimizer.generate_pwa_manifest({
    'name': 'Slideshow Presentation',
    'theme_color': brand_colors['primary'],
    'background_color': brand_colors['background'],
    'display': 'fullscreen',
    'orientation': 'landscape'
})
```

## Deployment Integration

### deploy_slideshow.py

Deploy generated slideshow to various platforms.

```bash
# Deploy to Vercel
python scripts/deploy_slideshow.py project-path \
  --platform vercel \
  --project-id vercel-project \
  --domain custom-domain.com

# Deploy to Netlify
python scripts/deploy_slideshow.py project-path \
  --platform netlify \
  --site-id netlify-site \
  --build-command "npm run build"

# Deploy to GitHub Pages
python scripts/deploy_slideshow.py project-path \
  --platform github-pages \
  --repo owner/repo \
  --branch gh-pages
```

### Deployment Configurations

```python
from deployers import SlideshowDeployer

# Vercel deployment
vercel_deployer = SlideshowDeployer.vercel({
    'project_id': 'vercel-project',
    'build_command': 'python scripts/build_production.py',
    'output_directory': 'dist',
    'environment_variables': {
        'OPTIMIZATION_LEVEL': 'high',
        'ENABLE_ANALYTICS': 'true'
    }
})

# Netlify deployment
netlify_deployer = SlideshowDeployer.netlify({
    'site_id': 'netlify-site',
    'build_settings': {
        'command': 'python scripts/build_production.py',
        'publish': 'dist'
    },
    'redirects': [
        {'from': '/presentation', 'to': '/index.html', 'status': 200}
    ]
})
```

## Performance Monitoring

### monitor_performance.py

Monitor slideshow performance and user analytics.

```bash
# Setup performance monitoring
python scripts/monitor_performance.py project-path \
  --analytics google-analytics \
  --real-user-monitoring \
  --performance-budget "3s,1MB"

# Generate performance report
python scripts/monitor_performance.py project-path \
  --report performance-report.html \
  --lighthouse-audit \
  --web-vitals
```

### Performance Analytics

```python
from analytics import PerformanceMonitor

monitor = PerformanceMonitor()

# Track Core Web Vitals
vitals = monitor.track_web_vitals([
    'largest_contentful_paint',
    'first_input_delay', 
    'cumulative_layout_shift',
    'first_contentful_paint'
])

# Monitor slide engagement
engagement = monitor.track_slide_engagement({
    'time_per_slide': True,
    'interaction_events': True,
    'exit_points': True,
    'device_types': True
})

# Real User Monitoring (RUM)
rum_data = monitor.setup_rum({
    'sample_rate': 0.1,  # 10% of users
    'track_errors': True,
    'track_performance': True,
    'track_user_flow': True
})
```

## Testing and Quality Assurance

### test_slideshow.py

Automated testing for generated slideshows.

```bash
# Run all tests
python scripts/test_slideshow.py project-path \
  --test-suite full \
  --browsers "chrome,firefox,safari" \
  --devices "desktop,tablet,mobile"

# Performance testing
python scripts/test_slideshow.py project-path \
  --performance-test \
  --lighthouse-score 90 \
  --load-time-budget 3s

# Accessibility testing
python scripts/test_slideshow.py project-path \
  --accessibility-test \
  --wcag-level AA \
  --screen-reader-test
```

### Automated Testing

```python
from testing import SlideshowTester

tester = SlideshowTester(project_path)

# Visual regression testing
visual_results = tester.run_visual_tests({
    'baseline_screenshots': 'tests/baselines/',
    'current_screenshots': 'tests/current/',
    'diff_threshold': 0.1,
    'browsers': ['chrome', 'firefox']
})

# Functionality testing
func_results = tester.run_functionality_tests([
    'navigation_keyboard',
    'navigation_touch',
    'slide_transitions',
    'presenter_mode',
    'responsive_layout'
])

# Performance testing
perf_results = tester.run_performance_tests({
    'lighthouse_score': 90,
    'load_time_budget': 3000,  # ms
    'asset_size_budget': 2048,  # KB
    'test_devices': ['desktop', 'mobile']
})
```

## Error Handling and Recovery

### Generation Error Handling

```python
try:
    slideshow = generator.generate(content_file, styles_dir, output_dir)
except ContentValidationError as e:
    print(f"Content validation failed: {e.slide_id}")
    print(f"Error: {e.message}")
    # Attempt to fix common issues
    fixed_content = generator.auto_fix_content(content_file)
    slideshow = generator.generate(fixed_content, styles_dir, output_dir)
    
except TemplateNotFoundError as e:
    print(f"Template not found: {e.template_name}")
    # Fall back to default template
    slideshow = generator.generate(
        content_file, styles_dir, output_dir,
        template='default'
    )
    
except AssetMissingError as e:
    print(f"Missing asset: {e.asset_path}")
    # Generate placeholder or download from CDN
    generator.handle_missing_asset(e.asset_path)
    slideshow = generator.generate(content_file, styles_dir, output_dir)
    
except InsufficientMemoryError as e:
    print(f"Insufficient memory for generation")
    # Use streaming generation for large presentations
    slideshow = generator.generate_streaming(
        content_file, styles_dir, output_dir,
        chunk_size=10  # Process 10 slides at a time
    )
```

### Recovery Mechanisms

```python
from generators import GeneratorRecovery

recovery = GeneratorRecovery(project_path)

# Create backup before generation
recovery.create_generation_backup()

# Recover from failed generation
if generation_failed:
    recovery.restore_from_backup()
    
    # Analyze failure cause
    failure_analysis = recovery.analyze_failure()
    print(f"Failure cause: {failure_analysis.cause}")
    print(f"Suggested fix: {failure_analysis.suggestion}")
    
    # Attempt recovery with suggested fix
    recovery.apply_fix(failure_analysis.suggestion)
    slideshow = generator.generate(content_file, styles_dir, output_dir)
```