Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
recognition_resolver.hpp
Go to the documentation of this file.
1#pragma once
2
45
47
48#include <filesystem>
49#include <optional>
50#include <string>
51#include <unordered_map>
52#include <vector>
53
54namespace pulp::view {
55
75
80 std::string name;
81 std::vector<RecognitionEntry> entries;
82};
83
86 bool matched = false;
88 std::string factory_id;
89 std::string source_name;
91 std::string via;
92};
93
99
105public:
109
113
120 static std::optional<RecognitionSource> parse_manifest_json(
121 const std::string& json,
122 const std::string& source_name,
123 std::string* error_out = nullptr);
124
128 ResolvedControl resolve(const std::string& component_key,
129 const std::string& name) const;
130
132 bool empty() const { return sources_.empty(); }
133
134private:
135 std::vector<RecognitionSource> sources_;
136};
137
152 std::string component_key;
153 std::string name;
154};
156 const RecognitionResolver& resolver,
157 std::vector<UnmatchedComponent>* unmatched_out = nullptr);
158
159// ── Installed-package custom-control source ───────────────────────────────────
160// Gather every installed package's `design_controls` fragments into recognition
161// sources the resolver consumes. A package declares custom controls in its
162// registry entry under `design_controls`: an array of
163// { "factory_id": "<id>", "component_set_key"?: "<key>", "name_prefix"?: "<p>" }
164// each mapping a Figma identity to the `factory_id` the package's
165// `pulp::view::View` registers via `register_design_control_factory`. The merge
166// reads two project-local files:
167// - the lockfile (packages.lock.json): WHICH packages are installed, by id;
168// - the registry (registry.json): each package's `design_controls` fragment.
169// One `RecognitionSource` is produced per installed package that declares any
170// design control, named by package id so a wired control's provenance is
171// traceable. A package with no `design_controls` contributes nothing — so with
172// no custom-control package installed the result is empty and behavior is
173// unchanged.
174//
175// Reads files directly with choc::json (no CLI dependency) so the importer can
176// build the merged table without linking the package CLI. Missing/empty/invalid
177// files yield an empty result (with an optional human-readable warning), never
178// an error — a malformed registry must not break an import.
180 std::vector<RecognitionSource> sources;
181 std::vector<std::string> warnings;
182};
183
184// Build the per-package custom-control sources from explicit file paths. Either
185// file may be absent. Use this overload in tests and when the paths are known.
187 const std::filesystem::path& lockfile_path,
188 const std::filesystem::path& registry_path);
189
190// Discover the project's packages.lock.json and registry.json by walking up
191// from `start_dir` (looking for a sibling pair), then gather. Returns an empty
192// result when no lockfile is found. Convenience wrapper used by the importer.
194 const std::filesystem::path& start_dir);
195
196// ── Materialize half: stamp resolved custom controls onto the IR ─────────────
197// Walk the IR and, for every node the resolver stamped with a custom-control
198// `recognitionFactoryId` (see apply_recognition_resolver), append a
199// `kind=custom` IRInteractiveElement carrying that `factory_id` so the native
200// materializer builds the registered overlay — or renders inert + diagnoses
201// when the factory is unregistered (never a silent knob). Geometry
202// is taken from the node's own box; `source_node_id` is carried so the
203// inspector can map the control back to its design node.
204//
205// Idempotent and strictly additive: a node that already carries a custom
206// interactive element for the same factory_id is not double-stamped, and a node
207// without a `recognitionFactoryId` is untouched. Returns the number of custom
208// elements newly materialized.
210
211} // namespace pulp::view
The single merge layer.
Definition recognition_resolver.hpp:104
RecognitionResolver & add_source(RecognitionSource source)
Append a source.
static std::optional< RecognitionSource > parse_manifest_json(const std::string &json, const std::string &source_name, std::string *error_out=nullptr)
Parse a recognition manifest in the flat library-manifest.json shape: { "widgets": { "<name>": { "kin...
ResolvedControl resolve(const std::string &component_key, const std::string &name) const
Resolve one node's identity.
bool empty() const
Whether any source contributed at least one entry.
Definition recognition_resolver.hpp:132
RecognitionResolver()=default
Empty resolver (no built-in seed) — used by tests and by callers that want full control over the sour...
Normalized intermediate representation (IR) for imported designs: the IR value model (style,...
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
PackageDesignControlSources gather_package_design_controls(const std::filesystem::path &lockfile_path, const std::filesystem::path &registry_path)
AudioWidgetType audio_widget_kind_from_manifest_id(const std::string &id)
Map an AudioWidgetType to/from the lowercase id used in manifests and the figma-plugin envelope ("kno...
int materialize_recognized_custom_controls(IRNode &root)
AudioWidgetType
Audio widget type detected from naming conventions or annotations.
Definition design_ir.hpp:258
@ none
Definition design_ir.hpp:259
const char * audio_widget_kind_to_manifest_id(AudioWidgetType kind)
int apply_recognition_resolver(IRNode &root, const RecognitionResolver &resolver, std::vector< UnmatchedComponent > *unmatched_out=nullptr)
PackageDesignControlSources discover_package_design_controls(const std::filesystem::path &start_dir)
Definition design_ir.hpp:614
Definition recognition_resolver.hpp:179
std::vector< RecognitionSource > sources
Definition recognition_resolver.hpp:180
std::vector< std::string > warnings
non-fatal parse/skip notes
Definition recognition_resolver.hpp:181
One recognition source: a flat map of a designer's component identity to the Pulp control it material...
Definition recognition_resolver.hpp:60
std::string component_set_key
Figma published component-set key (authoritative identity).
Definition recognition_resolver.hpp:66
std::string factory_id
#4677 (custom controls): the registered factory id this identity resolves to.
Definition recognition_resolver.hpp:73
std::string name_prefix
Optional layer/component name prefix fallback (case-insensitive), used when no key matched.
Definition recognition_resolver.hpp:69
AudioWidgetType kind
Pulp built-in control kind.
Definition recognition_resolver.hpp:63
A named bundle of recognition entries from one origin (built-in library, user manifest,...
Definition recognition_resolver.hpp:79
std::vector< RecognitionEntry > entries
Definition recognition_resolver.hpp:81
std::string name
e.g. "builtin-library", "user-manifest", "<pkg>"
Definition recognition_resolver.hpp:80
The result of resolving one node's identity against the merged table.
Definition recognition_resolver.hpp:85
std::string via
How it matched: "key" (authoritative) or "name_prefix" (fallback).
Definition recognition_resolver.hpp:91
std::string source_name
which source won the match
Definition recognition_resolver.hpp:89
AudioWidgetType kind
Definition recognition_resolver.hpp:87
std::string factory_id
non-empty only for custom-control matches
Definition recognition_resolver.hpp:88
bool matched
Definition recognition_resolver.hpp:86
Apply the resolver to a parsed figma-plugin IR tree IN PLACE: for every node that carries a Figma com...
Definition recognition_resolver.hpp:151
std::string name
Definition recognition_resolver.hpp:153
std::string component_key
Definition recognition_resolver.hpp:152