Home For You Tutorials Claw
⚙️ Technical Deep Dive

How UX Master Works

Deep technical dive into the extraction pipeline, AI analysis, and code generation.

Architecture Overview

UX Master v4 Pipeline
INPUT
PROCESSING
OUTPUT
🌐
Website URL
Input target for extraction
🔍
Browser Crawler
Headless Chromium, visual stability wait
🤖
AI Extractor (harvester_v4.js)
Color histograms, typography, layout grids
🏗️
Semi Design Mapper
150+ CSS variables, 7-state color variants
⚛️
Component Generator
React/Vue/Semi/shadcn code
📦 Outputs
  • 📄 design-system.css (150+ CSS variables)
  • 📄 design-system.json (Structured tokens)
  • 📄 figma-tokens.json (Tokens Studio format)
  • 📄 DESIGN.md (Stitch-compatible)
  • 📁 components/ (React/Vue/Semi/shadcn)

Stage 1: Browser Extraction

What Happens

Python
class HarvesterBrowser:
    async def extract(self, url: str) -> HarvestResult:
        """
        1. Launch headless Chromium
        2. Navigate to URL
        3. Wait for visual stability
        4. Inject harvester_v4.js
        5. Execute AI extraction
        6. Capture screenshot
        7. Return structured data
        """

Key Features

FeatureImplementationPurpose
Headless BrowserPlaywright ChromiumAccurate rendering
Visual Stabilitywait_seconds parameterLet animations finish
Mobile DetectionViewport emulationResponsive design analysis
Error ResilienceTry/catch in browserHandle broken sites

Stage 2: AI Extraction

Core Algorithm

JavaScript
class HarvesterV4 {
    extract(options) {
        return {
            // Visual Analysis
            colors: this.extractColors(),
            typography: this.extractTypography(),
            spacing: this.extractSpacing(),
            components: this.extractComponents(),
            
            // Structural
            layout: this.analyzeLayout(),
            pageType: this.detectPageType(),
            
            // Metadata
            _version: 4,
            _timestamp: Date.now()
        };
    }
}

Color Extraction

JavaScript
extractColors() {
    const elements = document.querySelectorAll('*');
    const frequency = new Map();
    
    // Collect all colors
    elements.forEach(el => {
        const style = window.getComputedStyle(el);
        const bg = style.backgroundColor;
        const text = style.color;
        const border = style.borderColor;
        
        [bg, text, border].forEach(color => {
            if (color && color !== 'transparent') {
                frequency.set(color, (frequency.get(color) || 0) + 1);
            }
        });
    });
    
    // Sort by frequency
    const sorted = [...frequency.entries()]
        .sort((a, b) => b[1] - a[1]);
    
    return {
        histogram: { background, text, border },
        dominant: this.extractDominant(sorted)
    };
}

Component Detection

JavaScript
extractComponents() {
    const blueprints = [];
    
    // Button detection
    document.querySelectorAll('button, [role="button"]')
        .forEach(el => blueprints.push(this.analyzeButton(el)));
    
    // Input detection
    document.querySelectorAll('input, textarea, select')
        .forEach(el => blueprints.push(this.analyzeInput(el)));
    
    // Card detection
    document.querySelectorAll('.card, [class*="card"]')
        .forEach(el => blueprints.push(this.analyzeCard(el)));
    
    return { blueprints, count: blueprints.length };
}

Stage 3: Semi Design Mapper

The mapper converts raw harvest data to standardized Semi Design tokens:

Stage 4: Component Generator

Generates production-ready components from blueprints:

Supported Frameworks

Generated Components

🔬 Tìm hiểu thêm

Khám phá API reference và bắt đầu sử dụng Harvester v4.