Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
design_sources.hpp
Go to the documentation of this file.
1#pragma once
2
12
16#include <cstdint>
17#include <map>
18#include <memory>
19#include <string>
20#include <string_view>
21#include <optional>
22#include <vector>
23#include <unordered_map>
24
25namespace pulp::view {
26
27// ── Design source helpers ───────────────────────────────────────────────
28//
29// The DesignSource enum itself lives in design_ir.hpp (DesignIR::source uses
30// it by value). These string<->enum helpers live with the source adapters.
31
33std::optional<DesignSource> parse_design_source(const std::string& name);
34
36const char* design_source_name(DesignSource source);
37
41
42// ── Source adapters ─────────────────────────────────────────────────────
43
45DesignIR parse_figma_json(const std::string& json);
46
48DesignIR parse_figma_plugin_json(const std::string& json);
49
51DesignIR parse_stitch_html(const std::string& html);
52
54DesignIR parse_v0_tsx(const std::string& tsx);
55
57DesignIR parse_pencil_json(const std::string& json);
58
64DesignIR parse_claude_html(const std::string& html);
65
66// ── DESIGN.md adapter (Google design.md, Apache-2.0) ─────────────────────
67//
68// DESIGN.md is a YAML-frontmatter + Markdown-body description of a design
69// system. Unlike the other import sources, it does NOT describe a screen
70// or a renderable artifact — it carries tokens and prose rationale. The
71// parser populates IR token maps; the IR root node is left empty (no
72// children, type "frame"). It deliberately does NOT scaffold a
73// placeholder UI tree; that would imply scaffold quality Pulp cannot yet
74// deliver. Spec: https://github.com/google-labs-code/design.md
75//
76// Diagnostics use a structured shape so the CLI can emit them as JSON
77// with line/column info supplied by yaml-cpp.
78
82DesignMdParseResult parse_designmd(const std::string& markdown);
83
87DesignIR parse_designmd_yaml(const std::string& markdown);
88
89// ── Lint, diff, and Tailwind export ─────────────────────────────────────
90//
91// These surfaces let DESIGN.md slot into CI gates the same way
92// @google/design.md's TypeScript CLI does, without taking on its JS
93// dependency surface. The lint rule set tracks the format rules Pulp consumes,
94// including DESIGN.md 0.4 omitted-section and token-schema validation.
95
98std::vector<DesignMdDiagnostic> lint_designmd(const DesignMdParseResult& parsed);
99
103 const DesignMdParseResult& after);
104
111
117
118// ── Claude Design bundle envelope (pulp #468) ───────────────────────────
119//
120// Claude Design's "standalone HTML" export is a small loader shell
121// wrapping a JSON envelope of base64-gzip-compressed assets. The loader
122// JS unpacks the envelope at runtime and replaces `document.documentElement.innerHTML`
123// with the unwrapped template HTML, then injects the bundled scripts.
124//
125// For the native-runtime import lane (`--execute-bundle`), Pulp needs to
126// reproduce that unpack step in C++ before handing the result to the JS
127// engine. This function performs only the unpack — running the result is
128// `parse_claude_html_with_runtime`'s job.
129
134std::optional<ClaudeBundle> parse_claude_bundle(const std::string& html);
135
141std::optional<ClaudeBundle> parse_materialized_browser_document(
142 const std::string& json);
143
155std::shared_ptr<const ClaudeBundle> parse_materialized_browser_document_shared(
156 const std::string& json);
157
161
166std::vector<std::string> runtime_import_whole_scripts(const ClaudeBundle& bundle);
167
174std::optional<ClaudeBundle> parse_v0_dev_react(const std::string& tsx_or_envelope);
175
181std::optional<ClaudeBundle> parse_figma_make_react(const std::string& tsx);
182
189std::optional<ClaudeBundle> parse_stitch_react(const std::string& tsx);
190
197std::optional<ClaudeBundle> parse_react_native_export(const std::string& tsx);
198
206std::optional<ClaudeBundle> parse_pencil_react(const std::string& tsx);
207
223std::optional<ClaudeBundle> parse_jsx_react(const std::string& bundle_js,
224 const std::string& component_name = "JsxComponent");
225
237std::string synthesize_runtime_envelope(const ClaudeBundle& bundle);
238
246 ClaudeRuntimeOptions opts = {});
247
248// ── Claude Design classname extraction (pulp #1035) ─────────────────────
249//
250// Spectr's `tools/extract-html-bundle/extract.mjs` walks every `<style>`
251// block in a Claude Design export and emits a `classnames.json` mapping
252// of `classname → { cssProp: cssValue, ... }` (camelCase keys, raw
253// values). The downstream `@pulp/css-adapt` layer consumes that map to
254// merge class-based styles into inline before forwarding to bridge
255// calls. Pulp's `pulp import-design --from claude` bakes that pass into
256// the import pipeline so plugin authors get the same artifact without
257// having to run a separate Node-side script.
258//
259// Result type (ClaudeClassNameRules, design_source_types.hpp): outer map keyed by classname (no leading dot), inner map
260// keyed by CSS property in camelCase (e.g. `font-family` → `fontFamily`).
261// Multiple `<style>` blocks in document order are merged; later blocks
262// override earlier ones for the same classname (mirrors browser
263// cascading order). `.scheme-*` rules are skipped — those are already
264// handled as theme-mode token overrides upstream.
265
273
280
281} // namespace pulp::view
Normalized intermediate representation (IR) for imported designs: the IR value model (style,...
Importer operations over the DesignIR value model: canonical JSON serialize/parse,...
Value types exchanged with the design-source adapters: DESIGN.md parse and diff results,...
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
ClaudeClassNameRules extract_claude_classnames(const std::string &html)
Extract classname → declaration map from a Claude Design HTML export.
std::optional< ClaudeBundle > parse_jsx_react(const std::string &bundle_js, const std::string &component_name="JsxComponent")
Wrap a pre-compiled JSX runtime bundle (esbuild IIFE of React plus either ReactDOM or the @pulp/react...
DesignMdParseResult parse_designmd(const std::string &markdown)
Parse a DESIGN.md file (YAML frontmatter + Markdown body) into a DesignIR.
SnapshotDynamicApiScan detect_jsx_snapshot_dynamic_apis(std::string_view source)
Detect dynamic APIs that make a JSX baked snapshot non-deterministic unless the caller explicitly acc...
std::optional< ClaudeBundle > parse_v0_dev_react(const std::string &tsx_or_envelope)
Normalize a constrained v0.dev React TSX export into the runtime-import bundle payload shape.
DesignIR parse_designmd_yaml(const std::string &markdown)
Thin wrapper that returns just the IR.
DesignIR parse_claude_html(const std::string &html)
Parse a Claude Design standalone HTML export into a DesignIR.
std::optional< ClaudeBundle > parse_figma_make_react(const std::string &tsx)
Normalize a constrained Figma Make React TSX export into the runtime-import bundle payload shape.
MaterializedDocumentCacheStats materialized_document_cache_stats()
std::optional< ClaudeBundle > parse_stitch_react(const std::string &tsx)
Normalize a constrained Google Stitch React export into the runtime-import bundle payload shape.
DesignIR parse_claude_html_with_runtime(const std::string &html, ClaudeRuntimeOptions opts={})
Run the Claude Design bundle in a headless JS engine and harvest the materialized DOM into a DesignIR...
std::shared_ptr< const ClaudeBundle > parse_materialized_browser_document_shared(const std::string &json)
parse_materialized_browser_document with process-wide reuse.
std::optional< ClaudeBundle > parse_react_native_export(const std::string &tsx)
Normalize a constrained React Native single-file component export into the runtime-import bundle payl...
std::string export_tailwind_v4_css(const DesignMdParseResult &parsed)
Emit a Tailwind v4 @theme { ... } CSS block from the parsed token tree.
void clear_materialized_document_cache()
Drop every kept document (tests; a host that wants the memory back).
DesignIR parse_v0_tsx(const std::string &tsx)
Parse v0-generated TSX/Tailwind into a DesignIR.
std::string serialize_claude_classnames(const ClaudeClassNameRules &rules)
Serialize a ClaudeClassNameRules map to the JSON shape Spectr's extract.mjs produces.
DesignIR parse_pencil_json(const std::string &json)
Parse Pencil node tree JSON into a DesignIR.
std::string synthesize_runtime_envelope(const ClaudeBundle &bundle)
Synthesize a Claude-style HTML envelope around an arbitrary ClaudeBundle so the existing parse_claude...
DesignSource
Definition design_ir.hpp:37
@ html
Definition design_ir.hpp:46
std::string export_tailwind_v3_json(const DesignMdParseResult &parsed)
Emit a Tailwind v3 theme.extend-shaped JSON object from the parsed token tree.
DesignIR parse_figma_plugin_json(const std::string &json)
Parse Pulp's "Design for Pulp" Figma-plugin export envelope.
std::optional< ClaudeBundle > parse_materialized_browser_document(const std::string &json)
Decode the deterministic pre-mount document emitted by Chromium browser capture.
DesignIR parse_stitch_html(const std::string &html)
Parse Stitch HTML export into a DesignIR.
DesignMdDiffResult diff_designmd(const DesignMdParseResult &before, const DesignMdParseResult &after)
Compute the token diff between two parsed DESIGN.md files plus a regression flag derived from their r...
std::optional< ClaudeBundle > parse_claude_bundle(const std::string &html)
Decode the bundler envelope from a Claude Design standalone HTML file.
std::map< std::string, std::map< std::string, std::string > > ClaudeClassNameRules
Definition design_source_types.hpp:160
std::optional< DesignSource > parse_design_source(const std::string &name)
Convert string to DesignSource, returns nullopt for unknown sources.
std::optional< ClaudeBundle > parse_pencil_react(const std::string &tsx)
Normalize a constrained Pencil/OpenPencil sanitized Tailwind-JSX export into the runtime-import bundl...
std::vector< DesignMdDiagnostic > lint_designmd(const DesignMdParseResult &parsed)
Run Pulp's Google design.md compatibility lint against a parsed DESIGN.md.
DesignIR parse_figma_json(const std::string &json)
Parse a Figma export JSON into a DesignIR.
std::vector< std::string > runtime_import_whole_scripts(const ClaudeBundle &bundle)
The whole scripts a live editor evaluates when it imports bundle at run time (__pulpRuntimeImport__):...
const char * design_source_name(DesignSource source)
Convert DesignSource to display name.
Result of unpacking a Claude Design bundle's <script type="__bundler/manifest">.
Definition design_source_types.hpp:113
Options for the --execute-bundle import lane.
Definition design_source_types.hpp:133
Complete design IR document.
Definition design_ir.hpp:791
Definition design_source_types.hpp:71
Definition design_source_types.hpp:45
Definition design_source_types.hpp:123
Definition design_source_types.hpp:21