Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
anchor_strategy.hpp File Reference

Stable-anchor-id assignment for design-import IR nodes. More...

#include <pulp/view/design_import.hpp>
#include <string>
#include <string_view>
#include <vector>

Go to the source code of this file.

Classes

struct  pulp::view::AnchorDisambiguation
 One derived anchor a collision pass replaced. More...

Namespaces

namespace  pulp
namespace  pulp::view
 Hover-cursor tracking for platform window hosts.

Enumerations

enum class  pulp::view::AnchorStrategy { pulp::view::content_hash , pulp::view::path , pulp::view::adapter }
 Strategy for computing stable_anchor_id values. See header comment. More...

Functions

void pulp::view::assign_anchors (IRNode &root, AnchorStrategy strategy, std::string_view adapter_name="")
 Walk root and populate stable_anchor_id on every node according to strategy.
std::vector< AnchorDisambiguation > pulp::view::resolve_anchor_collisions (IRNode &root)
 Makes every derived anchor in root unique, in document order over children.
std::string pulp::view::compute_anchor_id (const IRNode &node, std::string_view parent_anchor, std::size_t sibling_tag_index_for_path, std::size_t depth, std::size_t sig_index_for_content_hash, AnchorStrategy strategy, std::string_view adapter_name="")
 Compute a single anchor without walking.
AnchorStrategy pulp::view::default_anchor_strategy (DesignSource source)
 Map a DesignSource to its default anchor strategy.

Detailed Description

Stable-anchor-id assignment for design-import IR nodes.

The rendered children axis mirrors the TS-side @pulp/import-ir/src/anchors.ts strategy so the C++ and TS import pipelines produce compatible anchors and the tweaks layer (pulp-tweaks.json) works for either path. Native C++ IR also carries an ordered alternate_frames axis; that axis is scoped to this native importer until the TS IR and its consumers grow the same field.

Three strategies are supported: • content-hash — used by stitch / v0 / claude / generic HTML. Hash over (tag, role, normalized text, depth, sigIndex). • path — used by RN file exports / hand-edited code. "Tag[idx]/Tag[idx]/..." from root. • adapter — used by Figma / Pencil / Mitosis (sources with native IDs). "<adapter>:<source_node_id>".

The walker is purely traversal-shaped — it mutates IRNode::stable_anchor_id but otherwise leaves the tree alone. It visits both the rendered children axis and the ordered alternate_frames axis. Alternate roots use a reserved @alternate[index] path namespace and an @alternate/<type> content-hash namespace. Content-hash descendants under an alternate root carry the same marker without the frame index, so equivalent controls across captured states retain one identity while ordinary children cannot collide. Adapter identities continue to use their source node IDs. Adapters call assign_anchors() in the final stage of their parse path. The @alternate namespace is reserved for this walker. Adapter strategies assume the source supplies unique node IDs; this low-level API preserves duplicate authored IDs rather than silently rewriting source identity.