From d332c18a2c166f5d6ed6c1bf52370c8315d2c282 Mon Sep 17 00:00:00 2001 From: Hamza Date: Wed, 18 Nov 2026 15:44:42 +0500 Subject: [PATCH 1/3] REST import: variables bound to stroke sides bind each side's weight (#2441) boundVariables.individualStrokeWeights was skipped with a warning, so a 1 px bottom divider bound to a variable came across as a plain number. Each side now binds strokeTopWeight ... strokeLeftWeight, read from the live API's BORDER_TOP_WEIGHT ... keys or the published spec's top ... keys. --- .../format/src/rest/proto_variable_tests.rs | 38 +++++++++++++++++++ crates/format/src/rest/variables.rs | 13 +++++++ 2 files changed, 51 insertions(+) diff --git a/crates/format/src/rest/proto_variable_tests.rs b/crates/format/src/rest/proto_variable_tests.rs index 133d45de2..3c89d8a41 100644 --- a/crates/format/src/rest/proto_variable_tests.rs +++ b/crates/format/src/rest/proto_variable_tests.rs @@ -188,6 +188,44 @@ fn bound_variables_and_explicit_modes() { assert!(has(&warnings, "pass the local variables JSON"), "{warnings:?}"); } +/// #2441: a variable bound to one or more stroke sides (`individualStrokeWeights`) binds that +/// side's weight. The live API names the sides `BORDER_TOP_WEIGHT` …, the published spec `top` …; +/// both are read, and neither is reported as skipped. +#[test] +fn variables_bound_to_stroke_sides_bind_each_sides_weight() { + let rect = |id: &str, name: &str, sides: Value| { + json!({"id": id, "name": name, "type": "RECTANGLE", "relativeTransform": at(0.0, 0.0), "size": {"x": 40, "y": 20}, + "strokes": [{"type": "SOLID", "color": rgba(0.0, 0.0, 0.0)}], "strokeWeight": 1, + "individualStrokeWeights": {"top": 1, "right": 1, "bottom": 1, "left": 1}, + "boundVariables": {"individualStrokeWeights": sides}}) + }; + let file = json!({"name": "Sides", "document": {"id": "0:0", "type": "DOCUMENT", "children": [ + {"id": "0:1", "name": "Page", "type": "CANVAS", "children": [ + rect("1:1", "Row", json!({"BORDER_BOTTOM_WEIGHT": alias(SPACE)})), + rect("1:2", "Card", json!({"BORDER_TOP_WEIGHT": alias(SPACE), "BORDER_RIGHT_WEIGHT": alias(SPACE), + "BORDER_BOTTOM_WEIGHT": alias(SPACE), "BORDER_LEFT_WEIGHT": alias(SPACE)})), + rect("1:3", "Spec", json!({"top": alias(SPACE), "left": alias(SPACE)})), + rect("1:4", "Colour", json!({"BORDER_LEFT_WEIGHT": alias(BRAND)})) + ]} + ]}}); + let (doc, warnings) = import_with(&file, Some(&variables_json()), &no_images).unwrap(); + let sides = |name: &str| -> Vec<(String, String)> { + let n = named(&doc, name); + ["strokeTopWeight", "strokeRightWeight", "strokeBottomWeight", "strokeLeftWeight"] + .iter() + .filter_map(|f| n.bound.get(*f).map(|v| (f.to_string(), v.clone()))) + .collect() + }; + let b = |f: &str| (f.to_string(), SPACE.to_string()); + assert_eq!(sides("Row"), [b("strokeBottomWeight")], "one side bound"); + assert_eq!(sides("Card"), [b("strokeTopWeight"), b("strokeRightWeight"), b("strokeBottomWeight"), b("strokeLeftWeight")]); + assert_eq!(sides("Spec"), [b("strokeTopWeight"), b("strokeLeftWeight")], "the spec's names"); + assert_eq!(sides("Colour"), [], "a colour variable can't be a weight"); + assert!(!has(&warnings, "`individualStrokeWeights`"), "{warnings:?}"); + assert!(has(&warnings, "type doesn't fit"), "{warnings:?}"); + assert!(doc.validate().is_empty(), "{:?}", doc.validate()); +} + #[test] fn embedded_variables_match_separate_ones() { let mut embedded = file_json(); diff --git a/crates/format/src/rest/variables.rs b/crates/format/src/rest/variables.rs index ba2467423..a962ded0f 100644 --- a/crates/format/src/rest/variables.rs +++ b/crates/format/src/rest/variables.rs @@ -427,6 +427,19 @@ fn node_binding<'v>(k: &str, v: &'v Value, n: &Node, out: &mut Vec<(String, &'v push(f, v.get(key).and_then(alias)); } } + // Each stroke side's weight (#2441). The live `/nodes` response names the sides + // `BORDER_TOP_WEIGHT` and so on, as `rectangleCornerRadii` names its corners; Figma's + // published OpenAPI spec names them `top` … `left`. Either is read. + "individualStrokeWeights" => { + for (keys, f) in [ + (["BORDER_TOP_WEIGHT", "top"], "strokeTopWeight"), + (["BORDER_RIGHT_WEIGHT", "right"], "strokeRightWeight"), + (["BORDER_BOTTOM_WEIGHT", "bottom"], "strokeBottomWeight"), + (["BORDER_LEFT_WEIGHT", "left"], "strokeLeftWeight"), + ] { + push(f, keys.iter().find_map(|key| v.get(*key)).and_then(alias)); + } + } "fills" | "strokes" => { let field = if k == "fills" { "fill" } else { "stroke" }; match v.as_array().and_then(|a| a.first()).and_then(alias) { From d7fcbf94caf24325f748c8e19838e17b1b2e4beb Mon Sep 17 00:00:00 2001 From: Hamza Date: Wed, 18 Nov 2026 15:57:39 +0500 Subject: [PATCH 2/3] REST import test: each of Card's sides is bound to a variable of its own So a side read into another side's field fails the test (review). --- .../format/src/rest/proto_variable_tests.rs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/format/src/rest/proto_variable_tests.rs b/crates/format/src/rest/proto_variable_tests.rs index 3c89d8a41..e54a4fbf7 100644 --- a/crates/format/src/rest/proto_variable_tests.rs +++ b/crates/format/src/rest/proto_variable_tests.rs @@ -193,6 +193,10 @@ fn bound_variables_and_explicit_modes() { /// both are read, and neither is reported as skipped. #[test] fn variables_bound_to_stroke_sides_bind_each_sides_weight() { + const TOP: &str = "VariableID:9:1"; + const RIGHT: &str = "VariableID:9:2"; + const BOTTOM: &str = "VariableID:9:3"; + const LEFT: &str = "VariableID:9:4"; let rect = |id: &str, name: &str, sides: Value| { json!({"id": id, "name": name, "type": "RECTANGLE", "relativeTransform": at(0.0, 0.0), "size": {"x": 40, "y": 20}, "strokes": [{"type": "SOLID", "color": rgba(0.0, 0.0, 0.0)}], "strokeWeight": 1, @@ -202,13 +206,19 @@ fn variables_bound_to_stroke_sides_bind_each_sides_weight() { let file = json!({"name": "Sides", "document": {"id": "0:0", "type": "DOCUMENT", "children": [ {"id": "0:1", "name": "Page", "type": "CANVAS", "children": [ rect("1:1", "Row", json!({"BORDER_BOTTOM_WEIGHT": alias(SPACE)})), - rect("1:2", "Card", json!({"BORDER_TOP_WEIGHT": alias(SPACE), "BORDER_RIGHT_WEIGHT": alias(SPACE), - "BORDER_BOTTOM_WEIGHT": alias(SPACE), "BORDER_LEFT_WEIGHT": alias(SPACE)})), + rect("1:2", "Card", json!({"BORDER_TOP_WEIGHT": alias(TOP), "BORDER_RIGHT_WEIGHT": alias(RIGHT), + "BORDER_BOTTOM_WEIGHT": alias(BOTTOM), "BORDER_LEFT_WEIGHT": alias(LEFT)})), rect("1:3", "Spec", json!({"top": alias(SPACE), "left": alias(SPACE)})), rect("1:4", "Colour", json!({"BORDER_LEFT_WEIGHT": alias(BRAND)})) ]} ]}}); - let (doc, warnings) = import_with(&file, Some(&variables_json()), &no_images).unwrap(); + // A variable of its own for each of Card's sides, so a side read into another's field fails. + let mut vars = variables_json(); + for id in [TOP, RIGHT, BOTTOM, LEFT] { + vars["meta"]["variables"][id] = json!({"id": id, "name": id, "variableCollectionId": THEME, "resolvedType": "FLOAT", + "valuesByMode": {"1:0": 1}, "scopes": ["ALL_SCOPES"]}); + } + let (doc, warnings) = import_with(&file, Some(&vars), &no_images).unwrap(); let sides = |name: &str| -> Vec<(String, String)> { let n = named(&doc, name); ["strokeTopWeight", "strokeRightWeight", "strokeBottomWeight", "strokeLeftWeight"] @@ -217,8 +227,12 @@ fn variables_bound_to_stroke_sides_bind_each_sides_weight() { .collect() }; let b = |f: &str| (f.to_string(), SPACE.to_string()); + let on = |f: &str, v: &str| (f.to_string(), v.to_string()); assert_eq!(sides("Row"), [b("strokeBottomWeight")], "one side bound"); - assert_eq!(sides("Card"), [b("strokeTopWeight"), b("strokeRightWeight"), b("strokeBottomWeight"), b("strokeLeftWeight")]); + assert_eq!( + sides("Card"), + [on("strokeTopWeight", TOP), on("strokeRightWeight", RIGHT), on("strokeBottomWeight", BOTTOM), on("strokeLeftWeight", LEFT)] + ); assert_eq!(sides("Spec"), [b("strokeTopWeight"), b("strokeLeftWeight")], "the spec's names"); assert_eq!(sides("Colour"), [], "a colour variable can't be a weight"); assert!(!has(&warnings, "`individualStrokeWeights`"), "{warnings:?}"); From 11b896699f0d5fa6fcd3e56068211e7b6afcf107 Mon Sep 17 00:00:00 2001 From: Hamza Date: Wed, 18 Nov 2026 16:24:41 +0500 Subject: [PATCH 3/3] REST import test: the spec's four side names each bind a variable of their own --- crates/format/src/rest/proto_variable_tests.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/format/src/rest/proto_variable_tests.rs b/crates/format/src/rest/proto_variable_tests.rs index e54a4fbf7..f89466194 100644 --- a/crates/format/src/rest/proto_variable_tests.rs +++ b/crates/format/src/rest/proto_variable_tests.rs @@ -208,7 +208,7 @@ fn variables_bound_to_stroke_sides_bind_each_sides_weight() { rect("1:1", "Row", json!({"BORDER_BOTTOM_WEIGHT": alias(SPACE)})), rect("1:2", "Card", json!({"BORDER_TOP_WEIGHT": alias(TOP), "BORDER_RIGHT_WEIGHT": alias(RIGHT), "BORDER_BOTTOM_WEIGHT": alias(BOTTOM), "BORDER_LEFT_WEIGHT": alias(LEFT)})), - rect("1:3", "Spec", json!({"top": alias(SPACE), "left": alias(SPACE)})), + rect("1:3", "Spec", json!({"top": alias(TOP), "right": alias(RIGHT), "bottom": alias(BOTTOM), "left": alias(LEFT)})), rect("1:4", "Colour", json!({"BORDER_LEFT_WEIGHT": alias(BRAND)})) ]} ]}}); @@ -233,7 +233,11 @@ fn variables_bound_to_stroke_sides_bind_each_sides_weight() { sides("Card"), [on("strokeTopWeight", TOP), on("strokeRightWeight", RIGHT), on("strokeBottomWeight", BOTTOM), on("strokeLeftWeight", LEFT)] ); - assert_eq!(sides("Spec"), [b("strokeTopWeight"), b("strokeLeftWeight")], "the spec's names"); + assert_eq!( + sides("Spec"), + [on("strokeTopWeight", TOP), on("strokeRightWeight", RIGHT), on("strokeBottomWeight", BOTTOM), on("strokeLeftWeight", LEFT)], + "the spec's names" + ); assert_eq!(sides("Colour"), [], "a colour variable can't be a weight"); assert!(!has(&warnings, "`individualStrokeWeights`"), "{warnings:?}"); assert!(has(&warnings, "type doesn't fit"), "{warnings:?}");