Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
token_lock.hpp
Go to the documentation of this file.
1#pragma once
2
31
32#include <optional>
33#include <string>
34#include <vector>
35
36namespace pulp::view {
37
38// ── Token classification ────────────────────────────────────────────────
39//
40// Not every inspector tweak is a token. A one-off element edit ("make
41// THIS knob 4px wider") is an element tweak handled by the source-locking
42// paths.
43// A token tweak edits a value the *whole design system* shares.
44//
45// Two signals classify a tweak as token-typed, in priority order:
46// 1. Anchor convention. Token tweaks carry an anchor of the form
47// `designtoken:<group>.<name>` (e.g. `designtoken:colors.primary`).
48// The inspector stamps this anchor when the selected property is
49// backed by a resolved design token rather than a literal.
50// 2. Property-path convention. A dotted path whose first segment is a
51// canonical DESIGN.md token group (`colors`, `spacing`, `rounded`,
52// `typography`) is treated as a token path even without the anchor
53// prefix — this lets the CLI and tests address tokens directly.
54//
55// Element-only paths (`paint.*`, `layout.*`, `text.*`) never classify as
56// tokens; `classify_token_tweak` returns std::nullopt for them.
57
68
70const char* token_group_key(TokenGroup group);
71
76 std::string name;
80 std::string field;
81};
82
92std::optional<TokenTarget> classify_token_tweak(const std::string& anchor_id,
93 const std::string& property_path);
94
95// ── Lock result ─────────────────────────────────────────────────────────
96
100 bool ok = false;
102 std::string error;
106 std::string updated_markdown;
110 std::string previous_value;
113 int line = 0;
114};
115
142TokenLockResult lock_token_in_designmd(const std::string& markdown,
143 const TokenTarget& target,
144 const std::string& new_value);
145
148TokenLockResult lock_token_in_designmd(const std::string& markdown,
149 const std::string& anchor_id,
150 const std::string& property_path,
151 const std::string& new_value);
152
153} // namespace pulp::view
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
std::optional< TokenTarget > classify_token_tweak(const std::string &anchor_id, const std::string &property_path)
Classify a tweak as token-typed or not.
TokenLockResult lock_token_in_designmd(const std::string &markdown, const TokenTarget &target, const std::string &new_value)
Lock a single token tweak back into DESIGN.md text.
const char * token_group_key(TokenGroup group)
Stringify a TokenGroup as its DESIGN.md frontmatter key.
TokenGroup
The four canonical DESIGN.md frontmatter token groups this engine can lock into.
Definition token_lock.hpp:62
@ spacing
spacing: map — dimension values.
Definition token_lock.hpp:64
@ typography
typography: map — nested per-level field maps.
Definition token_lock.hpp:66
@ colors
colors: map — hex string values.
Definition token_lock.hpp:63
@ rounded
rounded: map — corner-radius dimension values.
Definition token_lock.hpp:65
Outcome of a lock_token_in_designmd call.
Definition token_lock.hpp:99
int line
1-based line number within DESIGN.md that was rewritten; 0 on failure.
Definition token_lock.hpp:113
bool ok
Definition token_lock.hpp:100
std::string previous_value
The value found at the token before the rewrite — lets the inspector show a "was X,...
Definition token_lock.hpp:110
std::string error
Human-readable failure reason when ok is false; empty on success.
Definition token_lock.hpp:102
std::string updated_markdown
The rewritten DESIGN.md text.
Definition token_lock.hpp:106
A tweak classified as targeting a design token.
Definition token_lock.hpp:73
std::string field
For typography tokens only: the field within the level map, e.g.
Definition token_lock.hpp:80
std::string name
The token name within the group, e.g. "primary", "md", "lg".
Definition token_lock.hpp:76
TokenGroup group
Definition token_lock.hpp:74