design-clone 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/README.md +13 -34
  2. package/SKILL.md +69 -45
  3. package/bin/cli.js +22 -4
  4. package/bin/commands/clone-site.js +31 -171
  5. package/bin/commands/help.js +19 -6
  6. package/bin/commands/init.js +9 -86
  7. package/bin/commands/uninstall.js +105 -0
  8. package/bin/commands/update.js +70 -0
  9. package/bin/commands/verify.js +7 -14
  10. package/bin/utils/paths.js +28 -0
  11. package/bin/utils/validate.js +2 -22
  12. package/bin/utils/version.js +23 -0
  13. package/docs/code-standards.md +789 -0
  14. package/docs/codebase-summary.md +533 -286
  15. package/docs/index.md +74 -0
  16. package/docs/project-overview-pdr.md +797 -0
  17. package/docs/system-architecture.md +718 -0
  18. package/package.json +14 -17
  19. package/src/ai/prompts/design-tokens/basic.md +80 -0
  20. package/src/ai/prompts/design-tokens/section-with-css.md +41 -0
  21. package/src/ai/prompts/design-tokens/section.md +48 -0
  22. package/src/ai/prompts/design-tokens/with-css.md +87 -0
  23. package/src/ai/prompts/structure-analysis/basic.md +55 -0
  24. package/src/ai/prompts/structure-analysis/with-context.md +59 -0
  25. package/src/ai/prompts/structure-analysis/with-dimensions.md +63 -0
  26. package/src/ai/prompts/structure-analysis/with-hierarchy.md +73 -0
  27. package/src/ai/prompts/ux-audit/aggregation.md +42 -0
  28. package/src/ai/prompts/ux-audit/desktop.md +92 -0
  29. package/src/ai/prompts/ux-audit/mobile.md +93 -0
  30. package/src/ai/prompts/ux-audit/tablet.md +92 -0
  31. package/src/core/animation/animation-extractor-ast.js +183 -0
  32. package/src/core/animation/animation-extractor-output.js +152 -0
  33. package/src/core/animation/animation-extractor.js +178 -0
  34. package/src/core/animation/state-capture-detection.js +200 -0
  35. package/src/core/animation/state-capture.js +193 -0
  36. package/src/core/capture/browser-context-pool.js +96 -0
  37. package/src/core/capture/multi-page-screenshot-page.js +110 -0
  38. package/src/core/capture/multi-page-screenshot.js +208 -0
  39. package/src/core/capture/screenshot-extraction.js +186 -0
  40. package/src/core/capture/screenshot-helpers.js +175 -0
  41. package/src/core/capture/screenshot-orchestrator.js +174 -0
  42. package/src/core/capture/screenshot-viewport.js +93 -0
  43. package/src/core/capture/screenshot.js +192 -0
  44. package/src/core/content/content-counter-dom.js +191 -0
  45. package/src/core/content/content-counter.js +76 -0
  46. package/src/core/css/breakpoint-detector.js +66 -0
  47. package/src/core/css/chromium-defaults.json +23 -0
  48. package/src/core/css/computed-style-extractor.js +102 -0
  49. package/src/core/css/css-chunker.js +103 -0
  50. package/src/core/css/filter-css-dead-code.js +120 -0
  51. package/src/core/css/filter-css-html-analyzer.js +110 -0
  52. package/src/core/css/filter-css-selector-matcher.js +172 -0
  53. package/src/core/css/filter-css.js +206 -0
  54. package/src/core/css/merge-css-atrule-processor.js +158 -0
  55. package/src/core/css/merge-css-file-io.js +68 -0
  56. package/src/core/css/merge-css.js +148 -0
  57. package/src/core/detection/framework-detector-routing.js +68 -0
  58. package/src/core/detection/framework-detector-signals.js +65 -0
  59. package/src/core/detection/framework-detector.js +198 -0
  60. package/src/core/dimension/dimension-extractor-card-detector.js +82 -0
  61. package/src/core/dimension/dimension-extractor.js +317 -0
  62. package/src/core/dimension/dimension-output-ai-summary.js +111 -0
  63. package/src/core/dimension/dimension-output.js +173 -0
  64. package/src/core/dimension/dom-tree-analyzer-tree-builders.js +95 -0
  65. package/src/core/dimension/dom-tree-analyzer.js +191 -0
  66. package/src/core/discovery/app-state-snapshot-capture.js +195 -0
  67. package/src/core/discovery/app-state-snapshot-utils.js +178 -0
  68. package/src/core/discovery/app-state-snapshot.js +131 -0
  69. package/src/core/discovery/discover-pages-routes.js +84 -0
  70. package/src/core/discovery/discover-pages-utils.js +177 -0
  71. package/src/core/discovery/discover-pages.js +191 -0
  72. package/src/core/html/html-extractor-inline-styler.js +70 -0
  73. package/src/core/html/html-extractor.js +147 -0
  74. package/src/core/html/semantic-enhancer-mappings.js +200 -0
  75. package/src/core/html/semantic-enhancer-page.js +148 -0
  76. package/src/core/html/semantic-enhancer.js +135 -0
  77. package/src/core/links/rewrite-links-css-rewriter.js +53 -0
  78. package/src/core/links/rewrite-links.js +173 -0
  79. package/src/core/media/asset-validator.js +118 -0
  80. package/src/core/media/extract-assets-downloader.js +187 -0
  81. package/src/core/media/extract-assets-page-scraper.js +115 -0
  82. package/src/core/media/extract-assets.js +159 -0
  83. package/src/core/media/video-capture-convert.js +200 -0
  84. package/src/core/media/video-capture.js +201 -0
  85. package/src/core/{lazy-loader.js → page-prep/lazy-loader.js} +37 -39
  86. package/src/core/section/section-cropper-helpers.js +43 -0
  87. package/src/core/{section-cropper.js → section/section-cropper.js} +11 -88
  88. package/src/core/section/section-detector-strategies.js +139 -0
  89. package/src/core/section/section-detector-utils.js +100 -0
  90. package/src/core/section/section-detector.js +88 -0
  91. package/src/core/tests/test-section-cropper.js +2 -2
  92. package/src/core/tests/test-section-detector.js +2 -2
  93. package/src/post-process/enhance-assets.js +29 -4
  94. package/src/post-process/fetch-images-unsplash-client.js +123 -0
  95. package/src/post-process/fetch-images.js +60 -263
  96. package/src/post-process/inject-gosnap.js +88 -0
  97. package/src/post-process/inject-icons-svg-replacer.js +76 -0
  98. package/src/post-process/inject-icons.js +47 -200
  99. package/src/route-discoverers/base-discoverer-utils.js +137 -0
  100. package/src/route-discoverers/base-discoverer.js +29 -118
  101. package/src/route-discoverers/index.js +1 -1
  102. package/src/shared/config.js +38 -0
  103. package/src/shared/error-codes.js +31 -0
  104. package/src/shared/viewports.js +46 -0
  105. package/src/utils/browser.js +0 -7
  106. package/src/utils/helpers.js +4 -0
  107. package/src/utils/log.js +12 -0
  108. package/src/utils/playwright-loader.js +76 -0
  109. package/src/utils/playwright.js +3 -69
  110. package/src/utils/progress.js +32 -0
  111. package/src/verification/generate-audit-report-css-fixes.js +52 -0
  112. package/src/verification/generate-audit-report-sections.js +158 -0
  113. package/src/verification/generate-audit-report.js +5 -281
  114. package/src/verification/quality-scorer.js +92 -0
  115. package/src/verification/verify-footer-checks.js +103 -0
  116. package/src/verification/verify-footer-helpers.js +178 -0
  117. package/src/verification/verify-footer.js +23 -381
  118. package/src/verification/verify-header-checks.js +104 -0
  119. package/src/verification/verify-header-helpers.js +156 -0
  120. package/src/verification/verify-header.js +23 -365
  121. package/src/verification/verify-layout-report.js +101 -0
  122. package/src/verification/verify-layout.js +13 -259
  123. package/src/verification/verify-menu-checks.js +104 -0
  124. package/src/verification/verify-menu-helpers.js +112 -0
  125. package/src/verification/verify-menu.js +17 -285
  126. package/src/verification/verify-slider-checks.js +115 -0
  127. package/src/verification/verify-slider-constants.js +65 -0
  128. package/src/verification/verify-slider-helpers.js +164 -0
  129. package/src/verification/verify-slider.js +23 -414
  130. package/.env.example +0 -14
  131. package/docs/basic-clone.md +0 -63
  132. package/docs/cli-reference.md +0 -316
  133. package/docs/design-clone-architecture.md +0 -492
  134. package/docs/pixel-perfect.md +0 -117
  135. package/docs/project-roadmap.md +0 -382
  136. package/docs/troubleshooting.md +0 -170
  137. package/requirements.txt +0 -5
  138. package/src/ai/__pycache__/analyze-structure.cpython-313.pyc +0 -0
  139. package/src/ai/__pycache__/extract-design-tokens.cpython-313.pyc +0 -0
  140. package/src/ai/analyze-structure.py +0 -375
  141. package/src/ai/extract-design-tokens.py +0 -782
  142. package/src/ai/prompts/__init__.py +0 -2
  143. package/src/ai/prompts/__pycache__/__init__.cpython-313.pyc +0 -0
  144. package/src/ai/prompts/__pycache__/design_tokens.cpython-313.pyc +0 -0
  145. package/src/ai/prompts/__pycache__/structure_analysis.cpython-313.pyc +0 -0
  146. package/src/ai/prompts/__pycache__/ux_audit.cpython-313.pyc +0 -0
  147. package/src/ai/prompts/design_tokens.py +0 -316
  148. package/src/ai/prompts/structure_analysis.py +0 -592
  149. package/src/ai/prompts/ux_audit.py +0 -198
  150. package/src/ai/ux-audit.js +0 -596
  151. package/src/core/animation-extractor.js +0 -526
  152. package/src/core/app-state-snapshot.js +0 -511
  153. package/src/core/content-counter.js +0 -342
  154. package/src/core/design-tokens.js +0 -103
  155. package/src/core/dimension-extractor.js +0 -438
  156. package/src/core/dimension-output.js +0 -305
  157. package/src/core/discover-pages.js +0 -542
  158. package/src/core/dom-tree-analyzer.js +0 -298
  159. package/src/core/extract-assets.js +0 -468
  160. package/src/core/filter-css.js +0 -499
  161. package/src/core/framework-detector.js +0 -538
  162. package/src/core/html-extractor.js +0 -212
  163. package/src/core/merge-css.js +0 -407
  164. package/src/core/multi-page-screenshot.js +0 -380
  165. package/src/core/rewrite-links.js +0 -226
  166. package/src/core/screenshot.js +0 -701
  167. package/src/core/section-detector.js +0 -386
  168. package/src/core/semantic-enhancer.js +0 -492
  169. package/src/core/state-capture.js +0 -598
  170. package/src/core/video-capture.js +0 -546
  171. package/src/utils/__init__.py +0 -16
  172. package/src/utils/__pycache__/__init__.cpython-313.pyc +0 -0
  173. package/src/utils/__pycache__/env.cpython-313.pyc +0 -0
  174. package/src/utils/env.py +0 -134
  175. /package/src/core/{css-extractor.js → css/css-extractor.js} +0 -0
  176. /package/src/core/{cookie-handler.js → page-prep/cookie-handler.js} +0 -0
  177. /package/src/core/{page-readiness.js → page-prep/page-readiness.js} +0 -0
@@ -0,0 +1,718 @@
1
+ # Design Clone System Architecture
2
+
3
+ **Version:** 3.0.0 (v3.0 Improvement Roadmap)
4
+ **Last Updated:** February 23, 2026
5
+
6
+ ## System Design Overview
7
+
8
+ Design Clone is built as a modular, pipeline-based system where each component handles a specific transformation stage. The architecture supports three main workflows with a shared foundation.
9
+
10
+ ## High-Level Architecture
11
+
12
+ ```
13
+ ┌─────────────────────────────────────────────────────────┐
14
+ │ CLI Layer (Node.js) │
15
+ │ /design:clone | /design:clone-px | /design:clone-site │
16
+ │ /design:figma-to-code │
17
+ └──────────────────┬──────────────────────────────────────┘
18
+
19
+ ┌──────────┴──────────┬──────────────┐
20
+ ▼ ▼ ▼
21
+ ┌─────────────────┐ ┌─────────────────┐ ┌──────────────┐
22
+ │ Web Extraction │ │ Figma Pipeline │ │ Verification │
23
+ │ (Playwright) │ │ (Python/REST) │ │ & Quality │
24
+ └────────┬────────┘ └────────┬────────┘ └──────┬───────┘
25
+ │ │ │
26
+ ┌────┴────────────────────┴──────────────────┴─────┐
27
+ │ │
28
+ ▼ ▼ ▼
29
+ ┌──────────────┐ ┌─────────────────┐ ┌──────────────┐
30
+ │ Asset Layer │ │ Code Generation │ │ Output Store │
31
+ │ (Browser) │ │ (CSS/Tailwind) │ │ (File System)│
32
+ └──────────────┘ └─────────────────┘ └──────────────┘
33
+ ```
34
+
35
+ ## Component Layers
36
+
37
+ ### 1. CLI Layer (Entry Points)
38
+
39
+ **Location:** `bin/cli.js`, `bin/commands/`
40
+
41
+ **Responsibilities:**
42
+ - Parse command-line arguments
43
+ - Route to appropriate workflow
44
+ - Validate environment setup
45
+ - Display progress and results
46
+
47
+ **Key Commands:**
48
+ ```
49
+ design-clone <url> # Basic clone
50
+ design-clone clone-px <url> # Pixel-perfect
51
+ design-clone clone-site <url> # Multi-page
52
+ design-clone figma-to-code <url> # Figma conversion
53
+ ```
54
+
55
+ **Flow:**
56
+ 1. Parse arguments with yargs
57
+ 2. Validate dependencies (Node, Python, browsers)
58
+ 3. Load environment variables
59
+ 4. Execute workflow command
60
+ 5. Report results to user
61
+
62
+ ---
63
+
64
+ ### 2. Web Extraction Pipeline
65
+
66
+ **Location:** `src/core/`
67
+
68
+ **Workflow Diagram:**
69
+
70
+ ```
71
+ URL Input
72
+
73
+ ├─► Browser Setup (Playwright)
74
+ │ └─► Launch Chrome/Firefox/WebKit
75
+
76
+ ├─► Page Loading
77
+ │ ├─► Navigate to URL
78
+ │ ├─► Wait for network idle
79
+ │ └─► Trigger lazy-loading
80
+
81
+ ├─► Screenshot Capture (3 viewports)
82
+ │ ├─► Desktop: 1920x1080
83
+ │ ├─► Tablet: 768x1024
84
+ │ └─► Mobile: 375x812
85
+
86
+ ├─► HTML Extraction
87
+ │ ├─► Serialize DOM
88
+ │ ├─► Remove <script> tags
89
+ │ ├─► Keep semantic markup
90
+ │ └─► Preserve data attributes
91
+
92
+ ├─► CSS Extraction
93
+ │ ├─► Collect all stylesheets
94
+ │ ├─► Inline critical CSS
95
+ │ ├─► Preserve animations
96
+ │ └─► Extract @keyframes
97
+
98
+ └─► [Optional] Asset Extraction
99
+ ├─► Images (WebP/JPG/PNG)
100
+ ├─► Fonts (WOFF2/TTF)
101
+ └─► Icons (SVG/Font Awesome)
102
+ ```
103
+
104
+ **Key Modules (by Domain):**
105
+
106
+ | Module | Location | Purpose | v3.0 Changes | Input | Output |
107
+ |--------|----------|---------|-------------|-------|--------|
108
+ | screenshot.js | capture/ | Viewport capture | Fast-path, breakpoint detect, quality score | URL | PNG screenshots |
109
+ | screenshot-extraction.js | capture/ | HTML/CSS extract | Progress reporting, computed gap-fill, aggressive filter | Page | HTML + CSS |
110
+ | browser-context-pool.js | capture/ | Context reuse | NEW: Parallel multi-page, memory guards | - | Browser contexts |
111
+ | extract-assets.js | media/ | Asset downloads | Concurrency 5→10, validation | HTML + CSS | images/, fonts/, icons/ |
112
+ | asset-validator.js | media/ | Asset verification | NEW: Magic bytes, SVG sanitize | Assets | Valid/invalid report |
113
+ | filter-css.js | css/ | Remove unused rules | Chunked streaming, error codes, aggressive pass | HTML + CSS | Optimized CSS |
114
+ | breakpoint-detector.js | css/ | Breakpoint detection | NEW: Parse @media, actual breakpoints | CSS | Breakpoint list |
115
+ | filter-css-dead-code.js | css/ | Dead code removal | NEW: Two-pass @media/@keyframes removal | CSS | Cleaned CSS |
116
+ | css-chunker.js | css/ | Streaming chunks | NEW: 50MB limit, 5MB chunks | CSS | Chunked stream |
117
+ | computed-style-extractor.js | css/ | Style gap-fill | NEW: getComputedStyle vs Chromium defaults | Page | Gap-filled CSS |
118
+ | quality-scorer.js | verification/ | Quality metrics | NEW: 5-metric weighted score | Extraction | quality-score.json |
119
+ | progress.js | utils/ | Progress reporting | NEW: TTY-aware stderr output | - | Progress events |
120
+ | error-codes.js | shared/ | Error catalog | NEW: Structured codes + suggestions | - | DesignCloneError |
121
+ | discover-pages.js | discovery/ | SPA navigation | Progress reporting added | URL | Page list |
122
+ | multi-page-screenshot.js | capture/ | Multi-page capture | Context pool, memory guards, dry-run | Page list | Screenshots |
123
+ | animation-extractor.js | animation/ | Extract animations | - | CSS | animation-tokens.json |
124
+ | semantic-enhancer.js | html/ | HTML optimization | - | HTML + CSS | Enhanced HTML |
125
+ | dimension-extractor.js | dimension/ | Structure analysis | - | DOM tree | layout-analysis.json |
126
+ | section-detector.js | section/ | Section detection | - | HTML + viewport | sections.json |
127
+ | clone-site.js | bin/commands/ | Multi-page clone CLI | Dry-run, progress, parallel | URL | Screenshots + manifest |
128
+
129
+ **Critical Features:**
130
+
131
+ - **Lazy Loading:** Waits for dynamic content via `page.waitForLoadState('networkidle')`
132
+ - **JavaScript Removal:** Strips all `<script>` tags, preserves HTML structure
133
+ - **CSS Preservation:** Keeps all stylesheets, including animations
134
+ - **Asset Integrity:** Validates magic bytes, sanitizes SVG (v3.0)
135
+ - **Centralized Logging:** TTY-aware output via src/utils/log.js
136
+ - **Progress Reporting:** Real-time feedback via ProgressReporter (v3.0)
137
+ - **Streaming CSS:** Processes 50MB+ stylesheets in chunks (v3.0)
138
+ - **Parallel Context Pool:** Multi-page capture with memory guards (v3.0)
139
+
140
+ **Recent Refactoring (Feb 23):**
141
+
142
+ Two major modules were decomposed to reduce code duplication and code smells:
143
+ - **semantic-enhancer.js:** Now uses 3 companion modules (semantic-enhancer-page.js, semantic-enhancer-mappings.js)
144
+ - **dimension-extractor.js:** Now uses 5 companion modules (dimension-extractor-card-detector.js, dimension-output.js, dimension-output-ai-summary.js, dom-tree-analyzer.js, dom-tree-analyzer-tree-builders.js)
145
+
146
+ ---
147
+
148
+ ### 3. Figma-to-Code Pipeline (Phase 3)
149
+
150
+ **Location:** `src/figma/`
151
+
152
+ **Architecture:**
153
+
154
+ ```
155
+ Figma URL
156
+
157
+ ├─► URL Parser (parse-url.js)
158
+ │ └─► Extract file_key, node_id
159
+
160
+ ├─► API Authentication (figma-client.py)
161
+ │ └─► Validate FIGMA_ACCESS_TOKEN
162
+
163
+ ├─► Design Extraction (extract-figma.py)
164
+ │ ├─► Fetch file metadata
165
+ │ ├─► Traverse node hierarchy
166
+ │ ├─► Extract design tokens
167
+ │ │ ├─ Colors (fills, strokes, opacity)
168
+ │ │ ├─ Typography (family, size, weight, line-height)
169
+ │ │ ├─ Spacing (gaps, padding, margins)
170
+ │ │ ├─ Shadows (blur, offset, spread, color)
171
+ │ │ └─ Border radius (uniform, per-corner)
172
+ │ └─► Download screenshot
173
+
174
+ ├─► Output: design-tokens.json, tokens.css, figma-nodes.json
175
+
176
+ ├─► Code Generation (branching)
177
+ │ │
178
+ │ ├─ CSS Mode (default)
179
+ │ │ └─► generate-css.py
180
+ │ │ ├─► Build BEM class structure
181
+ │ │ ├─► Generate semantic HTML
182
+ │ │ ├─► Create CSS rules
183
+ │ │ └─► Output: index.html, styles.css
184
+ │ │
185
+ │ └─ Tailwind Mode (--tailwindcss)
186
+ │ └─► generate-tailwind.py
187
+ │ ├─► Map values to Tailwind scale
188
+ │ ├─► Generate utility classes
189
+ │ ├─► Generate HTML with classes
190
+ │ └─► Output: index.html, [tailwind.config.js]
191
+
192
+ └─► Final Output
193
+ ├─ index.html
194
+ ├─ styles.css (CSS mode) OR tailwind utilities
195
+ ├─ tokens.css (CSS custom properties)
196
+ ├─ design-tokens.json (machine-readable)
197
+ └─ analysis/ (figma-export.png, figma-nodes.json)
198
+ ```
199
+
200
+ **Key Features:**
201
+
202
+ 1. **Design Token Extraction (Phase 2)**
203
+ - Automatic color detection from fills/strokes
204
+ - Typography extraction from TEXT nodes
205
+ - Spacing normalization to Tailwind scale
206
+ - Shadow and border-radius mapping
207
+
208
+ 2. **BEM CSS Generation (Phase 3)**
209
+ - Semantic HTML structure
210
+ - Block-Element-Modifier naming
211
+ - Design token variable integration
212
+ - Responsive breakpoint support
213
+
214
+ 3. **Tailwind Generation (Phase 3)**
215
+ - Utility-first class generation
216
+ - Arbitrary value support for custom values
217
+ - Scale matching (spacing, colors, sizing)
218
+ - Config extension generation when needed
219
+
220
+ ---
221
+
222
+ ### 4. AI Analysis Layer
223
+
224
+ **Location:** `src/ai/prompts/`
225
+
226
+ **Claude Code Built-in Vision:**
227
+
228
+ Claude Code reads prompt templates + screenshots directly. No external API calls.
229
+
230
+ ```
231
+ Screenshot(s) + Context Files
232
+
233
+ ├─► Read prompt template (markdown)
234
+ │ ├─► Select best variant based on available context
235
+ │ └─► Highest accuracy: with-hierarchy > with-dimensions > with-context > basic
236
+
237
+ ├─► Claude Code vision analyzes screenshots
238
+ │ ├─► Structure analysis → structure.md
239
+ │ ├─► Design tokens → design-tokens.json, tokens.css
240
+ │ └─► UX audit → ux-audit.json, ux-audit.md
241
+
242
+ └─► Results written to output directory
243
+ ```
244
+
245
+ **Prompt Templates:**
246
+
247
+ - `prompts/structure-analysis/*.md` - Layout and hierarchy analysis (4 variants)
248
+ - `prompts/design-tokens/*.md` - Design system extraction (4 variants)
249
+ - `prompts/ux-audit/*.md` - UX quality checks (3 viewports + aggregation)
250
+
251
+ ---
252
+
253
+ ### 5. Verification & Quality Layer
254
+
255
+ **Location:** `src/verification/`
256
+
257
+ **Quality Checks:**
258
+
259
+ | Check | Module | Validates |
260
+ |-------|--------|-----------|
261
+ | Menu Verification | verify-menu.js | Navigation structure, links |
262
+ | Layout Consistency | verify-layout.js | Grid, flexbox, positioning |
263
+ | Header Structure | verify-header.js | Logo, nav, search presence |
264
+ | Footer Structure | verify-footer.js | Links, copyright, social |
265
+ | Slider Detection | verify-slider.js | Carousel elements |
266
+ | Semantic HTML | semantic-enhancer.js | Proper heading hierarchy |
267
+
268
+ **Execution:**
269
+ ```bash
270
+ # Part of /design:clone-px workflow
271
+ node src/verification/verify-menu.js --html output/source.html
272
+ ```
273
+
274
+ ---
275
+
276
+ ### 6. Post-Processing Layer
277
+
278
+ **Location:** `src/post-process/`
279
+
280
+ **Asset Enhancement:**
281
+
282
+ | Module | Function | Input | Output |
283
+ |--------|----------|-------|--------|
284
+ | fetch-images.js | Download images from Unsplash | Image URLs | assets/images/ |
285
+ | inject-icons.js | Replace with Japanese-style icons | HTML | Updated HTML |
286
+ | inject-gosnap.js | Add gosnap-widget Web Component | HTML dir | HTML with widget |
287
+ | enhance-assets.js | Orchestrate 3-step enhancement | output/ | Enhanced HTML |
288
+
289
+ **Pipeline:**
290
+ 1. Fetch images from Unsplash (if UNSPLASH_ACCESS_KEY set)
291
+ 2. Inject Japanese-style SVG icons
292
+ 3. Inject gosnap-widget (clone-px only)
293
+ 4. Generate responsive srcset
294
+ 5. Inject Font Awesome CDN link (step 2)
295
+
296
+ ---
297
+
298
+ ## Data Flow Diagrams
299
+
300
+ ### Basic Clone Workflow (/design:clone)
301
+
302
+ ```
303
+ User Input (URL)
304
+
305
+ CLI Router
306
+
307
+ ┌─────────────────────────────────────────────────────┐
308
+ │ 1. Launch Browser │
309
+ │ ├─ Initialize Playwright │
310
+ │ └─ Create context (or reuse from pool if exists) │
311
+ └─────────────────────────────────────────────────────┘
312
+
313
+ ┌─────────────────────────────────────────────────────┐
314
+ │ 2. Capture Screenshots (v3.0: Fast-path) │
315
+ │ ├─ Desktop (1920x1080) │
316
+ │ ├─ Tablet (768x1024) │
317
+ │ └─ Mobile (375x812) │
318
+ │ └─ (If all headless: skip browser restart) │
319
+ └─────────────────────────────────────────────────────┘
320
+
321
+ ┌─────────────────────────────────────────────────────┐
322
+ │ 3. Extract HTML & CSS (v3.0: Streaming) │
323
+ │ ├─ Report progress via TTY-aware stderr │
324
+ │ ├─ Serialize DOM, remove scripts │
325
+ │ ├─ Collect stylesheets (stream if >5MB) │
326
+ │ └─ Preserve animations │
327
+ └─────────────────────────────────────────────────────┘
328
+
329
+ ┌─────────────────────────────────────────────────────┐
330
+ │ 4. Filter Unused CSS (v3.0: Chunked + Errors) │
331
+ │ ├─ Parse selectors from HTML │
332
+ │ ├─ Chunk CSS (5MB threshold) │
333
+ │ ├─ Match rules against selectors │
334
+ │ ├─ Remove unused declarations (Pass 1) │
335
+ │ └─ (Optional --aggressive-filter: Pass 2) │
336
+ └─────────────────────────────────────────────────────┘
337
+
338
+ Output Directory
339
+ ├─ desktop.png
340
+ ├─ tablet.png
341
+ ├─ mobile.png
342
+ ├─ source.html
343
+ └─ source.css
344
+ ```
345
+
346
+ **v3.0 Additions:**
347
+ - Use `--detect-breakpoints` to capture at actual @media breakpoints
348
+ - Use `--extract-computed` to fill style gaps via getComputedStyle()
349
+ - Use `--aggressive-filter` for stronger CSS dead code removal
350
+ - Use `--quality-score` to output quality metrics
351
+ - Use `--skip-gosnap` flag in `/design:clone-px` to disable gosnap injection
352
+
353
+ ### Pixel-Perfect Workflow (/design:clone-px)
354
+
355
+ ```
356
+ Basic Clone Output
357
+
358
+ ┌─────────────────────────────────────────────────────┐
359
+ │ 5. Extract Assets (v3.0: Validated, Concurrent) │
360
+ │ ├─ Download images (maxConcurrent: 10) │
361
+ │ ├─ Validate magic bytes (v3.0) │
362
+ │ ├─ Fetch web fonts │
363
+ │ ├─ Sanitize SVG icons (v3.0) │
364
+ │ ├─ Retry on 429 with exponential backoff (v3.0) │
365
+ │ └─ Cache Font Awesome icons │
366
+ └─────────────────────────────────────────────────────┘
367
+
368
+ ┌─────────────────────────────────────────────────────┐
369
+ │ 6. AI Analysis (Built-in) │
370
+ │ ├─ Read prompt template │
371
+ │ ├─ Claude Code vision analysis │
372
+ │ └─ Generate structure report │
373
+ └─────────────────────────────────────────────────────┘
374
+
375
+ ┌─────────────────────────────────────────────────────┐
376
+ │ 7. Design Token Extraction │
377
+ │ ├─ Analyze visual patterns │
378
+ │ ├─ Extract tokens │
379
+ │ └─ Generate CSS custom props │
380
+ └─────────────────────────────────────────────────────┘
381
+
382
+ ┌─────────────────────────────────────────────────────┐
383
+ │ 8. Verification & Quality Scoring (v3.0) │
384
+ │ ├─ Check menu structure │
385
+ │ ├─ Validate layout │
386
+ │ ├─ Score: CSS coverage, asset completeness │
387
+ │ ├─ Score: responsive fidelity, HTML semantics │
388
+ │ └─ Score: accessibility compliance │
389
+ └─────────────────────────────────────────────────────┘
390
+
391
+ Output + Assets + Analysis + Quality Score
392
+ ```
393
+
394
+ ### Multi-Page Clone Workflow (/design:clone-site)
395
+
396
+ ```
397
+ User Input (URL + options)
398
+
399
+ ┌─────────────────────────────────────────────────────┐
400
+ │ 1. Discover Pages (v3.0: Progress reporting) │
401
+ │ ├─ Report progress via TTY-aware stderr │
402
+ │ ├─ Parse site navigation │
403
+ │ ├─ Detect SPA framework (React, Vue, etc) │
404
+ │ └─ Generate page list (--dry-run stops here) │
405
+ └─────────────────────────────────────────────────────┘
406
+
407
+ ┌─────────────────────────────────────────────────────┐
408
+ │ 2. Capture Screenshots (v3.0: Parallel Pool) │
409
+ │ ├─ Initialize browser context pool │
410
+ │ ├─ Reuse contexts across pages (memory guards) │
411
+ │ ├─ Desktop (1920x1080) │
412
+ │ ├─ Tablet (768x1024) │
413
+ │ └─ Mobile (375x812) │
414
+ └─────────────────────────────────────────────────────┘
415
+
416
+ ┌─────────────────────────────────────────────────────┐
417
+ │ 3. Generate Manifest (v3.0) │
418
+ │ ├─ Create manifest.json │
419
+ │ ├─ Map pages to screenshot paths │
420
+ │ ├─ Include capture stats & estimates │
421
+ │ └─ Document pool efficiency metrics │
422
+ └─────────────────────────────────────────────────────┘
423
+
424
+ Output Directory
425
+ ├─ manifest.json
426
+ ├─ capture-results.json
427
+ └─ analysis/
428
+ ├─ desktop/
429
+ ├─ tablet/
430
+ └─ mobile/
431
+ ```
432
+
433
+ **v3.0 Key Features:**
434
+ - Discovery with automatic progress reporting
435
+ - Parallel capture with context pool (reuses browser contexts, reduces memory)
436
+ - Memory guards prevent context leaks
437
+ - `--dry-run` shows discovery + estimates without capturing
438
+ - Per-page status updates
439
+ - Pool efficiency metrics in manifest
440
+
441
+ ### Figma-to-Code Workflow (/design:figma-to-code)
442
+
443
+ ```
444
+ User Input (Figma URL + flags)
445
+
446
+ ┌─────────────────────────────────────┐
447
+ │ 1. Parse URL │
448
+ │ ├─ Extract file_key │
449
+ │ └─ Extract node_id │
450
+ └─────────────────────────────────────┘
451
+
452
+ ┌─────────────────────────────────────┐
453
+ │ 2. Figma API Connection │
454
+ │ ├─ Load FIGMA_ACCESS_TOKEN │
455
+ │ └─ Authenticate │
456
+ └─────────────────────────────────────┘
457
+
458
+ ┌─────────────────────────────────────┐
459
+ │ 3. Extract Design Data │
460
+ │ ├─ Fetch file metadata │
461
+ │ ├─ Traverse nodes │
462
+ │ ├─ Extract components │
463
+ │ └─ Collect all styles │
464
+ └─────────────────────────────────────┘
465
+
466
+ ┌─────────────────────────────────────┐
467
+ │ 4. Design Token Extraction │
468
+ │ ├─ Colors (fills, strokes) │
469
+ │ ├─ Typography (size, weight) │
470
+ │ ├─ Spacing (gaps, padding) │
471
+ │ ├─ Shadows (blur, offset) │
472
+ │ └─ Border radius │
473
+ └─────────────────────────────────────┘
474
+
475
+ ┌─────────────────────────────────────┐
476
+ │ 5. Generate Code (Branch) │
477
+ │ │
478
+ │ IF --tailwindcss: │
479
+ │ → generate-tailwind.py │
480
+ │ → Output: HTML + classes │
481
+ │ │
482
+ │ ELSE (default): │
483
+ │ → generate-css.py │
484
+ │ → Output: HTML + BEM CSS │
485
+ └─────────────────────────────────────┘
486
+
487
+ Output Directory
488
+ ├─ index.html
489
+ ├─ styles.css (CSS mode only)
490
+ ├─ tokens.css
491
+ ├─ design-tokens.json
492
+ └─ analysis/
493
+ ├─ figma-export.png
494
+ └─ figma-nodes.json
495
+ ```
496
+
497
+ ---
498
+
499
+ ## Database & State Management
500
+
501
+ **No Traditional Database.** Design Clone uses file-system-based storage:
502
+
503
+ ### Output Structure
504
+
505
+ ```
506
+ cloned-designs/
507
+ ├── {timestamp}-{domain}/ # Per-session directory
508
+ │ ├── desktop.png # Screenshots
509
+ │ ├── tablet.png
510
+ │ ├── mobile.png
511
+ │ ├── source.html # Extracted code
512
+ │ ├── source.css
513
+ │ ├── source-raw.css
514
+ │ ├── tokens.json # Design tokens
515
+ │ ├── animation-tokens.json
516
+ │ ├── structure.md # AI analysis
517
+ │ ├── assets/
518
+ │ │ ├── images/ # Downloaded images
519
+ │ │ ├── fonts/ # Web fonts
520
+ │ │ └── icons/ # Icon sets
521
+ │ └── hover-states/ # Hover captures
522
+ │ ├── hover-1-normal.png
523
+ │ └── hover-1-hover.png
524
+
525
+ └── {timestamp}-figma/ # Figma conversions
526
+ ├── index.html
527
+ ├── styles.css
528
+ ├── tokens.css
529
+ ├── design-tokens.json
530
+ └── analysis/
531
+ ```
532
+
533
+ ### Manifest Files
534
+
535
+ **Multi-page cloning generates manifest.json:**
536
+
537
+ ```json
538
+ {
539
+ "generated": "2026-02-05T08:00:00Z",
540
+ "source": "https://example.com",
541
+ "pages": [
542
+ {
543
+ "path": "/",
544
+ "filename": "index.html",
545
+ "screenshots": {
546
+ "desktop": "analysis/desktop/index.png",
547
+ "tablet": "analysis/tablet/index.png",
548
+ "mobile": "analysis/mobile/index.png"
549
+ }
550
+ }
551
+ ]
552
+ }
553
+ ```
554
+
555
+ ---
556
+
557
+ ## Technology Decisions
558
+
559
+ ### Why Playwright (not Puppeteer)?
560
+ - **Multi-browser support:** Chrome, Firefox, WebKit
561
+ - **Modern async/await API:** Cleaner code
562
+ - **Better viewport handling:** More accurate mobile testing
563
+ - **Native video recording:** Built-in screen capture
564
+
565
+ ### Why Python for Figma?
566
+ - **Better JSON handling:** Easier design token parsing
567
+ - **Stdlib sufficient:** urllib, json, argparse cover all needs
568
+ - **Cross-platform:** Windows/Mac/Linux compatible
569
+
570
+ ### Playwright as Regular Dependency (Feb 23)
571
+ - **Before:** Optional peerDependency, required manual install
572
+ - **After:** Regular dependency, auto-installed with `npm install`
573
+ - **Benefit:** Simpler setup, guaranteed availability, init.js simplified (20 lines removed)
574
+
575
+ ### Why CSS Custom Properties for Tokens?
576
+ - **Runtime flexibility:** Change values without compilation
577
+ - **CSS native:** No build step required
578
+ - **Fallback support:** Works with older browsers
579
+ - **Easy override:** Component-level customization
580
+
581
+ ### Why BEM for CSS Mode?
582
+ - **Predictable naming:** No namespace collisions
583
+ - **Scalability:** Maintains clarity at large scale
584
+ - **Maintainability:** Clear element relationships
585
+ - **Compatibility:** Works with any CSS architecture
586
+
587
+ ### Why Tailwind Utilities as Alternative?
588
+ - **Smaller output:** Utility classes compress well
589
+ - **Consistency:** Enforced design system
590
+ - **Developer UX:** Rapid prototyping
591
+ - **Industry standard:** Familiar to most developers
592
+
593
+ ---
594
+
595
+ ## Scalability Considerations
596
+
597
+ ### Current Limits (v3.0)
598
+
599
+ | Aspect | Limit | v3.0 Impact |
600
+ |--------|-------|-------------|
601
+ | Screenshot viewports | 3 fixed | Easy to extend |
602
+ | Figma nodes | 1000+ | Tested, performs well |
603
+ | CSS file size | 50MB+ | Streaming chunks at 5MB threshold |
604
+ | Images per page | 100+ | Concurrent downloads (5→10), adaptive throttling |
605
+ | Pages per site | 50+ | Multi-page CLI with context pool |
606
+ | Stylesheets | 100+ | Chunked processing, dead code removal |
607
+
608
+ ### Performance Optimizations (v3.0)
609
+
610
+ 1. **Parallel Viewport:** Fast-path when all headless (skip browser restart)
611
+ 2. **Parallel Multi-Page:** Context pool reuse with memory guards
612
+ 3. **CSS Streaming:** Chunk-based processing for 50MB+ files
613
+ 4. **Download Concurrency:** Increased 5→10, adaptive 429 backoff
614
+ 5. **CSS Deduplication:** 40-60% baseline, up to 80% with aggressive filter
615
+ 6. **Asset Validation:** Early detection prevents corrupted downloads
616
+ 7. **Dead Code Removal:** Two-pass filtering of @media/@keyframes/unused vars
617
+ 8. **Computed Style Gap-Fill:** getComputedStyle() extraction for complete styling
618
+ 9. **Caching:** Screenshot reuse between workflows
619
+ 10. **Progress Reporting:** TTY-aware updates keep user informed
620
+
621
+ ---
622
+
623
+ ## Error Handling & Recovery
624
+
625
+ **Multi-Level Error Strategy:**
626
+
627
+ ```javascript
628
+ try {
629
+ // 1. Input validation
630
+ validateUrl(url);
631
+ validateEnvironment();
632
+
633
+ // 2. Operation with retry logic
634
+ try {
635
+ result = await executeWithRetry(operation, 3);
636
+ } catch (e) {
637
+ // 3. Graceful degradation
638
+ if (isOptional(operation)) {
639
+ console.warn(`Skipping ${operation}: ${e.message}`);
640
+ } else {
641
+ throw e; // Fatal error
642
+ }
643
+ }
644
+ } catch (error) {
645
+ // 4. User-friendly error messages
646
+ reportError(error);
647
+ suggestResolution(error);
648
+ process.exit(1);
649
+ }
650
+ ```
651
+
652
+ **Common Failure Modes:**
653
+
654
+ | Error | Handling | Recovery |
655
+ |-------|----------|----------|
656
+ | Network timeout | Retry 3x with exponential backoff | Skip if optional |
657
+ | Missing FIGMA_ACCESS_TOKEN | Check environment vars | Provide setup guide |
658
+ | Browser crash | Restart Playwright | Clear cache, retry |
659
+ | API rate limit | Wait and retry | Queue requests |
660
+ | Malformed HTML | Fallback to text nodes | Continue |
661
+
662
+ ---
663
+
664
+ ## Security Considerations
665
+
666
+ 1. **No Credential Storage:** Environment variables only, no .env files in output
667
+ 2. **URL Validation:** Only HTTP(S) URLs, no file:// or javascript:
668
+ 3. **HTML Sanitization:** Remove `<script>`, event handlers in AI analysis
669
+ 4. **Asset Validation:** CORS checks, size limits on downloads
670
+ 5. **API Token:** FIGMA_ACCESS_TOKEN never logged or exposed
671
+
672
+ ---
673
+
674
+ ## Testing Strategy
675
+
676
+ **Test Coverage (50+ tests):**
677
+
678
+ - Unit tests for individual modules (screenshot, filter-css, etc.)
679
+ - Integration tests for complete workflows
680
+ - Regression tests with snapshot comparisons
681
+ - Performance benchmarks
682
+ - Accessibility validation (axe-core)
683
+
684
+ **Test Execution:**
685
+
686
+ ```bash
687
+ npm test # Run all tests
688
+ npm run test:unit # Unit tests only
689
+ npm run test:integration # Workflow tests
690
+ npm run test:accessibility # A11y checks
691
+ ```
692
+
693
+ ---
694
+
695
+ ## Future Architecture Enhancements
696
+
697
+ ### Phase 4: Component Library Generation
698
+ - Extract reusable components from Figma
699
+ - Generate Storybook-compatible stories
700
+ - Document component API and variants
701
+
702
+ ### Real-Time Sync
703
+ - Webhook support for Figma file changes
704
+ - Automatic code generation on file updates
705
+ - Design system consistency checking
706
+
707
+ ### Advanced CSS Generation
708
+ - CSS-in-JS support (styled-components, emotion)
709
+ - Shadow DOM component wrapping
710
+ - CSS Module generation for scoping
711
+
712
+ ---
713
+
714
+ ## Documentation References
715
+
716
+ - **Codebase Summary:** [codebase-summary.md](./codebase-summary.md)
717
+ - **Code Standards:** [code-standards.md](./code-standards.md)
718
+ - **Project Overview PDR:** [project-overview-pdr.md](./project-overview-pdr.md)