Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
design_import.hpp
Go to the documentation of this file.
1#pragma once
2
20
28
29#include <filesystem>
30#include <memory>
31#include <optional>
32#include <string>
33#include <string_view>
34#include <unordered_map>
35#include <vector>
36
37namespace pulp::view {
38
39class View;
40class Checkbox;
41class ComboBox;
43class Stepper;
44class Knob;
45class Fader;
46class LevelDisplay;
47class SeriesDisplay;
48class Meter;
49class ToggleButton;
50class TextButton;
51class TextEditor;
52class XYPad;
53class WaveformView;
54
55// ── Import report ────────────────────────────────────────────────────────────
56// Surfaces the per-control resolution provenance the IR carries so a
57// low-confidence or conflicted control is SEEN at import time — in the CLI and
58// as machine-readable JSON a CI gate can threshold — instead of discovered later.
60 std::string source_node_id;
61 std::string kind;
63 float confidence_score = 1.0f;
64 std::vector<std::string> conflict_signals;
65 bool verification_pass = true;
66};
67
69 std::vector<ImportReportEntry> controls;
70 int conflicted = 0;
72 int unresolved = 0;
75 bool ok() const { return conflicted == 0 && unresolved == 0; }
76};
77
78// Walk a parsed DesignIR root and collect the resolution report over every
79// interactive element (recursively). `low_confidence_threshold` flags controls
80// whose confidence is below it (default 0.6).
82 float low_confidence_threshold = 0.6f);
83
84// Render an ImportReport as JSON (for a CI gate / tooling) or a human summary.
85std::string import_report_to_json(const ImportReport& report);
86std::string import_report_to_text(const ImportReport& report);
87
88// Render-placement verification. Walks the IR and flags interactive overlays
89// that cannot render where
90// they claim to: a degenerate extent (no hit radius and a zero-area box), or a
91// box that falls entirely outside the node's own render region [0,0,frame_w,
92// frame_h] (when the frame size is known, >0). A flagged control gets
93// verification_pass=false plus a recorded conflict, so collect_import_report
94// surfaces it and --fail-on-unresolved can gate on it. Mutates `root` in place;
95// returns the number of controls newly flagged. frame_w/h <= 0 means "unknown"
96// (skip the bounds half, keep the degenerate-extent check). This is a
97// geometry-level check, not a pixel diff.
98int apply_placement_verification(IRNode& root, float frame_w = 0.0f, float frame_h = 0.0f);
99
100// Swap-target verification. Walks the IR and flags every `swap` element whose
101// target_frame does not name a frame that was actually captured on its own node
102// — an unset target (-1), a negative index, an index past the captured frame
103// count (1 + alternate_frames.size()), or a self-target that would make the
104// button a no-op. Such a swap would render as a button that silently does
105// nothing, so each one gets verification_pass=false plus a conflict signal,
106// which makes collect_import_report count it as `conflicted` and
107// --fail-on-unresolved exit nonzero. Mutates `root` in place; returns the number
108// of swaps newly flagged. A design with no swap elements is untouched.
110
111// One node that captured alternate frames nobody can render.
113 std::string node_name;
114 std::size_t alternates;
115 std::string reason;
116};
117
118// Alternate frames are consumed by exactly one lowering — the faithful_svg one
119// (DesignFrameView::add_frame in both the C++ codegen and the native
120// materializer). A node that carries alternate_frames but is NOT a renderable
121// faithful node (wrong render_mode, or no svg_asset_id) therefore has its extra
122// states silently dropped: the import "succeeds" and emits a single frame. This
123// walk reports every such node so a caller can fail instead of dropping states
124// without a word. An empty result means every captured state will render.
125std::vector<UnrenderableFrameSet> find_unrenderable_alternate_frames(const IRNode& root);
126
127// A node whose stable_anchor_id an earlier node already carries.
129 std::string anchor;
130 std::string path;
131 std::string node_name;
132 std::string first_path;
133 std::string first_node_name;
134};
135
136// Every node, in document order over `children`, that repeats an earlier node's
137// stable_anchor_id. Bindings, tweaks and lock-to-source address a node by that
138// anchor, so a repeat is unreachable: a generated binder that requires one match
139// binds neither. Alternate frames are not walked; a captured state deliberately
140// shares its control's identity across states.
141std::vector<DuplicateAnchor> find_duplicate_anchors(const IRNode& root);
142
144 bool apply_token_theme = true;
145 bool preview_mode = false;
146 std::vector<ImportDiagnostic>* diagnostics_out = nullptr;
150 std::filesystem::path asset_base_directory;
151};
152
154 std::vector<ImportDiagnostic>* diagnostics_out = nullptr;
155};
156
158 std::string_view route_id;
159 std::string_view param_key;
160 std::string_view binding_module;
161 std::string_view binding_param;
162 std::string_view event_contract;
163 std::string_view gesture_contract;
164};
165
167 std::string_view route_id;
168 std::string_view param_key;
169 std::string_view binding_module;
170 std::string_view binding_param;
172};
173
175 std::string_view route_id;
176 std::string_view param_key;
177 std::string_view binding_module;
178 std::string_view binding_param;
179 double min = 0.0;
180 double max = 1.0;
181 double step = 1.0;
182};
183
185 std::string_view route_id;
186 std::string_view x_param_key;
187 std::string_view y_param_key;
188 std::string_view x_binding_module;
189 std::string_view x_binding_param;
190 std::string_view y_binding_module;
191 std::string_view y_binding_param;
192 std::string_view event_contract;
193 std::string_view gesture_contract;
194};
195
201 std::string_view route_id;
202 std::string_view meter_source;
203 std::string_view channel;
204 std::string_view value_key;
205 std::string_view event_contract;
206};
207
209 std::string_view route_id;
210 std::string_view param_key;
211 std::string_view choice_value;
212 std::string_view choice_label;
213 std::string_view event_contract;
214 std::string_view gesture_contract;
215};
216
218 std::string_view route_id;
219 std::string_view param_key;
220 std::string_view shape;
221 std::string_view event_contract;
222};
223
225 std::string_view route_id;
226 std::string_view value_key;
227 std::string_view initial_value;
228 std::string_view placeholder;
229 std::string_view event_contract;
230 std::string_view focus_contract;
231};
232
234 std::string_view route_id;
235 std::string_view action;
236 std::string_view label;
237 std::string_view payload_contract;
238 std::string_view event_contract;
239 std::string_view gesture_contract;
240};
241
243public:
248
256 bool claim_import_binding(View& view, std::string_view route_id);
258
259 virtual void bind_knob(Knob& knob, const NativeImportBindingDescriptor& descriptor) {
260 (void)knob;
261 (void)descriptor;
262 }
263 virtual void bind_fader(Fader& fader, const NativeImportBindingDescriptor& descriptor) {
264 (void)fader;
265 (void)descriptor;
266 }
267 [[deprecated("override bind_level_display instead")]]
268 virtual void bind_meter(Meter& meter, const NativeImportMeterBindingDescriptor& descriptor) {
269 (void)meter;
270 (void)descriptor;
271 }
272 virtual void bind_toggle_button(ToggleButton& button, const NativeImportBindingDescriptor& descriptor) {
273 (void)button;
274 (void)descriptor;
275 }
276 virtual void bind_choice_button(ToggleButton& button, const NativeImportChoiceBindingDescriptor& descriptor) {
277 (void)button;
278 (void)descriptor;
279 }
280 virtual void bind_xy_pad(XYPad& pad, const NativeImportXYPadBindingDescriptor& descriptor) {
281 (void)pad;
282 (void)descriptor;
283 }
284 [[deprecated("override bind_series_display instead")]]
286 const NativeImportWaveformBindingDescriptor& descriptor) {
287 (void)waveform;
288 (void)descriptor;
289 }
290 virtual void bind_text_editor(TextEditor& editor, const NativeImportTextBindingDescriptor& descriptor) {
291 (void)editor;
292 (void)descriptor;
293 }
294 virtual void bind_host_action(TextButton& button, const NativeImportHostActionDescriptor& descriptor) {
295 (void)button;
296 (void)descriptor;
297 }
298
305 virtual void bind_segmented(SegmentedControl& segmented,
306 const NativeImportSegmentedBindingDescriptor& descriptor) {
307 (void)segmented;
308 (void)descriptor;
309 }
310
316 const NativeImportStepperBindingDescriptor& descriptor) {
317 (void)stepper;
318 (void)descriptor;
319 }
320 virtual void bind_checkbox(Checkbox& checkbox, const NativeImportBindingDescriptor& descriptor) {
321 (void)checkbox;
322 (void)descriptor;
323 }
324 // Provider-neutral display binders, appended after every earlier slot so
325 // existing virtuals keep their vtable positions. A context still has to be
326 // compiled against this SDK, which is how Pulp ships (static libraries).
327 virtual void bind_level_display(View& view, LevelDisplay& display,
328 const NativeImportMeterBindingDescriptor& descriptor) {
329 (void)view;
330 (void)display;
331 (void)descriptor;
332 }
334 const NativeImportWaveformBindingDescriptor& descriptor) {
335 (void)view;
336 (void)display;
337 (void)descriptor;
338 }
339};
340
348
355 const NativeImportMeterBindingDescriptor& descriptor);
357 SeriesDisplay& display,
358 const NativeImportWaveformBindingDescriptor& descriptor);
359
366public:
368 virtual void bind_combo_box(
369 ComboBox& combo,
370 const NativeImportSegmentedBindingDescriptor& descriptor) = 0;
371};
372
373std::unique_ptr<View> build_native_view_tree(
374 const DesignIR& ir,
375 const IRAssetManifest& manifest,
376 const NativeMaterializeOptions& options = {});
377
384
390 const DesignIR& ir,
392 const NativeImportBindingOptions& options = {});
393
400 const IRAssetManifest& manifest,
401 std::string_view base_directory = {});
402
421
436
452
472
487 IRNode& root,
488 const std::unordered_map<std::string, std::string>& node_id_to_param_key);
489
496std::optional<std::unordered_map<std::string, std::string>>
497parse_param_binding_manifest_json(const std::string& json, std::string* error);
498
499} // namespace pulp::view
Definition widgets.hpp:2111
Drop-down selector for enumerated parameters.
Definition ui_components.hpp:43
Definition widgets.hpp:1337
Definition widgets.hpp:901
Generic level, series and bin display seams owned by view-core.
Definition data_display.hpp:24
Definition audio_widgets.hpp:19
Definition design_import.hpp:242
virtual void bind_checkbox(Checkbox &checkbox, const NativeImportBindingDescriptor &descriptor)
Definition design_import.hpp:320
bool claim_import_binding(View &view, std::string_view route_id)
Claim a materialized view/route pair before installing callbacks.
virtual ~NativeImportBindingContext()
Descriptor string_view fields passed to bind_* callbacks are borrowed and valid only for the duration...
virtual void bind_segmented(SegmentedControl &segmented, const NativeImportSegmentedBindingDescriptor &descriptor)
A segmented selector.
Definition design_import.hpp:305
virtual void bind_waveform_display(WaveformView &waveform, const NativeImportWaveformBindingDescriptor &descriptor)
Definition design_import.hpp:285
virtual void bind_choice_button(ToggleButton &button, const NativeImportChoiceBindingDescriptor &descriptor)
Definition design_import.hpp:276
virtual void bind_fader(Fader &fader, const NativeImportBindingDescriptor &descriptor)
Definition design_import.hpp:263
virtual void bind_stepper(Stepper &stepper, const NativeImportStepperBindingDescriptor &descriptor)
A stepper.
Definition design_import.hpp:315
virtual void bind_knob(Knob &knob, const NativeImportBindingDescriptor &descriptor)
Definition design_import.hpp:259
virtual void bind_xy_pad(XYPad &pad, const NativeImportXYPadBindingDescriptor &descriptor)
Definition design_import.hpp:280
virtual void bind_level_display(View &view, LevelDisplay &display, const NativeImportMeterBindingDescriptor &descriptor)
Definition design_import.hpp:327
virtual void bind_series_display(View &view, SeriesDisplay &display, const NativeImportWaveformBindingDescriptor &descriptor)
Definition design_import.hpp:333
virtual void bind_text_editor(TextEditor &editor, const NativeImportTextBindingDescriptor &descriptor)
Definition design_import.hpp:290
virtual void bind_toggle_button(ToggleButton &button, const NativeImportBindingDescriptor &descriptor)
Definition design_import.hpp:272
virtual void bind_host_action(TextButton &button, const NativeImportHostActionDescriptor &descriptor)
Definition design_import.hpp:294
virtual void bind_meter(Meter &meter, const NativeImportMeterBindingDescriptor &descriptor)
Definition design_import.hpp:268
Optional capability for binding a collapsed selector.
Definition design_import.hpp:365
virtual void bind_combo_box(ComboBox &combo, const NativeImportSegmentedBindingDescriptor &descriptor)=0
Horizontal segmented selector — a row of mutually-exclusive labeled segments sharing one inset track,...
Definition ui_components.hpp:443
Definition data_display.hpp:39
Definition gap_widgets.hpp:95
Definition buttons.hpp:17
Text editing widget with comprehensive keyboard/mouse interaction.
Definition text_editor.hpp:47
Definition widgets.hpp:2383
Definition view.hpp:73
Definition audio_widgets.hpp:219
Definition widgets.hpp:2599
Code generation from a DesignIR: native-bridge / web-compat JS emission, baked-C++ view artifact expo...
Normalized intermediate representation (IR) for imported designs: the IR value model (style,...
Keyboard-shortcut import for designs: static-scan extracted shortcuts, platform-convention default sh...
Source adapters that lower external design exports into the normalized DesignIR: Figma / Stitch / v0 ...
W3C Design Tokens and external-tool token sync.
TextRasterPolicy
Glyph preblend a surface is created with.
Definition text_raster_policy.hpp:33
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
void invoke_legacy_import_binder(std::string_view id, NativeImportBindingContext &, View &, const NativeImportMeterBindingDescriptor *meter, const NativeImportWaveformBindingDescriptor *waveform)
int apply_param_binding_manifest(IRNode &root, const std::unordered_map< std::string, std::string > &node_id_to_param_key)
Bind geometry-detected controls to host parameters from an out-of-band manifest that maps a Figma nod...
std::unique_ptr< View > build_native_view_tree(const DesignIR &ir, const IRAssetManifest &manifest, const NativeMaterializeOptions &options={})
std::vector< DuplicateAnchor > find_duplicate_anchors(const IRNode &root)
canvas::TextRasterPolicy design_ir_text_raster_policy(const DesignIR &ir)
The text raster policy a surface showing ir should be created with: chromium when any captured text n...
void register_legacy_import_binder(std::string id, LegacyImportBinder binder)
void reconnect_slider_fill(IRNode &root)
Reconnect a slider's progress fill to its thumb.
void normalize_border_shorthand(IRNode &root)
Split the CSS border shorthand — "1px solid #333" — into the discrete border_color / border_width / b...
void bind_imported_level_display(NativeImportBindingContext &ctx, View &view, LevelDisplay &display, const NativeImportMeterBindingDescriptor &descriptor)
Bind an imported level or series display through both binder generations: the provider-neutral virtua...
int apply_swap_target_verification(IRNode &root)
std::string import_report_to_text(const ImportReport &report)
@ fader
Definition design_ir.hpp:261
@ stepper
Definition design_ir.hpp:281
@ waveform
Definition design_ir.hpp:264
@ knob
Definition design_ir.hpp:260
void enrich_imported_image_asset_metadata(DesignIR &ir, const IRAssetManifest &manifest, std::string_view base_directory={})
Resolve imported image asset_ref nodes against an asset manifest and stamp source-derived metadata on...
void hoist_captured_art_knobs(DesignIR &ir)
Captured-art knob promotion.
void(*)(NativeImportBindingContext &, View &, const NativeImportMeterBindingDescriptor *, const NativeImportWaveformBindingDescriptor *) LegacyImportBinder
Definition design_import.hpp:341
void bind_native_view_tree(View &root, const DesignIR &ir, NativeImportBindingContext &ctx, const NativeImportBindingOptions &options={})
Apply explicit pulp* binding metadata from ir to an already materialized native view tree.
std::optional< std::unordered_map< std::string, std::string > > parse_param_binding_manifest_json(const std::string &json, std::string *error)
Parse a --param-binding-manifest document — a flat JSON object mapping a Figma node id to a host-para...
int apply_placement_verification(IRNode &root, float frame_w=0.0f, float frame_h=0.0f)
void synthesize_primitive_paths(IRNode &root)
Source-agnostic IR normalization for vector SHAPE PRIMITIVES.
@ meter
a Meter's level
Definition binding_diagnostics.hpp:20
ImportReport collect_import_report(const IRNode &root, float low_confidence_threshold=0.6f)
std::string import_report_to_json(const ImportReport &report)
std::vector< UnrenderableFrameSet > find_unrenderable_alternate_frames(const IRNode &root)
void bind_imported_series_display(NativeImportBindingContext &ctx, View &view, SeriesDisplay &display, const NativeImportWaveformBindingDescriptor &descriptor)
@ error
Definition design_ir.hpp:697
Complete design IR document.
Definition design_ir.hpp:791
Definition design_import.hpp:128
std::string anchor
Definition design_import.hpp:129
std::string node_name
the repeat's name, or "<unnamed>"
Definition design_import.hpp:131
std::string first_node_name
Definition design_import.hpp:133
std::string first_path
the earlier node that keeps the anchor
Definition design_import.hpp:132
std::string path
$/children[i]/... of the repeat
Definition design_import.hpp:130
Definition design_ir.hpp:739
Definition design_ir.hpp:614
Definition design_import.hpp:59
bool verification_pass
Definition design_import.hpp:65
std::string source_node_id
Figma node id (empty if unknown).
Definition design_import.hpp:60
std::string kind
resolved interactive-element kind
Definition design_import.hpp:61
int resolution_rung
0=unset..5=inert (see InteractiveElementKind)
Definition design_import.hpp:62
std::vector< std::string > conflict_signals
cross-signal conflicts
Definition design_import.hpp:64
float confidence_score
0..1
Definition design_import.hpp:63
Definition design_import.hpp:68
bool ok() const
True when the import is clean enough to pass a CI gate at the given policy (no conflicts and nothing ...
Definition design_import.hpp:75
int conflicted
controls with >=1 conflict signal
Definition design_import.hpp:70
int unresolved
controls resolved only at the inert rung (5)
Definition design_import.hpp:72
int low_confidence
controls with confidence below the threshold
Definition design_import.hpp:71
std::vector< ImportReportEntry > controls
Definition design_import.hpp:69
Definition design_import.hpp:157
std::string_view event_contract
Definition design_import.hpp:162
std::string_view param_key
Definition design_import.hpp:159
std::string_view route_id
Definition design_import.hpp:158
std::string_view binding_module
Definition design_import.hpp:160
std::string_view binding_param
Definition design_import.hpp:161
std::string_view gesture_contract
Definition design_import.hpp:163
Definition design_import.hpp:153
std::vector< ImportDiagnostic > * diagnostics_out
Definition design_import.hpp:154
Definition design_import.hpp:208
std::string_view event_contract
Definition design_import.hpp:213
std::string_view choice_value
Definition design_import.hpp:211
std::string_view route_id
Definition design_import.hpp:209
std::string_view param_key
Definition design_import.hpp:210
std::string_view gesture_contract
Definition design_import.hpp:214
std::string_view choice_label
Definition design_import.hpp:212
Definition design_import.hpp:233
std::string_view event_contract
Definition design_import.hpp:238
std::string_view payload_contract
Definition design_import.hpp:237
std::string_view action
Definition design_import.hpp:235
std::string_view route_id
Definition design_import.hpp:234
std::string_view gesture_contract
Definition design_import.hpp:239
std::string_view label
Definition design_import.hpp:236
A level display's binding.
Definition design_import.hpp:200
std::string_view meter_source
Definition design_import.hpp:202
std::string_view value_key
Definition design_import.hpp:204
std::string_view route_id
Definition design_import.hpp:201
std::string_view event_contract
Definition design_import.hpp:205
std::string_view channel
Definition design_import.hpp:203
std::string_view route_id
Definition design_import.hpp:167
std::string_view binding_module
Definition design_import.hpp:169
std::string_view param_key
Definition design_import.hpp:168
std::string_view binding_param
Definition design_import.hpp:170
int segment_count
Definition design_import.hpp:171
Definition design_import.hpp:174
std::string_view binding_module
Definition design_import.hpp:177
std::string_view binding_param
Definition design_import.hpp:178
double step
Definition design_import.hpp:181
std::string_view param_key
Definition design_import.hpp:176
std::string_view route_id
Definition design_import.hpp:175
double max
Definition design_import.hpp:180
double min
Definition design_import.hpp:179
Definition design_import.hpp:224
std::string_view value_key
Definition design_import.hpp:226
std::string_view event_contract
Definition design_import.hpp:229
std::string_view focus_contract
Definition design_import.hpp:230
std::string_view initial_value
Definition design_import.hpp:227
std::string_view route_id
Definition design_import.hpp:225
std::string_view placeholder
Definition design_import.hpp:228
std::string_view shape
Definition design_import.hpp:220
std::string_view param_key
Definition design_import.hpp:219
std::string_view event_contract
Definition design_import.hpp:221
std::string_view route_id
Definition design_import.hpp:218
Definition design_import.hpp:184
std::string_view y_param_key
Definition design_import.hpp:187
std::string_view gesture_contract
Definition design_import.hpp:193
std::string_view event_contract
Definition design_import.hpp:192
std::string_view x_param_key
Definition design_import.hpp:186
std::string_view x_binding_module
Definition design_import.hpp:188
std::string_view y_binding_module
Definition design_import.hpp:190
std::string_view y_binding_param
Definition design_import.hpp:191
std::string_view x_binding_param
Definition design_import.hpp:189
std::string_view route_id
Definition design_import.hpp:185
Definition design_import.hpp:143
std::filesystem::path asset_base_directory
Resolve relative manifest local_path values against the DesignIR document directory.
Definition design_import.hpp:150
bool preview_mode
Definition design_import.hpp:145
std::vector< ImportDiagnostic > * diagnostics_out
Definition design_import.hpp:146
bool apply_token_theme
Definition design_import.hpp:144
Definition design_import.hpp:112
std::size_t alternates
how many captured states would be dropped
Definition design_import.hpp:114
std::string node_name
the node's name, or "<unnamed>"
Definition design_import.hpp:113
std::string reason
why they cannot render
Definition design_import.hpp:115