# Code Conversion Reference Convert Pencil designs to production code (HTML/CSS/React/Blazor). ## Overview This guide covers converting `.pen` files to production code with proper structure, responsive design, and design system integration. ## Element Mapping ### Pencil to HTML/CSS | Pencil Element | HTML | CSS Layout | Notes | |----------------|------|------------|-------| | `frame` (layout:vertical) | `
` | `flex-direction: column` | Flexbox container | | `frame` (layout:horizontal) | `
` | `flex-direction: row` | Flexbox container | | `frame` (layout:none) | `
` | `position: relative` | Free positioning | | `text` | `

`, `

`-`

`, `` | - | Based on fontSize | | `rectangle` | `
` | - | With background | | `ellipse` | `
` | `border-radius: 50%` | Circular shape | | `icon_font` | `` | - | Lucide icons | ### Pencil to React/Blazor | Pencil | React | Blazor | |--------|-------|--------| | `frame` | `
` | `
` | | `text` | `

{content}

` | `

@content

` | | `icon_font` | `` | `` | | Component ref | ` ); } // CSS .button { /* Base styles */ } .button--primary { background: var(--orange-primary); } .button--default { /* Default state */ } .button--hover { background: var(--orange-light); } ``` ## Framework-Specific Examples ### React Component ```jsx import React from 'react'; import './HeroSection.css'; export function HeroSection({ title, subtitle, ctaText }) { return (

{title}

{subtitle}

); } ``` ```css /* HeroSection.css */ .hero-section { display: flex; flex-direction: column; align-items: center; padding: 80px 120px; background: var(--bg-page); } .hero-content { max-width: 800px; text-align: center; } .hero-title { font-size: 48px; font-weight: 700; color: var(--text-primary); margin-bottom: 16px; } .hero-subtitle { font-size: 18px; color: var(--text-secondary); margin-bottom: 32px; } .hero-cta { padding: 16px 32px; background: var(--orange-primary); color: var(--text-primary); border: none; border-radius: 10px; font-size: 16px; font-weight: 600; cursor: pointer; } .hero-cta:hover { background: var(--orange-light); } ``` ### Blazor Component ```razor @* HeroSection.razor *@

@Title

@Subtitle

@code { [Parameter] public string Title { get; set; } = ""; [Parameter] public string Subtitle { get; set; } = ""; [Parameter] public string CtaText { get; set; } = ""; [Parameter] public EventCallback OnCtaClick { get; set; } } ``` ### Tailwind CSS From design tokens to Tailwind config: ```javascript // tailwind.config.js module.exports = { theme: { extend: { colors: { 'bg-page': '#0A0A0B', 'bg-surface': '#1A1A1C', 'text-primary': '#FFFFFF', 'orange-primary': '#FF5C00', }, spacing: { '1': '4px', '2': '8px', '4': '16px', '6': '24px', }, borderRadius: { 'sm': '6px', 'md': '10px', 'lg': '16px', } } } } ``` ```jsx // Component with Tailwind

{title}

{subtitle}

``` ## Conversion Tools ### Automated Conversion Script ```javascript import fs from 'fs'; function convertPencilToHTML(pencilFile) { const data = JSON.parse(fs.readFileSync(pencilFile, 'utf-8')); // Extract main page const mainPage = data.children[0]; // Generate HTML const html = convertElement(mainPage); // Generate CSS const css = generateCSSForAll(mainPage); // Generate design tokens const tokens = generateTokensCSS(data.variables); return { html, css: `${tokens}\n\n${css}`, tokens: data.variables }; } // Example usage const result = convertPencilToHTML('design.pen'); fs.writeFileSync('output.html', result.html); fs.writeFileSync('output.css', result.css); console.log('✅ Conversion complete!'); ``` ## Common Patterns ### Navigation Bar ```html ``` ```css .navbar { display: flex; justify-content: space-between; align-items: center; padding: 16px 120px; background: var(--bg-surface); } .navbar-menu { display: flex; gap: 32px; list-style: none; } .navbar-menu a { color: var(--text-primary); text-decoration: none; } ``` ### Card Component ```html

Feature Title

Feature description text goes here.

Learn More →
``` ```css .card { display: flex; flex-direction: column; padding: 24px; background: var(--bg-surface); border-radius: var(--radius-md); gap: 16px; } .card-header { display: flex; align-items: center; gap: 12px; } .card-description { color: var(--text-secondary); line-height: 1.6; } .card-link { color: var(--orange-primary); text-decoration: none; font-weight: 600; } ``` ## Resources - Back to [Pencil Design Skill](../SKILL.md) - [File Format Reference](./FILE_FORMAT.md) - [Build System Reference](./BUILD_SYSTEM.md) - [Atomic Design Reference](./ATOMIC_DESIGN.md) - [Tailwind Design System](../tailwind-design-system/SKILL.md) - [React UI Components](../react-ui-components/SKILL.md) - [Blazor Theme Patterns](../blazor-theme-patterns/SKILL.md) - [MAUI Branding Expert](../maui-branding-expert/SKILL.md) - [Swift UI Components](../swift-ui-components/SKILL.md)