Merge pull request #2464 from storytold/fix/rest-binding-warnings-2441

M6: REST import reports node-level paint and effect bindings only when something is lost (#2441)
This commit is contained in:
BFlat authored and GitHub committed 2026-11-19 04:05:50 +07:00
commit f2696e0dbf
3 files changed
+74 -1

No files matched your search

@@ -244,6 +244,55 @@ fn variables_bound_to_stroke_sides_bind_each_sides_weight() {
assert!(doc.validate().is_empty(), "{:?}", doc.validate());
}
/// #2441: node-level `fills`, `effects` and `textRangeFills` lists repeat what each gradient stop,
/// effect and paint binds itself. When those are read, nothing is lost and nothing is reported; a
/// list naming a variable they don't bind still is.
#[test]
fn node_level_lists_the_paints_and_effects_bind_are_not_reported() {
const ACCENT: &str = "VariableID:1:4";
let gradient = |stop_var: Option<&str>| {
let first = match stop_var {
Some(v) => json!({"position": 0, "color": rgba(1.0, 0.0, 0.0), "boundVariables": {"color": alias(v)}}),
None => json!({"position": 0, "color": rgba(1.0, 0.0, 0.0)}),
};
json!([{"type": "GRADIENT_LINEAR", "gradientHandlePositions": [{"x": 0, "y": 0.5}, {"x": 1, "y": 0.5}, {"x": 0, "y": 1}],
"gradientStops": [first, {"position": 1, "color": rgba(0.0, 0.0, 1.0)}]}])
};
let shadow = json!([{"type": "DROP_SHADOW", "color": rgba(0.0, 0.0, 0.0), "offset": {"x": 0, "y": 2}, "radius": 4, "visible": true,
"blendMode": "NORMAL", "boundVariables": {"color": alias(BRAND)}}]);
let page = |children: Value| {
json!({"name": "Lists", "document": {"id": "0:0", "type": "DOCUMENT", "children": [
{"id": "0:1", "name": "Page", "type": "CANVAS", "children": children}]}})
};
let rect = |id: &str, name: &str, extra: Value| {
let mut r = json!({"id": id, "name": name, "type": "RECTANGLE", "relativeTransform": at(0.0, 0.0), "size": {"x": 40, "y": 20}});
if let (Some(r), Some(e)) = (r.as_object_mut(), extra.as_object()) {
r.extend(e.clone());
}
r
};
let kept = page(json!([
rect("1:1", "Gradient", json!({"fills": gradient(Some(BRAND)), "boundVariables": {"fills": [alias(BRAND)]}})),
rect("1:2", "Shadow", json!({"effects": shadow, "boundVariables": {"effects": [alias(BRAND)]}})),
{"id": "1:3", "name": "Label", "type": "TEXT", "relativeTransform": at(0.0, 0.0), "size": {"x": 40, "y": 20}, "characters": "Hi",
"style": {"fontFamily": "Inter", "fontSize": 8},
"fills": [{"type": "SOLID", "color": rgba(1.0, 0.0, 0.0), "boundVariables": {"color": alias(BRAND)}}],
"boundVariables": {"textRangeFills": [alias(BRAND)]}}
]));
let (doc, warnings) = import_with(&kept, Some(&variables_json()), &no_images).unwrap();
for k in ["`fills`", "`effects`", "`textRangeFills`"] {
assert!(!has(&warnings, k), "{k}: {warnings:?}");
}
assert_eq!(named(&doc, "Gradient").bound.get("fills/0/stops/0/color").map(String::as_str), Some(BRAND));
assert_eq!(named(&doc, "Shadow").bound.get("effects/0/color").map(String::as_str), Some(BRAND));
assert_eq!(named(&doc, "Label").bound.get("fill").map(String::as_str), Some(BRAND));
// A list naming a variable no stop binds is still reported.
let lost = page(json!([rect("1:1", "Gradient", json!({"fills": gradient(None), "boundVariables": {"fills": [alias(ACCENT)]}}))]));
let (_, warnings) = import_with(&lost, Some(&variables_json()), &no_images).unwrap();
assert!(has(&warnings, "`fills`"), "{warnings:?}");
}
#[test]
fn embedded_variables_match_separate_ones() {
let mut embedded = file_json();
+23
View File
@@ -377,6 +377,7 @@ impl Ctx<'_> {
}
}
}
skipped.retain(|k| !bound_by_items(k, j, &found));
for k in skipped {
self.warn(format!("variables bound to `{}` are not supported and were skipped", clip_str(k)));
}
@@ -460,6 +461,28 @@ fn node_binding<'v>(k: &str, v: &'v Value, n: &Node, out: &mut Vec<(String, &'v
true
}
/// A node-level `fills`, `strokes`, `effects` or `textRangeFills` list only repeats what each
/// paint, gradient stop and effect binds itself (#2441): nothing is lost when every variable it
/// names was read for one of them.
fn bound_by_items(k: &str, j: &Value, found: &[(String, &str)]) -> bool {
let (one, each) = match k {
"fills" | "textRangeFills" => ("fill", "fills/"),
"strokes" => ("stroke", "strokes/"),
"effects" => ("", "effects/"),
_ => return false,
};
let Some(list) = j.get("boundVariables").and_then(|b| b.get(k)) else { return false };
aliases(list).iter().all(|a| found.iter().any(|(f, x)| x == a && (f == one || f.starts_with(each))))
}
/// Every variable an alias, or a list of them (nested), names.
fn aliases(v: &Value) -> Vec<&str> {
match v.as_array() {
Some(a) => a.iter().flat_map(aliases).collect(),
None => alias(v).into_iter().collect(),
}
}
/// The one variable every entry of a per-range list (or a single alias) names.
fn same_alias(v: &Value) -> Option<&str> {
match v.as_array() {
+2 -1
View File
@@ -1,6 +1,6 @@
# File format parity
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (`.fig` export writes ruler guides (#2336); `.fig` export writes vector region paints (#2302); `.fig` export writes text on a path (#2323); `.jam` import: shapes with text come in as native board shapes (#1808); `.fig` export writes image adjustments (#2297); `.fig` import: a numbered list keeps its start only where it starts counting (#2273); `.fig` export writes a page's prototype background (#2326); `.fig` export writes list spacing, hanging punctuation and lists, and vertical trim (#2305); `.fig` import and export read and write a boolean group's corner radius and smoothing (#2222); `.jam` import: stickies come in as native board stickies (#1808); `.fig` import scales per-point vector corner radii with the row that supplies their network and keeps different instance scales separate in the network cache (#2097); `.fig` export preserves scaled-instance lengths reset to their unscaled main values, including nested linked-style overrides (#2097); `.fig` import: the layers of an instance scaled with the Scale tool draw at its scale factor, not at their main's lengths (#2091); a color profile per PNG, JPG and WebP export setting (Same as file, sRGB or Display P3), the pixels converted; a `.jam` connector end with an `AUTO` or `CENTER` magnet leaves the side facing the other end, not the side its stale saved point named (#1909); a FigJam elbow connector saved with its path (`connectorControlPoints`) keeps it on import, as a board connector reshaped by hand does, instead of being routed again (#1910); JPG exports take a quality, 1 to 100 with 90 the default, and embed the file's colour profile when it is sRGB too (#2004); a FigJam connector without a saved snapshot took no stroke and was invisible; its line's paint, weight, cap and dashes now come from the file's generated line record (#1807); a Dash cap setting (none, round or square) on Dash and Custom strokes, drawn on both ends of every dash; pasted layers whose image the clipboard lacks are named and show a placeholder that reads as missing (#1646); paint-style colours on layers pasted from another design app keep their style instead of turning black (#1638); imported and pasted text finds an installed family under the other names its fonts give it, and with other case and spacing (#1292); `.fig` export writes colour calculations as the colour they show in each mode and leaves out, with a warning, one that resolves to nothing (#1280); `.fig` import budgets four decoded values per compressed byte instead of one, still within 20M–128M, so dense files within that budget open instead of being refused as having too many values (#574); `.fig` ZIP image reads share a total byte budget and count skipped images in the import warnings (#1076); every file a command reads whole by path is a regular file within a cap that fits it: documents 16 GiB, placed images 256 MiB, CLI scripts 1 GiB; folders, devices and pipes are refused before anything is read (#1114); files nested 256 levels deep import on the browser's 1 MB stack (#1101); SVG and PDF exports count pattern sources and the renders they embed from the layer's depth, so one cap bounds a whole export (#1082); opening a `.figcraft` file unpacks at most 6 GiB in all (2 GiB in the browser), every area together (#1079); `.fig` instance expansion no longer walks variable nodes for every instance or copies every outer override row into each nested instance (#1077); a FigJam `.jam` file opens as a board (#1342); FigJam `.jam` files open like `.fig` files: File ▸ Open, drag and drop, `file.import` and the command line (#1342); SVG import reads `color()` and `color-mix()` colours, with a note and a grey for those it can't (#1550); SVG import draws each pattern tile once per scale, within the layer budget (#1080); a file's JPEG thumbnail can't crash the home screen (#1491's progressive JPEG check, now shared); `.fig` import: library text styles linked by asset key, and override rows restating a nested level (#1234); `.fig` import keeps the file's saved line breaks while the text and its box are unedited (#1236); Download a missing free font from the Missing fonts window (`font.download`, #754); offline Penpot 2.x import/export (#1143); `.sketch` import checked against Sketch's renders: master backgrounds, symbol clipping, tints before Sketch 64, mask opacity, bitmap fills, image overrides on shapes, stretching stacks, blur radii, colour adjustments, OKLab gradients, text growth, shape group borders (#1389); FigJam outer shape outlines and sticky body fallback beside author text (#1341, #1397); image member names are checked on read, and REST image placeholders get archive-safe keys (#1086); Android Vector Drawable (XML) export; `.fig` export: files the incumbent imports, with component set properties, and grid track sizes at its field ids; Save and auto-save don't replace changes another app made to the open file (#1330); `.sketch` impLine truncated
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (REST import no longer reports node-level `fills`, `strokes`, `effects` or `textRangeFills` bindings as skipped when each paint, stop or effect binds those variables itself (#2441); `.fig` export writes ruler guides (#2336); `.fig` export writes vector region paints (#2302); `.fig` export writes text on a path (#2323); `.jam` import: shapes with text come in as native board shapes (#1808); `.fig` export writes image adjustments (#2297); `.fig` import: a numbered list keeps its start only where it starts counting (#2273); `.fig` export writes a page's prototype background (#2326); `.fig` export writes list spacing, hanging punctuation and lists, and vertical trim (#2305); `.fig` import and export read and write a boolean group's corner radius and smoothing (#2222); `.jam` import: stickies come in as native board stickies (#1808); `.fig` import scales per-point vector corner radii with the row that supplies their network and keeps different instance scales separate in the network cache (#2097); `.fig` export preserves scaled-instance lengths reset to their unscaled main values, including nested linked-style overrides (#2097); `.fig` import: the layers of an instance scaled with the Scale tool draw at its scale factor, not at their main's lengths (#2091); a color profile per PNG, JPG and WebP export setting (Same as file, sRGB or Display P3), the pixels converted; a `.jam` connector end with an `AUTO` or `CENTER` magnet leaves the side facing the other end, not the side its stale saved point named (#1909); a FigJam elbow connector saved with its path (`connectorControlPoints`) keeps it on import, as a board connector reshaped by hand does, instead of being routed again (#1910); JPG exports take a quality, 1 to 100 with 90 the default, and embed the file's colour profile when it is sRGB too (#2004); a FigJam connector without a saved snapshot took no stroke and was invisible; its line's paint, weight, cap and dashes now come from the file's generated line record (#1807); a Dash cap setting (none, round or square) on Dash and Custom strokes, drawn on both ends of every dash; pasted layers whose image the clipboard lacks are named and show a placeholder that reads as missing (#1646); paint-style colours on layers pasted from another design app keep their style instead of turning black (#1638); imported and pasted text finds an installed family under the other names its fonts give it, and with other case and spacing (#1292); `.fig` export writes colour calculations as the colour they show in each mode and leaves out, with a warning, one that resolves to nothing (#1280); `.fig` import budgets four decoded values per compressed byte instead of one, still within 20M–128M, so dense files within that budget open instead of being refused as having too many values (#574); `.fig` ZIP image reads share a total byte budget and count skipped images in the import warnings (#1076); every file a command reads whole by path is a regular file within a cap that fits it: documents 16 GiB, placed images 256 MiB, CLI scripts 1 GiB; folders, devices and pipes are refused before anything is read (#1114); files nested 256 levels deep import on the browser's 1 MB stack (#1101); SVG and PDF exports count pattern sources and the renders they embed from the layer's depth, so one cap bounds a whole export (#1082); opening a `.figcraft` file unpacks at most 6 GiB in all (2 GiB in the browser), every area together (#1079); `.fig` instance expansion no longer walks variable nodes for every instance or copies every outer override row into each nested instance (#1077); a FigJam `.jam` file opens as a board (#1342); FigJam `.jam` files open like `.fig` files: File ▸ Open, drag and drop, `file.import` and the command line (#1342); SVG import reads `color()` and `color-mix()` colours, with a note and a grey for those it can't (#1550); SVG import draws each pattern tile once per scale, within the layer budget (#1080); a file's JPEG thumbnail can't crash the home screen (#1491's progressive JPEG check, now shared); `.fig` import: library text styles linked by asset key, and override rows restating a nested level (#1234); `.fig` import keeps the file's saved line breaks while the text and its box are unedited (#1236); Download a missing free font from the Missing fonts window (`font.download`, #754); offline Penpot 2.x import/export (#1143); `.sketch` import checked against Sketch's renders: master backgrounds, symbol clipping, tints before Sketch 64, mask opacity, bitmap fills, image overrides on shapes, stretching stacks, blur radii, colour adjustments, OKLab gradients, text growth, shape group borders (#1389); FigJam outer shape outlines and sticky body fallback beside author text (#1341, #1397); image member names are checked on read, and REST image placeholders get archive-safe keys (#1086); Android Vector Drawable (XML) export; `.fig` export: files the incumLine truncated
Every format Figma reads or writes, with FigCraft's support. Sources: `Info.plist` of
`/Applications/Figma.app` (document types only; nothing inside the bundle's code was read), Figma's
@@ -195,6 +195,7 @@ scales and empty-style clears; they have not been checked in other software.
| Date | Change | Summary |
|---|---|---|
| 2026-11-19 | patch | M6, #2441: REST import warned "variables bound to `fills` (`effects`, `textRangeFills`) are not supported and were skipped" for layers that lost nothing: those node-level lists repeat the variables each gradient stop, effect and paint binds itself, which are read. The warning now names such a list only when it holds a variable none of them bound, so the warnings left mean a real loss. Test: `rest::proto_variable_tests::node_level_lists_the_paints_and_effects_bind_are_not_reported`. Numbers unchanged. |
| 2026-11-19 | minor | M6, #2336: `.fig` export writes ruler guides: a page's and a frame's `guides` (each an `Axis` Y for a horizontal guide and X for a vertical one, the offset as the ruler reads it, a frame's in its own coordinates, and a guid of its own: local id 1 and a session id counted up from 3), as measured on a page and an unrotated frame in a synthetic file saved from Figma's web app. The "ruler guides were left out" warnings are gone. An instance writes a `guides` override only where its guides differ from its main's, and a guide whose offset isn't finite is left out. Our own import does not read guides yet, so this is checked by reading the written records only, not in other software. Numbers unchanged. |
| 2026-11-17 | minor | M6: Android Vector Drawable XML serialization uses the shared writer; application projection and colour policy remain local. Byte-parity tests cover full documents and generated deep wrappers; no new format capability or incumbent certification. |
| 2026-11-13 | patch | Rows that recent merges had duplicated or garbled are merged back into one row each (no behaviour change): Pasted content from other apps, PNG. |