figma_schema/
type_style.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Deserialize, Serialize, Copy, Clone)]
4#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
5#[typeshare::typeshare]
6pub enum TextCase {
7    Upper,
8    Lower,
9    Title,
10    SmallCaps,
11    SmallCapsForced,
12}
13
14#[derive(Debug, Deserialize, Serialize, Copy, Clone)]
15#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
16#[typeshare::typeshare]
17pub enum TextDecoration {
18    Strikethrough,
19    Underline,
20}
21
22#[derive(Debug, Deserialize, Serialize)]
23#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
24#[typeshare::typeshare]
25pub enum TextAutoResize {
26    Height,
27    WidthAndHeight,
28    /// The text will be shortened and trailing text will be replaced with "…" if the text contents is larger than the bounds
29    Truncate,
30}
31
32/// Type of hyperlink
33#[derive(Debug, Deserialize, Serialize)]
34#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
35#[typeshare::typeshare]
36pub enum HyperlinkType {
37    Url,
38    Node,
39}
40
41#[derive(Debug, Deserialize, Serialize)]
42#[serde(rename_all = "camelCase")]
43#[typeshare::typeshare]
44pub struct Hyperlink {
45    pub r#type: Option<HyperlinkType>,
46    /// URL being linked to, if URL type
47    pub url: Option<String>,
48    /// ID of frame hyperlink points to, if NODE type
49    pub node_id: Option<String>,
50}
51
52/// Metadata for character formatting
53///
54/// [Figma documentation](https://www.figma.com/developers/api#typestyle-type)
55#[derive(Debug, Deserialize, Serialize)]
56#[serde(rename_all = "camelCase")]
57#[typeshare::typeshare]
58pub struct TypeStyle {
59    /// Font family of text (standard name)
60    pub font_family: String,
61    /// Space between paragraphs in px, 0 if not present
62    pub paragraph_spacing: Option<f64>,
63    /// Whether or not text is italicized
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub italic: Option<bool>,
66    /// Numeric font weight
67    pub font_weight: f64,
68    /// Font size in px
69    pub font_size: f64,
70    /// Text casing applied to the node, default is the original casing
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub text_case: Option<TextCase>,
73    /// Text decoration applied to the node, default is none
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub text_decoration: Option<TextDecoration>,
76    /// Dimensions along which text will auto resize, default is that the text does not auto-resize
77    pub text_auto_resize: Option<TextAutoResize>,
78    /// Link to a URL or frame
79    pub hyperlink: Option<Hyperlink>,
80    /// Line height in px
81    pub line_height_px: f64,
82}