From a55963841973ae4fc31122c49349fe6aacc7cdee Mon Sep 17 00:00:00 2001 From: YarilaFox <102650794+YarilaFox@users.noreply.github.com> Date: Tue, 20 Oct 2026 17:57:10 +0500 Subject: [PATCH 01/50] M7: avoid Windows GNU UIA crash --- .cargo/config.toml | 7 +++++++ apps/figcraft/build.rs | 1 + apps/figcraft/src/main.rs | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/.cargo/config.toml b/.cargo/config.toml index acebfe9f..8abc94d7 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,5 +3,12 @@ [env] CRAFT_FONTS_DIR = { value = "../craft-fonts", relative = true } +# The Windows UI Automation adapter can be asked about a node that disappeared in the +# same frame. On MinGW, converting that HRESULT through windows-result's thread COM +# error-info path has crashed in GetErrorInfo. Keep the HRESULT without that extra +# COM lookup; this leaves the AccessKit tree and screen-reader support enabled. +[target.x86_64-pc-windows-gnu] +rustflags = ["--cfg=windows_slim_errors"] + [alias] xtask = "run -q -p xtask --" diff --git a/apps/figcraft/build.rs b/apps/figcraft/build.rs index 64f97835..6ed8a047 100644 --- a/apps/figcraft/build.rs +++ b/apps/figcraft/build.rs @@ -1,6 +1,7 @@ //! Windows: embed the icon and version info in figcraft.exe and size its main thread's stack //! (no-op elsewhere). fn main() { + println!("cargo::rustc-check-cfg=cfg(windows_slim_errors)"); println!("cargo::rerun-if-changed=../../assets/app-icon/figcraft.ico"); let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); if target_os == "windows" { diff --git a/apps/figcraft/src/main.rs b/apps/figcraft/src/main.rs index 00856c5d..887db45a 100644 --- a/apps/figcraft/src/main.rs +++ b/apps/figcraft/src/main.rs @@ -15,6 +15,11 @@ #![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)] #![cfg_attr(all(target_os = "windows", not(debug_assertions)), windows_subsystem = "windows")] +// A missing Windows GNU flag re-enables the COM error-info lookup that crashes while AccessKit +// reports a removed UI Automation node. Catch build configurations that drop the workaround. +#[cfg(all(target_os = "windows", target_env = "gnu", not(windows_slim_errors)))] +compile_error!("Windows GNU builds must set windows_slim_errors to keep UI Automation responsive"); + #[cfg(target_os = "macos")] mod apple_events; mod args; From f3e5d2abc4c5db3289dce999bc1c1ed47303975d Mon Sep 17 00:00:00 2001 From: Hamza Date: Wed, 21 Oct 2026 00:06:57 +0500 Subject: [PATCH 02/50] .fig import: a note says how much of the file it covers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A .fig import's notes were deduplicated and left uncounted, so each kind was named once with no sign of how much of the file it applied to: a file whose every text layer lost a setting read exactly like one where a single layer did. That is what made the loss in #467 invisible -- the reporter saw one line while three kinds of data went, one of them on all 83 text layers. The mapper now collects its notes through the same `Warnings` the REST importer already uses, which keeps the first-seen order and the cap and appends `(×n)` where a note was met more than once. Nothing else changes: the note text stays the catalog key it was, and the import report already reads a `(×n)` suffix off before translating the base (`ui-egui`'s `note_text`), so a counted note is still translated. `figcraft-cli info` prints these notes, so it now names each kind with its count. With the count dropped again, the test reports the two notes plain: ["connector layers import as static frame/vector snapshots ...", "connector label was skipped: depth limit prevents nested ..."] Part of #467. --- crates/format/src/fig/map.rs | 18 +++++---- .../map_connector_snapshot_budget_tests.rs | 40 +++++++++++++++++-- crates/format/src/rest/mod.rs | 19 +++++++-- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/crates/format/src/fig/map.rs b/crates/format/src/fig/map.rs index 8e467151..f36cbb83 100644 --- a/crates/format/src/fig/map.rs +++ b/crates/format/src/fig/map.rs @@ -58,7 +58,7 @@ pub(super) fn to_rest(msg: &Kv, name: &str, max_nodes: usize) -> (Value, Vec { library_contexts: Vec, /// Layers visited while scanning internal canvases, across all of them. library_scan_count: usize, - warnings: Vec, + warnings: crate::rest::Warnings, count: usize, /// Most layers produced or scanned, instance expansion included; the one place the cap comes /// from (see [`super::layer_budget`]). @@ -464,7 +464,7 @@ impl<'a> Mapper<'a> { override_scope_entries: 0, library_contexts: Vec::new(), library_scan_count: 0, - warnings: Vec::new(), + warnings: crate::rest::Warnings::default(), count: 0, max_nodes, networks: Vec::new(), @@ -493,12 +493,14 @@ impl<'a> Mapper<'a> { .cloned() } + /// A note about what this file's mapping left out or changed. Counted, as the REST importer + /// counts its own: these notes are met once per layer, so the kinds were named once each with + /// no sign of how much of the file they covered -- a file whose every text layer lost a + /// setting read the same as one where a single layer did (#467). The collector keeps the + /// first-seen order and the same cap, since some notes name fields of the file (image + /// filters). fn warn(&mut self, w: impl Into) { - let w = w.into(); - // Capped like the REST importer's list: some warnings name fields of the file (image filters). - if self.warnings.len() < crate::rest::MAX_WARNINGS && !self.warnings.contains(&w) { - self.warnings.push(w); - } + self.warnings.add(w.into()); } fn children(&self, id: &str) -> Vec { diff --git a/crates/format/src/fig/map_connector_snapshot_budget_tests.rs b/crates/format/src/fig/map_connector_snapshot_budget_tests.rs index ca47578d..8727c31b 100644 --- a/crates/format/src/fig/map_connector_snapshot_budget_tests.rs +++ b/crates/format/src/fig/map_connector_snapshot_budget_tests.rs @@ -115,14 +115,14 @@ fn connector_snapshot_respects_last_and_zero_child_slots() { assert!(!children[0]["fillGeometry"].as_array().unwrap().is_empty(), "saved outline survives the budget limit"); assert_eq!(children[0]["fillGeometry"][0]["path"], "M 0 0 L 20 10"); assert_eq!(mapper.count, MAX_NODES); - assert!(mapper.warnings.iter().any(|warning| warning == &format!("the file has more than {MAX_NODES} layers; connector label was skipped"))); + assert!(mapper.warnings.seen().any(|warning| warning == format!("the file has more than {MAX_NODES} layers; connector label was skipped"))); let mut mapper = Mapper::new(&message, MAX_NODES); mapper.count = MAX_NODES; let children = mapper.connector_snapshot_children(&view, "1:123"); assert!(children.is_empty()); assert_eq!(mapper.count, MAX_NODES, "the node budget is never exceeded"); - assert!(mapper.warnings.iter().any(|warning| warning.contains("connector snapshot children were skipped"))); + assert!(mapper.warnings.seen().any(|warning| warning.contains("connector snapshot children were skipped"))); } #[test] @@ -133,7 +133,7 @@ fn connector_snapshot_flattens_vector_at_depth_and_node_limits() { assert_eq!(depth_limited["type"], "VECTOR"); assert!(!depth_limited["fillGeometry"].as_array().unwrap().is_empty()); assert!(depth_limited.get("children").is_none()); - assert!(mapper.warnings.iter().any(|warning| warning == "connector label was skipped: depth limit prevents nested snapshot children")); + assert!(mapper.warnings.seen().any(|warning| warning == "connector label was skipped: depth limit prevents nested snapshot children")); let mut mapper = Mapper::new(&message, MAX_NODES); mapper.count = MAX_NODES - 1; @@ -142,5 +142,37 @@ fn connector_snapshot_flattens_vector_at_depth_and_node_limits() { assert!(!budget_limited["fillGeometry"].as_array().unwrap().is_empty()); assert!(budget_limited.get("children").is_none()); assert_eq!(mapper.count, MAX_NODES); - assert!(mapper.warnings.iter().any(|warning| warning == "connector label was skipped: node budget prevents nested snapshot children")); + assert!(mapper.warnings.seen().any(|warning| warning == "connector label was skipped: node budget prevents nested snapshot children")); +} + +/// A mapper note is met once per layer, so the kinds were named once each with no sign of how much +/// of the file they covered: a file whose every layer lost a setting read the same as one where a +/// single layer did (#467). They are counted now, with the `(×n)` the REST importer already uses +/// and the import report already reads back off before translating a note. +#[test] +fn a_note_met_more_than_once_carries_its_count() { + let message = message(); + + let mut mapper = Mapper::new(&message, MAX_NODES); + for _ in 0..2 { + mapper.layer("1:123", None, Affine::IDENTITY, None, None, MAX_DEPTH).expect("terminal connector"); + } + let notes = std::mem::take(&mut mapper.warnings).finish(); + let counted: Vec<&String> = notes.iter().filter(|n| n.contains("(×")).collect(); + assert!( + counted.iter().any(|n| n.ends_with("(×2)") && n.contains("connector label was skipped: depth limit")), + "the note met twice says so: {notes:?}" + ); + assert!(notes.iter().all(|n| !n.ends_with("(×1)")), "a count of one is left off: {notes:?}"); + + // One layer, and the same notes have no count at all. + let mut mapper = Mapper::new(&message, MAX_NODES); + mapper.layer("1:123", None, Affine::IDENTITY, None, None, MAX_DEPTH).expect("terminal connector"); + let once = std::mem::take(&mut mapper.warnings).finish(); + assert!(once.iter().all(|n| !n.contains("(×")), "{once:?}"); + assert_eq!( + once.len(), + counted.len() + notes.iter().filter(|n| !n.contains("(×")).count(), + "the same kinds, counted or not: {once:?} vs {notes:?}" + ); } diff --git a/crates/format/src/rest/mod.rs b/crates/format/src/rest/mod.rs index 78279e91..b86b0b91 100644 --- a/crates/format/src/rest/mod.rs +++ b/crates/format/src/rest/mod.rs @@ -329,15 +329,16 @@ fn children(v: &Value) -> &[Value] { v.get("children").and_then(Value::as_array).map(Vec::as_slice).unwrap_or_default() } -/// Distinct warnings in first-seen order, with repeat counts. +/// Distinct warnings in first-seen order, with repeat counts. Shared with the `.fig` mapper +/// (`crate::fig::map`), whose notes repeat per layer in the same way. #[derive(Default)] -struct Warnings { +pub(crate) struct Warnings { list: Vec<(String, usize)>, index: BTreeMap, } impl Warnings { - fn add(&mut self, msg: String) { + pub(crate) fn add(&mut self, msg: String) { if let Some(i) = self.index.get(&msg) { if let Some(e) = self.list.get_mut(*i) { e.1 += 1; @@ -348,7 +349,17 @@ impl Warnings { } } - fn finish(self) -> Vec { + /// The notes met so far, without their counts, for the tests that ask whether one was met + /// (the product reads them through [`Self::finish`], with the counts). + #[cfg(test)] + pub(crate) fn seen(&self) -> impl Iterator { + self.list.iter().map(|(msg, _)| msg.as_str()) + } + + /// The notes, each with `(×n)` after it where it was met more than once. The import report + /// reads that suffix off before it looks the note up in the catalogue, so a counted note is + /// still translated (`ui-egui`'s `note_text`). + pub(crate) fn finish(self) -> Vec { self.list.into_iter().map(|(m, n)| if n > 1 { format!("{m} (×{n})") } else { m }).collect() } } From e211bf5476c44512bf3238e3698c085267f5da9b Mon Sep 17 00:00:00 2001 From: Ridzzz0Alam Date: Wed, 21 Oct 2026 18:22:16 +0200 Subject: [PATCH 03/50] M1: large .fig files keep their layers and their library links (#981) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A design-system .fig file (54 pages) stopped at 244 248 layers, the rest of its pages skipped, and most of its instances came in as frames "of components that aren't in the file", with the cap note shown twice. - The layer budget follows the compressed canvas at 8 bytes a layer, not 32: design systems are mostly instances, which pack tightly. Files under about 1.6 MB keep the 200 000 floor and the 2 million ceiling stays (measured on synthetic files: about 5.4 KB and 19 µs a layer). - The library copies the pages use (the file's hidden internal canvas) are mapped before the pages: at the cap the pages' last layers are skipped, not the mains their instances link to. The REST stage keeps building pages first (its ids are first-wins) and allows for the wrapper frame of each library copy, the one layer the mapper doesn't count; that layer tripped the REST stage's own cap and repeated the note. - Instances and swap defaults whose main is in the file but past the cap say so instead of "aren't in the file" (en and es catalogs). - The .fig import gives a note the mapper already gave only once. Tests in fig/layer_cap_tests.rs: the budget for a #981-sized canvas, library mains ahead of the pages at the cap, the note for a capped local main, and a whole 210 000-layer file with one cap note and its library links kept. All four fail on the previous code. --- crates/format/src/fig/layer_cap_tests.rs | 117 +++++++++++++++++++++++ crates/format/src/fig/map.rs | 32 ++++++- crates/format/src/fig/mod.rs | 17 +++- crates/format/src/rest/mod.rs | 33 +++++-- crates/ui-egui/locales/en.toml | 2 + crates/ui-egui/locales/es.toml | 2 + 6 files changed, 188 insertions(+), 15 deletions(-) create mode 100644 crates/format/src/fig/layer_cap_tests.rs diff --git a/crates/format/src/fig/layer_cap_tests.rs b/crates/format/src/fig/layer_cap_tests.rs new file mode 100644 index 00000000..6eeb15f4 --- /dev/null +++ b/crates/format/src/fig/layer_cap_tests.rs @@ -0,0 +1,117 @@ +//! Large `.fig` files at the layer cap (#981): the budget a design-system file gets, the library +//! copies its instances need kept ahead of the pages, honest notes for what the cap kept out, and +//! one note for the cap itself. + +use figcraft_doc::{Document, NodeKind}; + +use super::kiwi::{Kv, Schema}; +use super::*; + +type Fields = Vec<(&'static str, Kv<'static>)>; + +fn o(fields: Fields) -> Kv<'static> { + Kv::Object(fields) +} + +fn g(id: u64) -> Kv<'static> { + o(vec![("sessionID", Kv::Uint(1)), ("localID", Kv::Uint(id))]) +} + +fn xy(x: f64, y: f64) -> Kv<'static> { + o(vec![("x", Kv::Float(x as f32)), ("y", Kv::Float(y as f32))]) +} + +/// A layer under `parent`; siblings come in id order. +fn node(id: u64, parent: Option, ty: &'static str, name: &str, more: Fields) -> Kv<'static> { + let mut fields = vec![("guid", g(id)), ("phase", Kv::Enum("CREATED")), ("type", Kv::Enum(ty)), ("name", Kv::Str(name.into()))]; + if let Some(parent) = parent { + fields.push(("parentIndex", o(vec![("guid", g(parent)), ("position", Kv::Str(format!("{id:08}")))]))); + } + fields.extend(more); + o(fields) +} + +fn instance(id: u64, page: u64, main: u64) -> Kv<'static> { + node(id, Some(page), "INSTANCE", "Instance", vec![("symbolData", o(vec![("symbolID", g(main))]))]) +} + +/// A main `id` of `layers` rectangles under `parent`. +fn main(id: u64, parent: u64, name: &str, layers: u64) -> Vec> { + let mut out = vec![node(id, Some(parent), "SYMBOL", name, vec![("size", xy(10.0, 10.0))])]; + out.extend((1..=layers).map(|i| node(id * 10_000 + i, Some(id), "RECTANGLE", "R", vec![("size", xy(1.0, 1.0))]))); + out +} + +/// A page (2) of `count` instances of a main kept on the file's hidden library canvas (3), as a +/// design system's file carries the library components it uses. +fn library_message(count: u64, main_layers: u64) -> Kv<'static> { + let mut nodes = vec![ + node(1, None, "DOCUMENT", "Document", vec![]), + node(2, Some(1), "CANVAS", "Screens", vec![]), + node(3, Some(1), "CANVAS", "Internal", vec![("internalOnly", Kv::Bool(true))]), + ]; + nodes.extend(main(20, 3, "Library main", main_layers)); + nodes.extend((0..count).map(|i| instance(1_000 + i, 2, 20))); + o(vec![("nodeChanges", Kv::Array(nodes))]) +} + +/// The `.fig` import's two stages at layer cap `cap`. +fn import_at(msg: &Kv, cap: usize) -> (Document, Vec) { + let (json, mut warnings, networks) = map::to_rest(msg, "Capped", cap); + let (doc, more) = crate::rest::import_with_networks(&json, &|_: &str| None, networks, cap).unwrap(); + warnings.extend(more); + (doc, warnings) +} + +fn linked_to(doc: &Document, main_name: &str) -> usize { + doc.nodes().filter(|n| matches!(n.kind, NodeKind::Instance { component, .. } if doc.node(component).is_some_and(|c| c.name == main_name))).count() +} + +#[test] +fn a_design_system_sized_canvas_gets_room() { + // The file in #981 stopped at 244 248 layers: a 7.8 MB canvas at 32 bytes a layer. + let reported = 244_248 * 32; + assert!(layer_budget(reported) >= 4 * 244_248, "{}", layer_budget(reported)); + // Small files still can't claim more than the REST import's cap, nor any file the ceiling. + assert_eq!(layer_budget(1 << 20), crate::rest::MAX_NODES); + assert_eq!(layer_budget(usize::MAX), MAX_FIG_NODES); +} + +#[test] +fn library_mains_come_before_the_pages_at_the_cap() { + // 40 instances of an 11-layer library main on a page, with room for 100 layers: mapped after + // the pages, the main found no room and every instance became a frame of "a component that + // isn't in the file". + let (doc, warnings) = import_at(&library_message(40, 10), 100); + assert!(warnings.iter().any(|w| w.contains("more than 100 layers")), "{warnings:?}"); + assert!(!warnings.iter().any(|w| w.contains("aren't in the file")), "{warnings:?}"); + let linked = linked_to(&doc, "Library main"); + assert!(linked >= 5, "{linked} instances linked to the library main: {warnings:?}"); + assert!(doc.nodes().any(|n| n.name == "Library main" && doc.is_remote(n.id))); +} + +#[test] +fn instances_of_a_main_the_cap_kept_out_say_so() { + // The page's instances come before their main: at the cap, the main is skipped though the + // file has it. + let mut nodes = vec![node(1, None, "DOCUMENT", "Document", vec![]), node(2, Some(1), "CANVAS", "Page", vec![])]; + nodes.extend((0..20).map(|i| instance(100 + i, 2, 900))); + nodes.extend(main(900, 2, "Local main", 10)); + let (doc, warnings) = import_at(&o(vec![("nodeChanges", Kv::Array(nodes))]), 60); + assert!(warnings.iter().any(|w| w.starts_with("instances whose component was past the layer limit were imported as frames")), "{warnings:?}"); + assert!(!warnings.iter().any(|w| w.contains("aren't in the file")), "{warnings:?}"); + assert!(!doc.nodes().any(|n| n.name == "Local main")); +} + +#[test] +fn a_whole_file_past_the_cap_keeps_its_library_links_and_says_so_once() { + // A 1 001-layer library main used 210 times: about 210 000 layers in a file far too small to + // lift the cap above the REST import's 200 000. + let file = super::tests::canvas(&Schema::parse(export::SCHEMA).unwrap(), &library_message(210, 1_000)); + assert_eq!(layer_budget(file.len()), crate::rest::MAX_NODES); + let (doc, warnings) = import(&file, "Design system.fig").unwrap(); + let cap: Vec<_> = warnings.iter().filter(|w| w.contains("layers; the rest were skipped")).collect(); + assert_eq!(cap.len(), 1, "{warnings:?}"); + assert!(!warnings.iter().any(|w| w.contains("aren't in the file")), "{warnings:?}"); + assert!(linked_to(&doc, "Library main") >= 190, "{warnings:?}"); +} diff --git a/crates/format/src/fig/map.rs b/crates/format/src/fig/map.rs index 8e467151..7eb974da 100644 --- a/crates/format/src/fig/map.rs +++ b/crates/format/src/fig/map.rs @@ -42,6 +42,14 @@ pub(super) fn to_rest(msg: &Kv, name: &str, max_nodes: usize) -> (Value, Vec= m.max_nodes { + let capped: Vec = m.instance_mains.difference(&m.mapped_mains).map(|id| json!(id)).collect(); + if !capped.is_empty() { + out[crate::rest::FIG_CAPPED_MAINS_FIELD] = Value::Array(capped); + } + } if !m.styles.is_empty() { out["styles"] = Value::Object(std::mem::take(&mut m.styles)); } @@ -389,6 +397,10 @@ struct Mapper<'a> { library_scan_count: usize, warnings: Vec, count: usize, + /// The mains in the file that instances name, and the mains mapped as layers: the difference + /// is what the layer cap kept out. + instance_mains: BTreeSet, + mapped_mains: BTreeSet, /// Most layers produced or scanned, instance expansion included; the one place the cap comes /// from (see [`super::layer_budget`]). max_nodes: usize, @@ -466,6 +478,8 @@ impl<'a> Mapper<'a> { library_scan_count: 0, warnings: Vec::new(), count: 0, + instance_mains: BTreeSet::new(), + mapped_mains: BTreeSet::new(), max_nodes, networks: Vec::new(), network_ids: HashMap::new(), @@ -556,9 +570,8 @@ impl<'a> Mapper<'a> { Some(d) => self.children(d), None => self.nodes.iter().filter(|(_, n)| n.get("type").and_then(Kv::str) == Some("CANVAS")).map(|(id, _)| id.clone()).collect(), }; - let mut out = Vec::new(); let mut internal = Vec::new(); - let mut visible_pages = Vec::new(); + let mut visible = Vec::new(); for p in pages { let Some(&n) = self.nodes.get(&p) else { continue }; if n.get("type").and_then(Kv::str) != Some("CANVAS") { @@ -568,17 +581,20 @@ impl<'a> Mapper<'a> { // The hidden page that holds styles, variables and library copies. if n.get("internalOnly").and_then(Kv::bool) == Some(true) { internal.push((p, n)); - continue; + } else { + visible.push((p, n)); } - visible_pages.push(p.clone()); - out.push(self.page(&p, n)); } + // The library copies the pages use come first: in a file past the layer cap, the pages' + // last layers are skipped rather than the mains every instance of them needs (#981). + let visible_pages: Vec = visible.iter().map(|(p, _)| p.clone()).collect(); let required_mains = self.referenced_component_mains(&visible_pages); for (id, canvas) in internal { if let Some(context) = self.library_context(&id, canvas, &required_mains) { self.library_contexts.push(context); } } + let out: Vec = visible.into_iter().map(|(p, n)| self.page(&p, n)).collect(); if out.is_empty() { self.warn("the file has no pages"); } @@ -879,6 +895,9 @@ impl<'a> Mapper<'a> { self.warn("connector layers import as static frame/vector snapshots with labels when present; live endpoint bindings are not retained"); } self.count += 1; + if own == "SYMBOL" && inst.is_none() { + self.mapped_mains.insert(id.to_string()); + } let mut o = Obj::new(); o.insert("id".into(), json!(rest_id)); // Private provenance for the .fig importer; ordinary REST import ignores it. @@ -1994,6 +2013,9 @@ impl<'a> Mapper<'a> { self.warn("instances of components that aren't in the file show no layers"); return None; } + if !self.instance_mains.contains(&sym) { + self.instance_mains.insert(sym.clone()); + } if outer.is_some_and(|i| i.symbols.contains(&sym)) { return None; } diff --git a/crates/format/src/fig/mod.rs b/crates/format/src/fig/mod.rs index 4c103d08..c04043ae 100644 --- a/crates/format/src/fig/mod.rs +++ b/crates/format/src/fig/mod.rs @@ -23,6 +23,8 @@ mod export_tests; #[cfg(test)] mod interop_tests; pub mod kiwi; +#[cfg(test)] +mod layer_cap_tests; mod map; mod network; #[cfg(test)] @@ -64,8 +66,11 @@ const MAX_CHUNKS: usize = 16; /// compressed canvas, at least the REST import's cap and at most [`MAX_FIG_NODES`]. Instances /// expand into a layer per layer of their component, and chunks inflate up to [`MAX_CHUNK`], so the /// budget follows what the file takes, not what it unpacks to: a small file can't claim a large -/// count, however it's built; a large one gets room. -const PACKED_BYTES_PER_LAYER: usize = 32; +/// count, however it's built; a large one gets room. Design systems are mostly instances, which +/// pack tightly: a 7.8 MB canvas stopped at 244 248 layers at 32 bytes a layer (#981). At 8, files +/// under about 1.6 MB keep the floor and the ceiling comes at a 16 MB canvas (about 11 GB and 40 s +/// to import 2 million synthetic layers; memory grows with the count, about 5.4 KB a layer). +const PACKED_BYTES_PER_LAYER: usize = 8; const MAX_FIG_NODES: usize = 2_000_000; /// Most layers imported from a `.fig` file whose compressed canvas is `packed` bytes. @@ -108,7 +113,13 @@ pub fn import(bytes: &[u8], name: &str) -> Result<(Document, Vec), Forma drop(msg); let images = |r: &str| archive.image(r).or_else(|| embedded.get(r).cloned()); let (doc, more) = crate::rest::import_with_networks(&json, &images, networks, max_nodes)?; - warnings.extend(more.into_iter().filter_map(map::adapt_warning)); + // Both stages stop at the same cap and say so in the same words: one note (#981). + for w in more.into_iter().filter_map(map::adapt_warning) { + let base = w.rsplit_once(" (×").map_or(w.as_str(), |(b, _)| b); + if !warnings.iter().any(|seen| seen == base) { + warnings.push(w); + } + } Ok((doc, warnings)) } diff --git a/crates/format/src/rest/mod.rs b/crates/format/src/rest/mod.rs index 78279e91..40c091c6 100644 --- a/crates/format/src/rest/mod.rs +++ b/crates/format/src/rest/mod.rs @@ -65,6 +65,8 @@ const MAX_DEPTH: usize = 256; pub(crate) const FIG_SOURCE_FIELD: &str = "_figSource"; /// Hidden .fig library context; accepted only by the `.fig` import ([`import_with_networks`]). pub(crate) const FIG_LIBRARY_CONTEXTS_FIELD: &str = "_figLibraryContexts"; +/// Ids of mains in a `.fig` file that its layer cap kept out; read only by the `.fig` import. +pub(crate) const FIG_CAPPED_MAINS_FIELD: &str = "_figCappedMains"; /// Longest SVG path string read from one geometry entry. const MAX_PATH_BYTES: usize = 4 << 20; /// Most path elements in one vector. @@ -215,6 +217,14 @@ fn import_parts( cx.style_definitions(v); cx.networks = networks; cx.max_nodes = max_nodes; + // The `.fig` mapper already kept the layers, library copies included, within the cap; each + // library copy's wrapper frame is the one layer here it doesn't count (#981). + let contexts = if fig_sources { v.get(FIG_LIBRARY_CONTEXTS_FIELD).and_then(Value::as_array).map(Vec::as_slice).unwrap_or_default() } else { &[] }; + if fig_sources { + cx.capped_mains = + v.get(FIG_CAPPED_MAINS_FIELD).and_then(Value::as_array).into_iter().flatten().filter_map(Value::as_str).map(str::to_owned).collect(); + cx.max_nodes = max_nodes.saturating_add(contexts.len()); + } for e in entries { let Some(root) = e.get("document") else { continue }; match text(root, "type") { @@ -236,11 +246,9 @@ fn import_parts( None => cx.warn("entries without a node type were skipped"), } } - if fig_sources { - for context in v.get(FIG_LIBRARY_CONTEXTS_FIELD).and_then(Value::as_array).into_iter().flatten() { - let store = cx.doc.ensure_library_store(); - cx.build(context, store, Space::default(), None, 0, false); - } + for context in contexts { + let store = cx.doc.ensure_library_store(); + cx.build(context, store, Space::default(), None, 0, false); } // Drop the empty page the new document started with once real pages exist. if let Some(p) = blank @@ -404,6 +412,8 @@ pub(crate) struct Ctx<'a> { networks: Vec>, /// Most layers imported: [`MAX_NODES`], or the `.fig` import's own cap. max_nodes: usize, + /// Mains the `.fig` file has but its layer cap kept out ([`FIG_CAPPED_MAINS_FIELD`]). + capped_mains: BTreeSet, } impl<'a> Ctx<'a> { @@ -432,6 +442,7 @@ impl<'a> Ctx<'a> { var_modes: BTreeMap::new(), networks: Vec::new(), max_nodes: MAX_NODES, + capped_mains: BTreeSet::new(), } } @@ -998,7 +1009,11 @@ impl<'a> Ctx<'a> { fn resolve_swap_defaults(&mut self) { for (owner, name, rest_id) in std::mem::take(&mut self.swap_defaults) { let Some(c) = self.component(&rest_id) else { - self.warn("instance swap properties whose default component isn't in the file were skipped"); + if self.capped_mains.contains(&rest_id) { + self.warn("instance swap properties whose default component was past the layer limit were skipped"); + } else { + self.warn("instance swap properties whose default component isn't in the file were skipped"); + } continue; }; let def = PropDef::InstanceSwap { default: c, preferred: Vec::new() }; @@ -1017,7 +1032,11 @@ impl<'a> Ctx<'a> { let frames: BTreeSet = self.instances.iter().map(|(i, _)| *i).collect(); let mut links: Vec<(NodeId, NodeId, &'a Value)> = Vec::new(); for (inst, j) in std::mem::take(&mut self.instances) { - match text(j, "componentId").and_then(|r| self.component(r)) { + let main = text(j, "componentId"); + match main.and_then(|r| self.component(r)) { + None if main.is_some_and(|r| self.capped_mains.contains(r)) => { + self.warn("instances whose component was past the layer limit were imported as frames"); + } None => self.warn("instances of components that aren't in the file were imported as frames"), Some(c) if self.doc.is_ancestor(c, inst) => self.warn("instances inside their own main component were imported as frames"), Some(c) => links.push((inst, c, j)), diff --git a/crates/ui-egui/locales/en.toml b/crates/ui-egui/locales/en.toml index ae566fc8..32045d4e 100644 --- a/crates/ui-egui/locales/en.toml +++ b/crates/ui-egui/locales/en.toml @@ -1595,10 +1595,12 @@ name = "English" "image filters are ambiguous because both filter containers are present; filter conversion was skipped" = "image filters are ambiguous because both filter containers are present; filter conversion was skipped" "image filters use FigCraft's approximate renderer" = "image filters use FigCraft's approximate renderer" "instance swap properties whose default component isn't in the file were skipped" = "instance swap properties whose default component isn't in the file were skipped" +"instance swap properties whose default component was past the layer limit were skipped" = "instance swap properties whose default component was past the layer limit were skipped" "instances inside their own main component were imported as frames" = "instances inside their own main component were imported as frames" "instances of components that aren't in the file show no layers" = "instances of components that aren't in the file show no layers" "instances of components that aren't in the file were imported as frames" = "instances of components that aren't in the file were imported as frames" "instances that would nest a component inside itself were imported as frames" = "instances that would nest a component inside itself were imported as frames" +"instances whose component was past the layer limit were imported as frames" = "instances whose component was past the layer limit were imported as frames" "instances without a main component were imported as empty frames" = "instances without a main component were imported as empty frames" "invalid internal .fig text path data was ignored" = "invalid internal .fig text path data was ignored" "invalid or oversized vector networks import as outlines" = "invalid or oversized vector networks import as outlines" diff --git a/crates/ui-egui/locales/es.toml b/crates/ui-egui/locales/es.toml index 596feda6..c6e77866 100644 --- a/crates/ui-egui/locales/es.toml +++ b/crates/ui-egui/locales/es.toml @@ -1596,10 +1596,12 @@ status = "draft — needs native review" "image filters are ambiguous because both filter containers are present; filter conversion was skipped" = "los filtros de imagen son ambiguos porque están los dos contenedores de filtros; se omitió la conversión de filtros" "image filters use FigCraft's approximate renderer" = "los filtros de imagen usan el renderizado aproximado de FigCraft" "instance swap properties whose default component isn't in the file were skipped" = "se omitieron las propiedades de intercambio de instancia cuyo componente predeterminado no está en el archivo" +"instance swap properties whose default component was past the layer limit were skipped" = "se omitieron las propiedades de intercambio de instancia cuyo componente predeterminado quedó fuera del límite de capas" "instances inside their own main component were imported as frames" = "las instancias dentro de su propio componente principal se importaron como marcos" "instances of components that aren't in the file show no layers" = "las instancias de componentes que no están en el archivo no muestran capas" "instances of components that aren't in the file were imported as frames" = "las instancias de componentes que no están en el archivo se importaron como marcos" "instances that would nest a component inside itself were imported as frames" = "las instancias que anidarían un componente dentro de sí mismo se importaron como marcos" +"instances whose component was past the layer limit were imported as frames" = "las instancias cuyo componente quedó fuera del límite de capas se importaron como marcos" "instances without a main component were imported as empty frames" = "las instancias sin componente principal se importaron como marcos vacíos" "invalid internal .fig text path data was ignored" = "se ignoraron datos internos no válidos de texto en trazado del .fig" "invalid or oversized vector networks import as outlines" = "las redes vectoriales no válidas o demasiado grandes se importan como contornos" From 5e2957a9011d71ff8fc3469830eb28ca17a2d3ad Mon Sep 17 00:00:00 2001 From: Ridzzz0Alam Date: Wed, 21 Oct 2026 19:15:58 +0200 Subject: [PATCH 04/50] M1: Save, Save as and Export arrive as downloads in the browser (#969) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cause: in the web build no file has a path, so Save goes to Save as, and Save as and every Export go through Services::pick_save / pick_folder. WebServices keeps the trait's defaults there, which return no path, so the callback never ran: no download, no message. Only Variables ▸ Export used the platform's downloads (#368). Fix: where services.downloads() is true, those routes run their command without a path and hand the bytes to services.download(): - engine: file.saveAs takes `data: true` and returns the .figcraft file as base64 `data` with its `name`, marking it saved (no path, nothing remembered). Programmatic Save as without either still asks for a path. - ui: FigApp::download decodes a result's `data` and says when nothing arrived; Save as, one-off export (PNG/JPG/WebP/SVG/PDF), .fig export, frames to PDF and multi-layer export (one download per file) use it. Tests: engine save_as_data_hands_back_the_file_and_marks_it_saved; ui-egui web_save_tests (save, export, refused download) with the fake browser Services from variables_export_ui_tests. The UI tests fail without the fix. --- crates/engine/src/cmd/file.rs | 58 +++++++++++++++---- crates/ui-egui/locales/en.toml | 1 + crates/ui-egui/locales/es.toml | 1 + crates/ui-egui/src/dialogs.rs | 15 ++++- crates/ui-egui/src/export_panel.rs | 17 ++++++ crates/ui-egui/src/lib.rs | 22 +++++++ crates/ui-egui/src/menus.rs | 9 +++ .../ui-egui/src/variables_export_ui_tests.rs | 8 +-- crates/ui-egui/src/web_save_tests.rs | 55 ++++++++++++++++++ 9 files changed, 169 insertions(+), 17 deletions(-) create mode 100644 crates/ui-egui/src/web_save_tests.rs diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index 7380711f..8a75efb7 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -51,7 +51,7 @@ pub fn specs() -> Vec { spec!( "file.saveAs", "Save as", - "{path} (no extension adds .figcraft); a .fig path writes an experimental export copy of the shown document with `warnings`, keeping the native path, unsaved changes and version preview", + "{path | data: true (no path: returns the file as base64 `data` with its `name`, for a download)} (no extension adds .figcraft); a .fig path writes an experimental export copy of the shown document with `warnings`, keeping the native path, unsaved changes and version preview", false, save_as ), @@ -843,37 +843,53 @@ fn color_profile(s: &mut Session, p: &Value) -> Result { pub(crate) fn save_ends_preview(s: &Session, cmd: &str, p: &Value) -> bool { let path = string(p, "path").or_else(|| if cmd == "file.save" { s.docs.get(crate::branches::file_tab(s)).and_then(|ds| ds.path.clone()) } else { None }); - path.is_some_and(|path| ext(&path) != "fig") + path.is_some_and(|path| ext(&path) != "fig") || (cmd == "file.saveAs" && wants_data(p)) +} + +/// `file.saveAs` asked for the file's bytes instead of a path to write (the browser's download). +fn wants_data(p: &Value) -> bool { + p.get("data").and_then(Value::as_bool) == Some(true) } /// Save the file of the active tab (the main file for a branch tab, with its branches), or export /// the active document as an experimental `.fig` copy without changing its native save state. -fn save_to(s: &mut Session, path: String) -> Result { - if ext(&path) == "fig" { +/// Without a path the file comes back as base64 `data` for the caller to deliver (#969). +fn save_to(s: &mut Session, path: Option) -> Result { + if let Some(path) = path.as_deref().filter(|p| ext(p) == "fig") { return export_fig(s, &json!({"path": path})); } let i = crate::branches::file_tab(s); let ds = s.docs.get_mut(i).ok_or(EngineError::NoDocument)?; let mut snapshot = FileSnapshot::of(ds); let follows_path = ds.path.as_deref().map_or(ds.doc.name == "Untitled", |old| ds.doc.name == file_stem(old)); - if follows_path && ds.path.as_deref() != Some(path.as_str()) { - Arc::make_mut(&mut snapshot.doc).name = file_stem(&path); + if let Some(path) = path.as_deref() + && follows_path + && ds.path.as_deref() != Some(path) + { + Arc::make_mut(&mut snapshot.doc).name = file_stem(path); } let bytes = snapshot.encode()?; - write(&path, &bytes)?; + if let Some(path) = &path { + write(path, &bytes)?; + } ds.doc = snapshot.doc; - ds.path = Some(path.clone()); + if path.is_some() { + ds.path.clone_from(&path); + } ds.mark_saved(); ds.revision += 1; - let uid = ds.uid; + let (uid, name) = (ds.uid, format!("{}.figcraft", ds.doc.name)); branch_tabs_saved(s, uid); + let Some(path) = path else { + return Ok(json!({"name": name, "bytes": bytes.len(), "data": base64::engine::general_purpose::STANDARD.encode(&bytes)})); + }; remember(s, &path); Ok(json!({"path": path, "bytes": bytes.len()})) } fn save(s: &mut Session, p: &Value) -> Result { if let Some(path) = string(p, "path") { - return save_to(s, path); + return save_to(s, Some(path)); } match s.docs.get(crate::branches::file_tab(s)).ok_or(EngineError::NoDocument)?.path.clone() { // Earlier builds wrote native data under a .fig name: never overwrite that file with an export. @@ -881,7 +897,7 @@ fn save(s: &mut Session, p: &Value) -> Result { s.request_ui("dialog.saveAs", json!({})); Err(EngineError::Disabled("file.save".into(), "the saved path ends in .fig: choose Save as or pass `path`".into())) } - Some(path) => save_to(s, path), + Some(path) => save_to(s, Some(path)), None => { s.request_ui("dialog.saveAs", json!({})); Err(EngineError::Disabled("file.save".into(), "the file has no path yet: pass `path`".into())) @@ -895,8 +911,9 @@ fn save_as(s: &mut Session, p: &Value) -> Result { if ext(&path).is_empty() { path.push_str(".figcraft"); } - save_to(s, path) + save_to(s, Some(path)) } + None if wants_data(p) => save_to(s, None), None => { s.request_ui("dialog.saveAs", json!({})); Err(EngineError::Disabled("file.saveAs".into(), "pass `path`".into())) @@ -1563,6 +1580,23 @@ mod rest_import_tests { assert_eq!(s.docs.len(), open, "a refused open adds nothing"); } + #[test] + fn save_as_data_hands_back_the_file_and_marks_it_saved() { + // The browser has no paths: Save as returns the file for a download (#969). + let mut s = Session::new(); + s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap(); + assert!(s.execute("file.saveAs", &json!({})).is_err(), "no path and no data: still asks for a path"); + let recent = s.prefs.recent_files.clone(); + let r = s.execute("file.saveAs", &json!({"data": true})).unwrap(); + assert_eq!(r["name"], "Untitled.figcraft"); + assert!(!s.ds().unwrap().is_dirty()); + assert_eq!(s.ds().unwrap().path, None, "still no path to save over"); + assert_eq!(s.prefs.recent_files, recent, "nothing on disk to remember"); + let mut t = Session::new(); + t.execute("file.open", &json!({"data": r["data"], "name": r["name"]})).unwrap(); + assert!(t.doc().unwrap().nodes().any(|n| matches!(n.kind, NodeKind::Rectangle)), "the bytes reopen"); + } + #[test] fn open_and_import_rest_json() { let dir = std::env::temp_dir().join(format!("figcraft-rest-{}", std::process::id())); diff --git a/crates/ui-egui/locales/en.toml b/crates/ui-egui/locales/en.toml index ae566fc8..3ce0659d 100644 --- a/crates/ui-egui/locales/en.toml +++ b/crates/ui-egui/locales/en.toml @@ -319,6 +319,7 @@ name = "English" "Corner radius" = "Corner radius" "Corner smoothing" = "Corner smoothing" "Couldn't download the variables" = "Couldn't download the variables" +"Couldn't download {name}" = "Couldn't download {name}" "Couldn't reach {server}: showing what this computer remembers." = "Couldn't reach {server}: showing what this computer remembers." "Couldn't read {name}." = "Couldn't read {name}." "Couldn't save automatically: {error}" = "Couldn't save automatically: {error}" diff --git a/crates/ui-egui/locales/es.toml b/crates/ui-egui/locales/es.toml index 596feda6..bd572dbe 100644 --- a/crates/ui-egui/locales/es.toml +++ b/crates/ui-egui/locales/es.toml @@ -10,6 +10,7 @@ status = "draft — needs native review" [ui] "Compatibility notes" = "Notas de compatibilidad" "Couldn't download the variables" = "No se pudieron descargar las variables" +"Couldn't download {name}" = "No se pudo descargar {name}" "% of all commits" = "% del total de commits" "(no longer published)" = "(ya no publicado)" diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index bf9f1b29..9695faee 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -665,7 +665,11 @@ pub(crate) fn file_saved(app: &mut FigApp, result: &Value) { } fn result_file_name(result: &Value) -> String { - result["path"].as_str().and_then(|p| Path::new(p).file_name()).map(|f| f.to_string_lossy().into_owned()).unwrap_or_default() + match result["path"].as_str() { + Some(p) => Path::new(p).file_name().map(|f| f.to_string_lossy().into_owned()).unwrap_or_default(), + // A download (#969). + None => result["name"].as_str().unwrap_or_default().to_owned(), + } } /// The `.fig` result stays an export: native save state is unchanged, and omissions are reported. @@ -681,6 +685,15 @@ pub(crate) fn fig_exported(app: &mut FigApp, result: &Value) { /// Save the whole file as `.fig`; the toast says how much was left out. fn save_fig(app: &mut FigApp, name: &str) { let filename = format!("{name}.fig"); + if app.services.downloads() { + if let Some(mut r) = app.run("file.export", json!({"format": "fig"})) + && app.download(&filename, &r) + { + r["name"] = json!(filename); + fig_exported(app, &r); + } + return; + } app.pick_save(tr("Export"), &filename, &["fig"], |app, p| { if let Some(r) = app.run("file.export", json!({"format": "fig", "path": p.to_string_lossy()})) { fig_exported(app, &r); diff --git a/crates/ui-egui/src/export_panel.rs b/crates/ui-egui/src/export_panel.rs index 8617c35a..6a4ca8ee 100644 --- a/crates/ui-egui/src/export_panel.rs +++ b/crates/ui-egui/src/export_panel.rs @@ -320,6 +320,15 @@ pub(crate) fn export_layers(app: &mut FigApp, ids: &[NodeId], assets: bool) { [] => {} // The suggested name keeps only the file's own name (a layer's folders apply to folders). [one] => save_one(app, &[one.id], &one.setting, one.file.rsplit('/').next().unwrap_or(&one.file)), + // No folders in the browser: each file arrives as its own download (#969). + _ if app.services.downloads() => { + let Some(r) = app.run("file.exportLayers", json!({"ids": ids, "assets": assets})) else { return }; + let files = r["files"].as_array().map_or(&[][..], Vec::as_slice); + let n = files.iter().filter(|f| app.download(f["name"].as_str().unwrap_or_default(), f)).count(); + if n > 0 { + app.toast(trn("Exported {n} files", n, &[])); + } + } _ => { let ids = ids.to_vec(); app.pick_folder(tr("Export"), move |app, dir| { @@ -337,6 +346,14 @@ pub(crate) fn save_one(app: &mut FigApp, ids: &[NodeId], setting: &ExportSetting let ext = setting.format.ext(); let mut params = setting_params(setting); params["ids"] = json!(ids); + if app.services.downloads() { + if let Some(r) = app.run("file.export", params) + && app.download(file, &r) + { + app.toast(trf("Exported {name}", &[("name", &file)])); + } + return; + } app.pick_save(tr("Export"), file, &[ext], move |app, p| { params["path"] = json!(p.to_string_lossy()); if app.run("file.export", params).is_some() { diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index c93333b3..788bbf4f 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -223,6 +223,8 @@ mod vector_tail_ui_tests; #[cfg(test)] mod web_clipboard_tests; #[cfg(test)] +mod web_save_tests; +#[cfg(test)] mod windows_qa_tests; #[cfg(test)] mod windows_tests; @@ -1140,6 +1142,14 @@ impl FigApp { } pub fn save_as_dialog(&mut self) { + if self.services.downloads() { + if let Some(r) = self.run("file.saveAs", json!({"data": true})) + && self.download(r["name"].as_str().unwrap_or_default(), &r) + { + dialogs::file_saved(self, &r); + } + return; + } let Ok(name) = self.session.doc().map(|d| d.name.clone()) else { return }; self.pick_save(i18n::tr("Save as"), &format!("{name}.figcraft"), &["figcraft", "fig"], |app, mut p| { if p.extension().is_none_or(|e| e.is_empty()) { @@ -1244,6 +1254,18 @@ impl FigApp { self.start_dialog(|services| services.pick_save(title, name, exts), true, done); } + /// Hand a command result's base64 `data` over as a download named `name`, where the platform + /// saves by downloads rather than save dialogs (the browser, #969). Says so when nothing arrived. + pub(crate) fn download(&mut self, name: &str, result: &Value) -> bool { + use base64::Engine as _; + let bytes = result["data"].as_str().and_then(|d| base64::engine::general_purpose::STANDARD.decode(d).ok()); + if bytes.is_some_and(|b| self.services.download(name, &b)) { + return true; + } + self.toast(i18n::trf("Couldn't download {name}", &[("name", &name)])); + false + } + /// Pick a folder; `done` runs as [`FigApp::pick_open`]'s does. pub fn pick_folder(&mut self, title: &str, done: impl FnOnce(&mut FigApp, PathBuf) + 'static) { self.start_dialog(|services| services.pick_folder(title), true, done); diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 9659c6b3..afa34873 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -248,6 +248,15 @@ pub fn invoke(app: &mut FigApp, id: &str) { /// Every visible top-level frame of the page as one PDF page each, through a save dialog. fn export_frames_pdf(app: &mut FigApp) { let name = app.session.doc().map(|d| d.name.clone()).unwrap_or_else(|_| "Untitled".into()); + if app.services.downloads() { + let file = format!("{name}.pdf"); + if let Some(r) = app.run("file.exportFramesPdf", json!({})) + && app.download(&file, &r) + { + app.toast(trf("Exported {name}", &[("name", &file)])); + } + return; + } app.pick_save(tr("Export"), &format!("{name}.pdf"), &["pdf"], |app, p| { if app.run("file.exportFramesPdf", json!({"path": p.to_string_lossy()})).is_some() { app.toast(trf("Exported {name}", &[("name", &p.file_name().map(|f| f.to_string_lossy().to_string()).unwrap_or_default())])); diff --git a/crates/ui-egui/src/variables_export_ui_tests.rs b/crates/ui-egui/src/variables_export_ui_tests.rs index 40a84393..ce51a096 100644 --- a/crates/ui-egui/src/variables_export_ui_tests.rs +++ b/crates/ui-egui/src/variables_export_ui_tests.rs @@ -9,12 +9,12 @@ use serde_json::{Value, json}; use crate::variables_panel::export_dialog; use crate::{FigApp, NoServices, Services}; -type Downloads = Arc)>>>; +pub(crate) type Downloads = Arc)>>>; /// Services that save by downloads and keep them (`deliver` false: the browser refused). -struct Browser { - got: Downloads, - deliver: bool, +pub(crate) struct Browser { + pub(crate) got: Downloads, + pub(crate) deliver: bool, } impl Services for Browser { diff --git a/crates/ui-egui/src/web_save_tests.rs b/crates/ui-egui/src/web_save_tests.rs new file mode 100644 index 00000000..7d1d75d2 --- /dev/null +++ b/crates/ui-egui/src/web_save_tests.rs @@ -0,0 +1,55 @@ +//! Save, Save as and Export where the platform saves by downloads (the browser, which has no save +//! dialogs or paths): the file arrives as a download instead of nothing happening (#969). + +use base64::Engine as _; +use figcraft_doc::{ExportSetting, NodeId}; +use figcraft_engine::Session; +use serde_json::json; + +use crate::FigApp; +use crate::variables_export_ui_tests::{Browser, Downloads}; + +fn browser(deliver: bool) -> (FigApp, Downloads, NodeId) { + let mut s = Session::new(); + let r = s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap(); + let id = serde_json::from_value(r["id"].clone()).unwrap(); + let got = Downloads::default(); + (FigApp::new(s, Box::new(Browser { got: got.clone(), deliver })), got, id) +} + +fn toast(app: &FigApp) -> String { + app.ui.toast.as_ref().map(|t| t.0.clone()).unwrap_or_default() +} + +#[test] +fn save_downloads_the_figcraft_file() { + let (mut app, got, _) = browser(true); + app.save(); + let got = got.lock().unwrap(); + let [(name, bytes)] = got.as_slice() else { panic!("one download, got {}", got.len()) }; + assert_eq!(name, "Untitled.figcraft"); + let mut reopened = Session::new(); + let data = base64::engine::general_purpose::STANDARD.encode(bytes); + reopened.execute("file.open", &json!({"data": data, "name": name})).unwrap(); + assert!(!app.session.ds().unwrap().is_dirty()); + assert_eq!(toast(&app), "Saved Untitled.figcraft"); +} + +#[test] +fn export_downloads_the_exported_file() { + let (mut app, got, id) = browser(true); + crate::export_panel::save_one(&mut app, &[id], &ExportSetting::default(), "Rectangle.png"); + let got = got.lock().unwrap(); + let [(name, bytes)] = got.as_slice() else { panic!("one download, got {}", got.len()) }; + assert_eq!(name, "Rectangle.png"); + assert!(bytes.starts_with(b"\x89PNG")); + assert_eq!(toast(&app), "Exported Rectangle.png"); +} + +#[test] +fn a_refused_download_says_so() { + let (mut app, got, _) = browser(false); + app.save_as_dialog(); + assert_eq!(got.lock().unwrap().len(), 1); + assert_eq!(toast(&app), "Couldn't download Untitled.figcraft"); +} From 9315e5e014705e5866fa1d74fa8e9b2075a00b1c Mon Sep 17 00:00:00 2001 From: Kameron Date: Wed, 21 Oct 2026 11:19:47 -0700 Subject: [PATCH 05/50] command.batch: named steps ($ref) and slash paths in field A batch step can name itself with "as" and later steps refer to it with {"$ref": "name"}, alongside positional {"$step": n}. "field" now takes a slash path into the result as well as a key, so {"$ref": "copy", "field": "ids/0"} reaches the first id edit.duplicate returned (the convention variable.bind uses for fills/0/color; a leading "/" as in JSON Pointer also works, and a key holding "/" still matches first). Resolution moves to crates/engine/src/batch.rs (BatchStep, BatchScope), shared by command.batch, the CLI script runner, the control channel and the MCP batch tool, which now passes "as" through. Duplicate names fail before any step runs; unknown, same-step or later names, bad paths and out-of-range indexes fail the batch with the step, name and full path. $ref is reserved like $step; nested batches keep their own names. Fixes #994. Co-Authored-By: Claude Opus 5.5 --- apps/figcraft-cli/src/files.rs | 65 ++++++-- crates/engine/src/batch.rs | 192 ++++++++++++++++++++++ crates/engine/src/batch_step_ref_tests.rs | 148 +++++++++++++++++ crates/engine/src/cmd/edit.rs | 9 +- crates/engine/src/collab_live_tests.rs | 6 +- crates/engine/src/lib.rs | 79 +++------ crates/engine/src/tests.rs | 5 + crates/mcp/src/tools.rs | 10 +- crates/mcp/tests/agent_tasks.rs | 29 ++++ docs/cli.md | 14 +- docs/control-protocol.md | 14 +- docs/mcp.md | 52 ++++-- 12 files changed, 516 insertions(+), 107 deletions(-) create mode 100644 crates/engine/src/batch.rs diff --git a/apps/figcraft-cli/src/files.rs b/apps/figcraft-cli/src/files.rs index 46215599..d18e071a 100644 --- a/apps/figcraft-cli/src/files.rs +++ b/apps/figcraft-cli/src/files.rs @@ -4,7 +4,7 @@ use std::path::Path; use std::process::ExitCode; use figcraft_doc::{Document, ExportFormat, ExportSetting, NodeId, NodeKind, PrintSettings}; -use figcraft_engine::Session; +use figcraft_engine::{BatchScope, BatchStep, Session}; use serde_json::{Value, json}; use crate::{CliError, CliResult}; @@ -309,7 +309,7 @@ pub fn render(file: &str, out: &str, scale: f64, page: Option<&str>) -> CliResul } /// Parse a script: a JSON array of steps, `{"commands": [...]}`, or JSON lines. -pub fn parse_script(text: &str) -> Result, String> { +pub fn parse_script(text: &str) -> Result, String> { let steps: Vec = match serde_json::from_str::(text) { Ok(Value::Array(a)) => a, Ok(Value::Object(o)) if o.contains_key("commands") => { @@ -334,7 +334,8 @@ pub fn parse_script(text: &str) -> Result, String> { Some(p @ Value::Object(_)) => p.clone(), Some(_) => return Err(format!("step {i} ({cmd}): `params` must be an object")), }; - Ok((cmd.to_string(), params)) + let name = figcraft_engine::batch::step_name(i, &s).map_err(|e| e.to_string())?; + Ok(BatchStep { name, ..BatchStep::new(cmd, params) }) }) .collect() } @@ -352,31 +353,30 @@ pub fn run_script(script: &str, input: Option<&str>, out: Option<&str>) -> CliRe None => Session::new(), }; // One undo step and all-or-nothing, the way the same commands behave through `command.batch` - // (MCP, the control channel, plugins): `{"$step": n}` resolves against the steps before it, and - // a step that fails takes the whole script back instead of leaving the earlier steps applied. - // The result lines are held back until the script is through, so none of them reports work that - // was rolled back. - let mut results: Vec = Vec::with_capacity(steps.len()); + // (MCP, the control channel, plugins): `{"$step": n}` and `{"$ref": "name"}` resolve against the + // steps before it, and a step that fails takes the whole script back instead of leaving the + // earlier steps applied. The result lines are held back until the script is through, so none of + // them reports work that was rolled back. + let mut scope = BatchScope::new(&steps).map_err(|e| CliError::Failed(format!("{script}: {e}")))?; let mut failed_at = 0; let outcome = s.grouped(&format!("run {script}"), |s| { - for (i, (cmd, params)) in steps.iter().enumerate() { + for (i, step) in steps.iter().enumerate() { failed_at = i; - let v = s.batch_step(&results, i, cmd, params)?; + s.batch_step(&mut scope, &step.command, &step.params)?; s.ui_requests.clear(); - results.push(v); } Ok(()) }); if let Err(e) = outcome { - let cmd = steps.get(failed_at).map_or("", |(cmd, _)| cmd.as_str()); + let cmd = steps.get(failed_at).map_or("", |step| step.command.as_str()); let i = failed_at; println!("{}", json!({"step": i, "command": cmd, "ok": false, "error": e.to_string(), "rolledBack": true})); eprintln!("error: step {i} ({cmd}) failed: {e}"); eprintln!("the script's document changes were rolled back"); return Ok(ExitCode::from(1)); } - for (i, ((cmd, _), v)) in steps.iter().zip(&results).enumerate() { - println!("{}", json!({"step": i, "command": cmd, "ok": true, "result": v})); + for (i, (step, v)) in steps.iter().zip(scope.results()).enumerate() { + println!("{}", json!({"step": i, "command": step.command, "ok": true, "result": v})); } if let Some(out) = out { let ds = s.ds().map_err(|e| CliError::Failed(e.to_string()))?; @@ -494,6 +494,43 @@ mod tests { std::fs::remove_dir_all(dir).unwrap(); } + /// A script names its steps with `as` and reads paths into their results, like `command.batch`. + #[test] + fn a_script_refers_to_named_steps_and_paths() { + let dir = temp_dir("run-ref"); + let script = dir.join("script.json"); + std::fs::write( + &script, + r#"[ + {"command": "node.create", "as": "card", "params": {"type": "frame", "name": "Card", "x": 0, "y": 0, "width": 200, "height": 100}}, + {"command": "edit.duplicate", "as": "copy", "params": {"ids": [{"$ref": "card"}]}}, + {"command": "node.set", "params": {"ids": [{"$ref": "copy", "field": "ids/0"}], "props": {"name": "Copy"}}} + ]"#, + ) + .unwrap(); + let out = dir.join("out.figcraft"); + run_script(script.to_str().unwrap(), None, Some(out.to_str().unwrap())).unwrap(); + + let mut s = Session::empty(); + s.execute("file.open", &json!({"path": out.to_str().unwrap()})).unwrap(); + let doc = s.doc().unwrap(); + let top = doc.node(s.page().unwrap()).unwrap().children.clone(); + let names: Vec<_> = top.iter().map(|id| doc.node(*id).unwrap().name.clone()).collect(); + assert_eq!(names, ["Card", "Copy"]); + std::fs::remove_dir_all(dir).unwrap(); + } + + /// Two steps with one name fail before anything runs. + #[test] + fn a_script_with_a_name_twice_runs_nothing() { + let dir = temp_dir("run-dup-name"); + let script = dir.join("script.json"); + std::fs::write(&script, r#"[{"command": "select.none", "as": "a"}, {"command": "select.none", "as": "a"}]"#).unwrap(); + let Err(CliError::Failed(e)) = run_script(script.to_str().unwrap(), None, None) else { panic!("a name twice must fail") }; + assert!(e.contains("step 1: `as` \"a\" is already step 0's name"), "{e}"); + std::fs::remove_dir_all(dir).unwrap(); + } + /// A step that fails takes the whole script back: nothing is written, and the failure says so. #[test] fn a_failed_step_leaves_no_output() { diff --git a/crates/engine/src/batch.rs b/crates/engine/src/batch.rs new file mode 100644 index 00000000..5c4550ec --- /dev/null +++ b/crates/engine/src/batch.rs @@ -0,0 +1,192 @@ +//! Step references in `command.batch`: a step's params can use what an earlier step returned. +//! +//! `{"$step": n}` stands for the `id` in the result of step `n` (zero-based), and `{"$ref": "name"}` +//! for the `id` in the result of the step that called itself `name` with `"as": "name"`. Either +//! takes a `field`, a key of that result or a slash path into it (`ids/0`, `map/3`, `bounds/x`), the +//! way `variable.bind` names `fills/0/color`. The CLI's script runner resolves its steps the same way. + +use std::collections::HashMap; + +use serde_json::{Map, Value}; + +use crate::{Result, bad}; + +/// Deepest params nesting the resolver walks before giving up. +const MAX_DEPTH: usize = 64; + +/// One step of a batch: a command, its params and the name later steps can call it by. +#[derive(Clone, Debug, PartialEq)] +pub struct BatchStep { + pub command: String, + pub params: Value, + /// The step's `as`, for `{"$ref": name}` in later steps. + pub name: Option, +} + +impl BatchStep { + /// A step without a name. + pub fn new(command: impl Into, params: Value) -> Self { + Self { command: command.into(), params, name: None } + } +} + +/// A step's `as` (`step` is its index, for the error): `None` when it has none. +pub fn step_name(step: usize, json: &Value) -> Result> { + match json.get("as") { + None | Some(Value::Null) => Ok(None), + Some(Value::String(name)) if !name.is_empty() => Ok(Some(name.clone())), + Some(_) => Err(bad("command.batch", format!("step {step}: `as` must be a name (a non-empty string)"))), + } +} + +/// The steps of one batch run so far: their results, and which step each `as` name belongs to. +/// A nested `command.batch` step gets its own scope, so its references are to its own steps. +#[derive(Clone, Debug, Default)] +pub struct BatchScope { + names: HashMap, + results: Vec, +} + +impl BatchScope { + /// The scope for running `steps`. Two steps with the same name fail here, before any step runs. + pub fn new(steps: &[BatchStep]) -> Result { + let mut names = HashMap::new(); + for (i, step) in steps.iter().enumerate() { + let Some(name) = &step.name else { continue }; + if let Some(first) = names.insert(name.clone(), i) { + return Err(bad("command.batch", format!("step {i}: `as` \"{name}\" is already step {first}'s name"))); + } + } + Ok(Self { names, results: Vec::with_capacity(steps.len()) }) + } + + /// The results of the steps run so far, in order. + pub fn results(&self) -> &[Value] { + &self.results + } + + pub fn into_results(self) -> Vec { + self.results + } + + /// The index of the step that runs next. + pub fn next_step(&self) -> usize { + self.results.len() + } + + pub(crate) fn push(&mut self, result: Value) { + self.results.push(result); + } + + /// `params` of the next step with every reference in it replaced. + pub(crate) fn resolve(&self, params: &Value) -> Result { + self.resolve_in(params, 0) + } + + fn resolve_in(&self, v: &Value, depth: usize) -> Result { + let step = self.next_step(); + if depth > MAX_DEPTH { + return Err(bad("command.batch", format!("step {step}: params nest deeper than {MAX_DEPTH} levels"))); + } + match v { + Value::Object(o) if o.contains_key("$step") || o.contains_key("$ref") => self.reference(o), + Value::Object(o) => { + let mut out = Map::with_capacity(o.len()); + for (k, x) in o { + out.insert(k.clone(), self.resolve_in(x, depth + 1)?); + } + Ok(Value::Object(out)) + } + Value::Array(a) => a.iter().map(|x| self.resolve_in(x, depth + 1)).collect::>>().map(Value::Array), + _ => Ok(v.clone()), + } + } + + /// The value a `{"$step": n}` or `{"$ref": "name"}` object (with an optional `field`) stands for. + fn reference(&self, o: &Map) -> Result { + let step = self.next_step(); + let fail = |msg: String| bad("command.batch", format!("step {step}: {msg}")); + let key = if o.contains_key("$step") { "$step" } else { "$ref" }; + if let Some(k) = o.keys().find(|k| *k != key && *k != "field") { + return Err(fail(format!("a `{key}` reference takes only `field`, not `{k}`"))); + } + let (n, who) = if key == "$step" { + let n = o.get("$step").and_then(Value::as_u64).ok_or_else(|| fail("`$step` must be a step index (0, 1, …)".into()))?; + let n = usize::try_from(n).ok().filter(|n| *n < step).ok_or_else(|| { + let range = if step == 0 { "there is none before step 0".to_string() } else { format!("0 to {}", step - 1) }; + fail(format!("`$step` {n} must be an earlier step ({range})")) + })?; + (n, format!("step {n}")) + } else { + let name = o.get("$ref").and_then(Value::as_str).ok_or_else(|| fail("`$ref` must be a step name (a string)".into()))?; + let n = *self.names.get(name).ok_or_else(|| fail(format!("`$ref` \"{name}\" names no step ({})", self.known_names())))?; + if n >= step { + return Err(fail(format!("`$ref` \"{name}\" is step {n}, not an earlier step"))); + } + (n, format!("step {n} (\"{name}\")")) + }; + let path = match o.get("field") { + None => "id", + Some(Value::String(f)) => f.as_str(), + Some(_) => return Err(fail("`field` must be a string".into())), + }; + let result = self.results.get(n).ok_or_else(|| fail(format!("{who} has no result")))?; + lookup(result, path).cloned().map_err(|why| fail(format!("{who}'s result has no `{path}`{why}"))) + } + + fn known_names(&self) -> String { + let mut names: Vec<_> = self.names.iter().collect(); + names.sort_by_key(|(_, i)| **i); + if names.is_empty() { + return "no step has an `as` name".into(); + } + let list: Vec<_> = names.iter().map(|(name, i)| format!("\"{name}\" is step {i}")).collect(); + list.join(", ") + } +} + +/// `path` in `v`: a key as written, else a slash path (`ids/0`, `bounds/x`; a leading `/` as in +/// JSON Pointer is allowed). The error is the detail after "has no `path`". +fn lookup<'a>(v: &'a Value, path: &str) -> std::result::Result<&'a Value, String> { + // A key as written first, so a key holding `/` still works as it did before paths. + if let Some(x) = v.get(path) { + return Ok(x); + } + let hint = if path.contains('.') && !path.contains('/') { " (paths use `/`, as in `ids/0`)" } else { "" }; + walk(v, path.strip_prefix('/').unwrap_or(path)).map_err(|why| format!("{why}{hint}")) +} + +fn walk<'a>(v: &'a Value, path: &str) -> std::result::Result<&'a Value, String> { + let mut cur = v; + let mut walked = String::new(); + for seg in path.split('/') { + let here = if walked.is_empty() { "the result".to_string() } else { format!("`{walked}`") }; + cur = match cur { + Value::Object(o) => o.get(seg).ok_or_else(|| if walked.is_empty() { String::new() } else { format!(": {here} has no `{seg}`") })?, + Value::Array(a) => match seg.parse::() { + Ok(i) => a.get(i).ok_or_else(|| { + let items = if a.len() == 1 { "1 item".to_string() } else { format!("{} items", a.len()) }; + format!(": {here} has {items}") + })?, + Err(_) => return Err(format!(": {here} is a list, so `{seg}` must be an index (0, 1, …)")), + }, + _ => return Err(format!(": {here} is {}", kind(cur))), + }; + if !walked.is_empty() { + walked.push('/'); + } + walked.push_str(seg); + } + Ok(cur) +} + +fn kind(v: &Value) -> &'static str { + match v { + Value::Null => "null", + Value::Bool(_) => "a boolean", + Value::Number(_) => "a number", + Value::String(_) => "a string", + Value::Array(_) => "a list", + Value::Object(_) => "an object", + } +} diff --git a/crates/engine/src/batch_step_ref_tests.rs b/crates/engine/src/batch_step_ref_tests.rs index ac69118e..451a6300 100644 --- a/crates/engine/src/batch_step_ref_tests.rs +++ b/crates/engine/src/batch_step_ref_tests.rs @@ -110,3 +110,151 @@ fn a_nested_batch_refers_to_its_own_steps() { let rect = s.doc().unwrap().node(id(&inner[1])).unwrap().clone(); assert_eq!(rect.parent, Some(id(&inner[0])), "in the nested batch's own first frame, not the outer one"); } + +/// Runs `commands` as a batch and returns the error message, which must be `BadParams`. +fn batch_error(s: &mut Session, commands: serde_json::Value) -> String { + match s.execute("command.batch", &json!({"commands": commands})) { + Err(EngineError::BadParams { msg, .. }) => msg, + other => panic!("expected BadParams, got {other:?}"), + } +} + +#[test] +fn a_named_step_is_referred_to_by_its_name() { + let mut s = Session::new(); + let results = s + .execute( + "command.batch", + &json!({"commands": [ + {"command": "node.create", "as": "card", "params": {"type": "frame", "width": 200, "height": 100}}, + {"command": "node.create", "as": "swatch", "params": {"type": "rectangle", "parent": {"$ref": "card"}, "width": 20, "height": 20}}, + {"command": "node.set", "params": {"ids": [{"$ref": "swatch", "field": "id"}], "props": {"name": "Swatch"}}}, + {"command": "node.create", "params": {"type": "text", "text": "hi", "parent": {"$step": 0}}} + ]}), + ) + .unwrap(); + let (frame, rect, text) = (id(&results[0]), id(&results[1]), id(&results[3])); + let doc = s.doc().unwrap(); + assert_eq!(doc.node(rect).unwrap().parent, Some(frame)); + assert_eq!(doc.node(rect).unwrap().name, "Swatch"); + assert_eq!(doc.node(text).unwrap().parent, Some(frame), "`$step` and `$ref` mix in one batch"); + assert_eq!(s.ds().unwrap().history.undo.len(), 1, "still one undo step"); +} + +/// `edit.duplicate` answers `{"ids": [...]}`: a slash path in `field` takes one of them. +#[test] +fn a_field_path_indexes_into_a_list_in_the_result() { + let mut s = Session::new(); + let results = s + .execute( + "command.batch", + &json!({"commands": [ + {"command": "node.create", "as": "a", "params": {"type": "frame", "name": "A", "width": 10, "height": 10}}, + {"command": "node.create", "as": "b", "params": {"type": "frame", "name": "B", "width": 10, "height": 10}}, + {"command": "edit.duplicate", "as": "copies", "params": {"ids": [{"$ref": "a"}, {"$ref": "b"}]}}, + {"command": "node.set", "params": {"ids": [{"$ref": "copies", "field": "ids/1"}], "props": {"name": "B copy"}}}, + {"command": "node.set", "params": {"ids": [{"$step": 2, "field": "/ids/0"}], "props": {"name": "A copy"}}} + ]}), + ) + .unwrap(); + let copies = results[2]["ids"].as_array().unwrap().clone(); + let doc = s.doc().unwrap(); + assert_eq!(doc.node(crate::params::id_of(&copies[0]).unwrap()).unwrap().name, "A copy", "a leading `/` works too"); + assert_eq!(doc.node(crate::params::id_of(&copies[1]).unwrap()).unwrap().name, "B copy"); +} + +#[test] +fn a_field_path_walks_nested_objects_and_takes_whole_values() { + let mut scope = crate::BatchScope::default(); + scope.push(json!({"ids": [7, 8], "bounds": {"x": 1.5, "corners": [{"r": 4}]}, "a/b": "slash key"})); + let resolved = scope + .resolve(&json!({ + "x": {"$step": 0, "field": "bounds/x"}, + "r": {"$step": 0, "field": "bounds/corners/0/r"}, + "all": {"$step": 0, "field": "ids"}, + "key": {"$step": 0, "field": "a/b"}, + "pointer": {"$step": 0, "field": "/ids"} + })) + .unwrap(); + assert_eq!(resolved, json!({"x": 1.5, "r": 4, "all": [7, 8], "key": "slash key", "pointer": [7, 8]}), "a key holding `/` is still read as a key"); +} + +#[test] +fn bad_names_and_paths_fail_and_roll_back() { + let mut s = Session::new(); + let before = s.doc().unwrap().node(s.page().unwrap()).unwrap().children.len(); + let frame = |name: &str| json!({"command": "node.create", "as": name, "params": {"type": "frame", "width": 10, "height": 10}}); + let dup = json!({"command": "edit.duplicate", "as": "copy", "params": {"ids": [{"$ref": "card"}]}}); + let set = |r: serde_json::Value| json!({"command": "node.set", "params": {"ids": [r], "props": {"name": "x"}}}); + let later = json!({"command": "node.create", "as": "later", "params": {"type": "frame", "width": 10, "height": 10}}); + for (commands, needle) in [ + (json!([frame("card"), frame("card")]), "step 1: `as` \"card\" is already step 0's name"), + (json!([frame("card"), set(json!({"$ref": "nope"}))]), "step 1: `$ref` \"nope\" names no step (\"card\" is step 0)"), + (json!([{"command": "node.create", "params": {"type": "frame"}}, set(json!({"$ref": "nope"}))]), "no step has an `as` name"), + (json!([frame("card"), set(json!({"$ref": "later"})), later]), "step 1: `$ref` \"later\" is step 2, not an earlier step"), + ( + json!([frame("card"), {"command": "node.set", "as": "self", "params": {"ids": [{"$ref": "self"}], "props": {}}}]), + "is step 1, not an earlier step", + ), + (json!([frame("card"), set(json!({"$ref": 0}))]), "`$ref` must be a step name"), + (json!([frame("card"), set(json!({"$ref": "card", "id": 3}))]), "a `$ref` reference takes only `field`, not `id`"), + (json!([frame("card"), set(json!({"$ref": "card", "$step": 0}))]), "a `$step` reference takes only `field`, not `$ref`"), + (json!([frame("card"), {"command": "node.create", "as": "", "params": {}}]), "step 1: `as` must be a name"), + (json!([frame("card"), {"command": "node.create", "as": 3, "params": {}}]), "step 1: `as` must be a name"), + ( + json!([frame("card"), dup.clone(), set(json!({"$ref": "copy", "field": "ids/1"}))]), + "step 2: step 1 (\"copy\")'s result has no `ids/1`: `ids` has 1 item", + ), + (json!([frame("card"), dup.clone(), set(json!({"$ref": "copy", "field": "ids/first"}))]), "`ids` is a list, so `first` must be an index"), + (json!([frame("card"), dup.clone(), set(json!({"$ref": "copy", "field": "ids/0/x"}))]), "has no `ids/0/x`: `ids/0` is a number"), + (json!([frame("card"), dup.clone(), set(json!({"$ref": "copy", "field": "map/0"}))]), "step 1 (\"copy\")'s result has no `map/0`"), + (json!([frame("card"), dup.clone(), set(json!({"$ref": "copy", "field": "ids.0"}))]), "has no `ids.0` (paths use `/`, as in `ids/0`)"), + (json!([frame("card"), set(json!({"$step": 0, "field": "id/0"}))]), "has no `id/0`: `id` is a number"), + ] { + let msg = batch_error(&mut s, commands); + assert!(msg.contains(needle), "{msg:?} should contain {needle:?}"); + assert_eq!(s.doc().unwrap().node(s.page().unwrap()).unwrap().children.len(), before, "rolled back"); + } +} + +#[test] +fn text_that_looks_like_a_named_reference_is_left_alone() { + let mut s = Session::new(); + let text = "{\"$ref\": \"card\"} $ref"; + let results = s.execute("command.batch", &json!({"commands": [{"command": "node.create", "params": {"type": "text", "text": text}}]})).unwrap(); + let n = s.doc().unwrap().node(id(&results[0])).unwrap().clone(); + assert!(matches!(n.kind, figcraft_doc::NodeKind::Text(t) if t.characters == text)); +} + +/// A nested batch has its own names: it can't see the outer batch's, may reuse them, and the +/// outer batch can't see its. +#[test] +fn a_nested_batch_has_its_own_names() { + let mut s = Session::new(); + let frame = |name: &str| json!({"command": "node.create", "as": "frame", "params": {"type": "frame", "name": name, "width": 100, "height": 100}}); + let results = s + .execute( + "command.batch", + &json!({"commands": [ + frame("Outer"), + {"command": "command.batch", "as": "inner", "params": {"commands": [ + frame("Inner"), + {"command": "node.create", "params": {"type": "rectangle", "parent": {"$ref": "frame"}, "width": 10, "height": 10}} + ]}}, + {"command": "node.set", "params": {"ids": [{"$ref": "inner", "field": "1/id"}], "props": {"name": "In inner"}}} + ]}), + ) + .unwrap(); + let inner = &results[1]; + let rect = s.doc().unwrap().node(id(&inner[1])).unwrap().clone(); + assert_eq!(rect.parent, Some(id(&inner[0])), "in the nested batch's own frame, not the outer one"); + assert_eq!(rect.name, "In inner", "a path indexes into a nested batch's result list"); + + let msg = batch_error( + &mut s, + json!([frame("Outer"), {"command": "command.batch", "params": {"commands": [ + {"command": "node.create", "params": {"type": "rectangle", "parent": {"$ref": "frame"}, "width": 10, "height": 10}} + ]}}]), + ); + assert!(msg.contains("`$ref` \"frame\" names no step"), "the outer names aren't visible inside: {msg}"); +} diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index a16fbb38..c033c2cd 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -8,7 +8,7 @@ use serde_json::{Value, json}; use super::{CommandSpec, ok}; use crate::params::*; -use crate::{EngineError, Result, Session, bad, spec}; +use crate::{BatchStep, EngineError, Result, Session, bad, spec}; pub fn specs() -> Vec { vec![ @@ -336,15 +336,16 @@ pub fn specs() -> Vec { } ok() }), - spec!("command.batch", "Run several commands", "{label?, commands: [{command, params}]} (one undo step)", false, |s, p| { + spec!("command.batch", "Run several commands", "{label?, commands: [{command, params, as?}]} (one undo step)", false, |s, p| { let label = string(p, "label").unwrap_or_else(|| "Batch".into()); - let cmds: Vec<(String, Value)> = match get(p, "commands") { + let cmds: Vec = match get(p, "commands") { Some(Value::Array(a)) => { let mut out = Vec::new(); for (i, c) in a.iter().enumerate() { let cmd = c.get("command").and_then(Value::as_str).ok_or_else(|| bad("command.batch", format!("step {i} has no `command`")))?; - out.push((cmd.to_string(), c.get("params").cloned().unwrap_or(json!({})))); + let params = c.get("params").cloned().unwrap_or(json!({})); + out.push(BatchStep { name: crate::batch::step_name(i, c)?, ..BatchStep::new(cmd, params) }); } out } diff --git a/crates/engine/src/collab_live_tests.rs b/crates/engine/src/collab_live_tests.rs index 5b759391..d53eeff2 100644 --- a/crates/engine/src/collab_live_tests.rs +++ b/crates/engine/src/collab_live_tests.rs @@ -246,9 +246,9 @@ fn a_group_of_commands_syncs_as_one_step() { let (f, r) = frame_and_rect(room.server.document()); let start = room.server.replica().clone(); let cmds = vec![ - ("node.set".to_string(), json!({"id": r, "props": {"name": "A"}})), - ("node.set".to_string(), json!({"id": f, "props": {"name": "B"}})), - ("shape.rectangle".to_string(), json!({"x": 0, "y": 0, "width": 5, "height": 5})), + crate::BatchStep::new("node.set", json!({"id": r, "props": {"name": "A"}})), + crate::BatchStep::new("node.set", json!({"id": f, "props": {"name": "B"}})), + crate::BatchStep::new("shape.rectangle", json!({"x": 0, "y": 0, "width": 5, "height": 5})), ]; room.s(0).batch("Three", &cmds).unwrap(); room.pump(); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 79e7be0d..048c0722 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -13,6 +13,7 @@ pub mod al_keys; pub mod annotations; pub mod arc_handles; pub mod background; +pub mod batch; pub mod booleans; pub mod branches; pub mod catalog; @@ -64,6 +65,7 @@ pub mod tools; pub mod vectoredit; pub mod widgets; +pub use batch::{BatchScope, BatchStep}; pub use cmd::{CommandSpec, all_commands, find_command}; pub use figcraft_collab; pub use figcraft_doc as doc; @@ -115,47 +117,6 @@ pub fn bad(cmd: &str, msg: impl Into) -> EngineError { EngineError::BadParams { cmd: cmd.to_string(), msg: msg.into() } } -/// Deepest params nesting `resolve_step_refs` walks before giving up. -const STEP_REF_MAX_DEPTH: usize = 64; - -/// Replace every `{"$step": n}` / `{"$step": n, "field": "…"}` in `v` with that field (default -/// `id`) of `results[n]`, the result of an earlier batch step. -fn resolve_step_refs(v: &Value, results: &[Value], step: usize, depth: usize) -> Result { - if depth > STEP_REF_MAX_DEPTH { - return Err(bad("command.batch", format!("step {step}: params nest deeper than {STEP_REF_MAX_DEPTH} levels"))); - } - match v { - Value::Object(o) if o.contains_key("$step") => { - if let Some(k) = o.keys().find(|k| *k != "$step" && *k != "field") { - return Err(bad("command.batch", format!("step {step}: a `$step` reference takes only `field`, not `{k}`"))); - } - let n = o - .get("$step") - .and_then(Value::as_u64) - .ok_or_else(|| bad("command.batch", format!("step {step}: `$step` must be a step index (0, 1, …)")))?; - let field = match o.get("field") { - None => "id", - Some(Value::String(f)) => f.as_str(), - Some(_) => return Err(bad("command.batch", format!("step {step}: `field` must be a string"))), - }; - let Some(result) = usize::try_from(n).ok().and_then(|n| results.get(n)) else { - let range = if step == 0 { "there is none before step 0".to_string() } else { format!("0 to {}", step - 1) }; - return Err(bad("command.batch", format!("step {step}: `$step` {n} must be an earlier step ({range})"))); - }; - result.get(field).cloned().ok_or_else(|| bad("command.batch", format!("step {step}: step {n}'s result has no `{field}`"))) - } - Value::Object(o) => { - let mut out = serde_json::Map::with_capacity(o.len()); - for (k, x) in o { - out.insert(k.clone(), resolve_step_refs(x, results, step, depth + 1)?); - } - Ok(Value::Object(out)) - } - Value::Array(a) => a.iter().map(|x| resolve_step_refs(x, results, step, depth + 1)).collect::>>().map(Value::Array), - _ => Ok(v.clone()), - } -} - /// One undo step. #[derive(Clone, Debug)] pub struct HistoryEntry { @@ -1245,28 +1206,30 @@ impl Session { } /// Run several commands as one undo step. A param value `{"$step": n}` is replaced by the `id` - /// in the result of the earlier step `n` (`{"$step": n, "field": "…"}` picks another field), - /// so a step can target a layer that an earlier step of the same batch created. Any object - /// with a `$step` key in a step's params is such a reference, except inside a nested - /// `command.batch` step: its references are to its own steps. - pub fn batch(&mut self, label: &str, cmds: &[(String, Value)]) -> Result> { + /// in the result of the earlier step `n`, and `{"$ref": "name"}` by the `id` in the result of + /// the earlier step whose `as` is `name`; either takes a `field`, a key or slash path (`ids/0`) + /// into that result. So a step can target a layer that an earlier step of the same batch + /// created. Any object with a `$step` or `$ref` key in a step's params is such a reference, + /// except inside a nested `command.batch` step: its references are to its own steps. + pub fn batch(&mut self, label: &str, steps: &[BatchStep]) -> Result> { + let mut scope = BatchScope::new(steps)?; self.grouped(label, |s| { - let mut results: Vec = Vec::with_capacity(cmds.len()); - for (step, (id, p)) in cmds.iter().enumerate() { - let v = s.batch_step(&results, step, id, p)?; - results.push(v); + for step in steps { + s.batch_step(&mut scope, &step.command, &step.params)?; } - Ok(results) + Ok(scope.into_results()) }) } - /// One step of a batch: `{"$step": n}` in `params` resolves against `results` (the results of - /// the steps before it), then the command runs. [`Session::batch`] runs a list of these as one - /// undo step; a caller with its own list — the CLI's script runner — uses this so its steps - /// resolve `$step` the same way, inside its own [`Session::grouped`]. - pub fn batch_step(&mut self, results: &[Value], step: usize, cmd: &str, params: &Value) -> Result { - let p = if cmd == "command.batch" { params.clone() } else { resolve_step_refs(params, results, step, 0)? }; - self.execute(cmd, &p) + /// The next step of a batch: the references in `params` resolve against `scope` (the steps + /// before it), the command runs and its result joins `scope`. [`Session::batch`] runs a list + /// of these as one undo step; a caller with its own list — the CLI's script runner — uses this + /// so its steps resolve references the same way, inside its own [`Session::grouped`]. + pub fn batch_step(&mut self, scope: &mut BatchScope, cmd: &str, params: &Value) -> Result<()> { + let p = if cmd == "command.batch" { params.clone() } else { scope.resolve(params)? }; + let v = self.execute(cmd, &p)?; + scope.push(v); + Ok(()) } /// Run `f` as one undo step called `label`: the commands it executes push no steps of their diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 646c7c4b..4b811673 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -425,6 +425,11 @@ fn every_command_survives_junk_params() { // Rotation origins and placing with a tool as junk. json!({"tool": [1], "x": 1e308, "y": "NaN", "reset": "maybe", "on": {"x": 1}}), json!({"tool": "frame", "x": -1e308, "y": 1e308, "reset": true, "on": "yes"}), + // Batch step names and reference paths as junk. + json!({"commands": [{"command": "select.none", "as": "a"}, {"command": "select.none", "as": [1]}, {"command": "select.none", "as": "a"}]}), + json!({"commands": [{"command": "select.all", "as": "\u{0}"}, {"command": "node.set", "params": {"ids": [ + {"$ref": "\u{0}", "field": "ids/18446744073709551616/x"}, {"$ref": {"x": 1}}, {"$step": 0, "field": "//"}, {"$ref": "\u{0}", "field": "/"}], + "props": {"name": {"$ref": "nope", "field": 5}}}}]}), ]; for spec in all_commands() { if matches!( diff --git a/crates/mcp/src/tools.rs b/crates/mcp/src/tools.rs index 7714da5a..1e4c887f 100644 --- a/crates/mcp/src/tools.rs +++ b/crates/mcp/src/tools.rs @@ -128,10 +128,10 @@ pub fn tool_definitions() -> Vec { tool( "batch", "Run commands as one step", - "Run several commands in order as ONE undo step (engine `command.batch`). If any command fails, everything is rolled back and the error names the failing step. Returns an array of the results in order. A later step can use a layer an earlier step created: anywhere in its params, {\"$step\": n} stands for the `id` in step n's result (zero-based; {\"$step\": n, \"field\": \"…\"} picks another field). Example: [{\"command\":\"node.create\",\"params\":{\"type\":\"frame\"}}, {\"command\":\"node.create\",\"params\":{\"type\":\"text\",\"text\":\"Hi\",\"parent\":{\"$step\":0}}}] builds a frame and a text inside it in one call.", + "Run several commands in order as ONE undo step (engine `command.batch`). If any command fails, everything is rolled back and the error names the failing step. Returns an array of the results in order. A later step can use what an earlier step returned: name a step with \"as\": \"card\", then anywhere in a later step's params {\"$ref\": \"card\"} stands for the `id` in its result ({\"$step\": n} does the same by zero-based position). Add \"field\" for another part of the result: a key or a slash path, e.g. {\"$ref\": \"copy\", \"field\": \"ids/0\"} for the first id edit.duplicate returned. Any object with a `$ref` or `$step` key is a reference. Example: [{\"command\":\"node.create\",\"as\":\"card\",\"params\":{\"type\":\"frame\"}}, {\"command\":\"node.create\",\"params\":{\"type\":\"text\",\"text\":\"Hi\",\"parent\":{\"$ref\":\"card\"}}}] builds a frame and a text inside it in one call.", obj( json!({ - "commands": {"type": "array", "minItems": 1, "description": "Steps to run", "items": obj(json!({"command": string("Command id"), "params": {"type": "object"}}), &["command"])}, + "commands": {"type": "array", "minItems": 1, "description": "Steps to run", "items": obj(json!({"command": string("Command id"), "params": {"type": "object"}, "as": string("Name for this step, unique in the batch; later steps use its result with {\"$ref\": name}")}), &["command"])}, "label": string("Undo history label (default \"Batch\")"), }), &["commands"], @@ -497,7 +497,11 @@ fn batch(b: &mut dyn Backend, a: &Map) -> Result Date: Wed, 21 Oct 2026 20:35:13 +0200 Subject: [PATCH 06/50] M1: several exported layers arrive as one zip in the browser (#969) Cause: in the browser, exporting several layers started one download per file. Chrome holds back every download after the first until the site is allowed automatic downloads, so the other files didn't arrive. Fix: file.exportLayers takes `zip: true` (without `dir`) and returns the files together as one base64 zip `data`, written by a new figcraft_format::zip_files (the workspace's existing zip dependency). The UI asks for it when the platform saves by downloads and hands over one `.zip`. Test: ui-egui several_layers_download_as_one_zip (one download, a zip holding both layers). It fails on the previous commit (two downloads). --- crates/engine/src/cmd/file.rs | 13 +++++++++++-- crates/format/src/lib.rs | 14 ++++++++++++++ crates/ui-egui/src/export_panel.rs | 13 +++++++------ crates/ui-egui/src/web_save_tests.rs | 16 ++++++++++++++++ 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index 8a75efb7..d5023372 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -65,7 +65,7 @@ pub fn specs() -> Vec { spec!( "file.exportLayers", "Export layers", - "{ids? (default the selection, else every layer on the page with export settings), assets? (true: the Inspect tab's assets in and under them instead: layers with export settings, icons as SVG, images as PNG), dir? (folder to write into; else each file comes back as base64 `data`), bleed? (PDF: points, or with a unit: \"3mm\", \"0.125in\", \"9pt\"), cropMarks?, bleedMarks?, cmyk? (PDF print options): for every PDF instead of each setting's own} every layer once per export setting, named `.` (\"@2x\" when a scaled export has no suffix; repeats get \" 2\"; slashes in a layer name make folders). Returns {files: [{name, id, bytes, path | data}], skipped (layers without settings)}", + "{ids? (default the selection, else every layer on the page with export settings), assets? (true: the Inspect tab's assets in and under them instead: layers with export settings, icons as SVG, images as PNG), dir? (folder to write into; else each file comes back as base64 `data`), zip? (no dir: the files come back together as one base64 zip `data` instead), bleed? (PDF: points, or with a unit: \"3mm\", \"0.125in\", \"9pt\"), cropMarks?, bleedMarks?, cmyk? (PDF print options): for every PDF instead of each setting's own} every layer once per export setting, named `.` (\"@2x\" when a scaled export has no suffix; repeats get \" 2\"; slashes in a layer name make folders). Returns {files: [{name, id, bytes, path | data}], skipped (layers without settings), data? (zip)}", false, export_layers ), @@ -1209,6 +1209,9 @@ fn export_layers(s: &mut Session, p: &Value) -> Result { return Err(EngineError::Disabled(cmd.into(), "no export settings (add one with export.add)".into())); } let dir = string(p, "dir"); + // The browser saves one download at a time: several files go as one zip (#969). + let zip = dir.is_none() && boolean(p, "zip").unwrap_or(false); + let mut members = Vec::new(); // Print options passed here stand in for every PDF setting's own. let print = has_print_param(p).then(|| print_param(cmd, p, PrintSettings::default())).transpose()?; let mut files = Vec::with_capacity(jobs.len()); @@ -1228,12 +1231,18 @@ fn export_layers(s: &mut Session, p: &Value) -> Result { write(&path, &bytes)?; f["path"] = json!(path); } + None if zip => members.push((job.file.as_str(), bytes)), None => f["data"] = json!(base64::engine::general_purpose::STANDARD.encode(&bytes)), } files.push(f); } let with_settings: std::collections::BTreeSet = jobs.iter().map(|j| j.id).collect(); - Ok(json!({"files": files, "skipped": ids.len().saturating_sub(with_settings.len())})) + let mut r = json!({"files": files, "skipped": ids.len().saturating_sub(with_settings.len())}); + if zip { + let archive = figcraft_format::zip_files(members.iter().map(|(n, b)| (*n, b.as_slice()))).map_err(|e| EngineError::Other(e.to_string()))?; + r["data"] = json!(base64::engine::general_purpose::STANDARD.encode(&archive)); + } + Ok(r) } /// A PDF with one page per group of layers (an sRGB document), titled after the file; `area` diff --git a/crates/format/src/lib.rs b/crates/format/src/lib.rs index 9f7e51bc..d0775323 100644 --- a/crates/format/src/lib.rs +++ b/crates/format/src/lib.rs @@ -343,6 +343,20 @@ pub(crate) fn put( z.write_all(bytes).map_err(io_err) } +/// `files` (name, bytes; a `/` in a name makes a folder) as one zip archive: several exports +/// delivered as a single download (#969). +pub fn zip_files<'a>(files: impl IntoIterator) -> Result, FormatError> { + let mut buf = std::io::Cursor::new(Vec::new()); + { + let mut z = zip::ZipWriter::new(&mut buf); + for (name, bytes) in files { + put(&mut z, name, zip::write::SimpleFileOptions::default(), bytes)?; + } + z.finish().map_err(io_err)?; + } + Ok(buf.into_inner()) +} + /// Add `doc` as a `document.json`-style member, serialized straight into the compressor. fn put_json(z: &mut zip::ZipWriter, name: &str, doc: &Document) -> Result<(), FormatError> { z.start_file(name, json_options()).map_err(io_err)?; diff --git a/crates/ui-egui/src/export_panel.rs b/crates/ui-egui/src/export_panel.rs index 6a4ca8ee..39fc4bd1 100644 --- a/crates/ui-egui/src/export_panel.rs +++ b/crates/ui-egui/src/export_panel.rs @@ -320,13 +320,14 @@ pub(crate) fn export_layers(app: &mut FigApp, ids: &[NodeId], assets: bool) { [] => {} // The suggested name keeps only the file's own name (a layer's folders apply to folders). [one] => save_one(app, &[one.id], &one.setting, one.file.rsplit('/').next().unwrap_or(&one.file)), - // No folders in the browser: each file arrives as its own download (#969). + // No folders in the browser, and it lets a page start one download at a time: the files + // arrive together as one zip (#969). _ if app.services.downloads() => { - let Some(r) = app.run("file.exportLayers", json!({"ids": ids, "assets": assets})) else { return }; - let files = r["files"].as_array().map_or(&[][..], Vec::as_slice); - let n = files.iter().filter(|f| app.download(f["name"].as_str().unwrap_or_default(), f)).count(); - if n > 0 { - app.toast(trn("Exported {n} files", n, &[])); + let name = format!("{}.zip", app.session.doc().map_or("Export", |d| d.name.as_str())); + if let Some(r) = app.run("file.exportLayers", json!({"ids": ids, "assets": assets, "zip": true})) + && app.download(&name, &r) + { + app.toast(trn("Exported {n} files", r["files"].as_array().map_or(0, Vec::len), &[])); } } _ => { diff --git a/crates/ui-egui/src/web_save_tests.rs b/crates/ui-egui/src/web_save_tests.rs index 7d1d75d2..5fbb2524 100644 --- a/crates/ui-egui/src/web_save_tests.rs +++ b/crates/ui-egui/src/web_save_tests.rs @@ -53,3 +53,19 @@ fn a_refused_download_says_so() { assert_eq!(got.lock().unwrap().len(), 1); assert_eq!(toast(&app), "Couldn't download Untitled.figcraft"); } + +#[test] +fn several_layers_download_as_one_zip() { + // The browser lets a page start one download at a time: two downloads lost the second. + let (mut app, got, a) = browser(true); + let r = app.session.execute("shape.rectangle", &json!({"x": 20, "y": 0, "width": 10, "height": 10})).unwrap(); + let b: NodeId = serde_json::from_value(r["id"].clone()).unwrap(); + app.session.execute("export.add", &json!({"ids": [a, b]})).unwrap(); + crate::export_panel::export_layers(&mut app, &[a, b], false); + let got = got.lock().unwrap(); + let [(name, bytes)] = got.as_slice() else { panic!("one download, got {}", got.len()) }; + assert_eq!(name, "Untitled.zip"); + assert!(bytes.starts_with(b"PK\x03\x04")); + assert!(bytes.windows(15).any(|w| w == b"Rectangle 2.png"), "both layers are in the zip"); + assert_eq!(toast(&app), "Exported 2 files"); +} From 2118480e7af3c50334bf0b4c599ecb6a3ee010bd Mon Sep 17 00:00:00 2001 From: vetlucasmartins Date: Wed, 21 Oct 2026 20:03:46 +0100 Subject: [PATCH 07/50] Dev Mode: React + Tailwind page code and Tailwind theme export MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - inspect.code {language: "tailwind"}: a layer tree as a React component styled with Tailwind CSS v4 utilities, no stylesheet. Auto layout maps to flex utilities on the spacing scale; fixed-width auto layout frames, text and wide layers become fluid (w-full max-w-[…]); instances are inlined with their overrides, except those connected to code (codeConnect), which are their snippet with one import each; bound variables are theme utilities (bg-accent, rounded-card). - mobile: (same layer names): mobile-first code, desktop classes that differ behind lg:, resets for desktop defaults, padding compared per side; layers only on desktop are hidden below lg, those only on mobile are listed in the header. - variable.export {format: "tailwind"}: @import "tailwindcss" and an @theme block (--color-*, --radius-*, --text-*, --spacing-*, --font-*), names unique per file and shared with page code. Builds on the token roles of the CSS export px fix (#1008). --- crates/engine/src/cmd/variables_io.rs | 24 +- crates/engine/src/codegen.rs | 87 ++++- crates/engine/src/lib.rs | 3 + crates/engine/src/tailwind.rs | 490 ++++++++++++++++++++++++++ crates/engine/src/tailwind_tests.rs | 335 ++++++++++++++++++ docs/mcp.md | 16 + 6 files changed, 934 insertions(+), 21 deletions(-) create mode 100644 crates/engine/src/tailwind.rs create mode 100644 crates/engine/src/tailwind_tests.rs diff --git a/crates/engine/src/cmd/variables_io.rs b/crates/engine/src/cmd/variables_io.rs index 0f55ea2c..c74c46fe 100644 --- a/crates/engine/src/cmd/variables_io.rs +++ b/crates/engine/src/cmd/variables_io.rs @@ -18,7 +18,7 @@ pub fn specs() -> Vec { spec!( "variable.export", "Export variables", - "{collections? [ids or names; default every collection of this file, not library copies], format? (json (default): the local variables JSON that variable.import reads | css: custom properties, the default mode on :root and each other mode on [data-=\"\"]; numbers in px unless layers or scopes use them as opacity or font weight), path? (write it there)} → {text}, or {path} when written", + "{collections? [ids or names; default every collection of this file, not library copies], format? (json (default): the local variables JSON that variable.import reads | css: custom properties, the default mode on :root and each other mode on [data-=\"\"]; numbers in px unless layers or scopes use them as opacity or font weight | tailwind: a Tailwind CSS v4 stylesheet, the default mode as an @theme block named the way inspect.code's tailwind utilities read them: --color-*, --radius-*, --text-*, --spacing-*, --font-*, unique per file), path? (write it there)} → {text}, or {path} when written", false, export ), @@ -46,8 +46,9 @@ fn export(s: &mut Session, p: &Value) -> Result { let text = match string(p, "format").as_deref().unwrap_or("json") { "json" => serde_json::to_string_pretty(&figcraft_format::rest::export_variables(&doc.variables, &colls)) .map_err(|e| EngineError::Other(e.to_string()))?, - "css" => css(doc, &colls), - _ => return Err(bad(cmd, "format: json|css")), + "css" => css(doc, &colls, false), + "tailwind" => css(doc, &colls, true), + _ => return Err(bad(cmd, "format: json|css|tailwind")), }; match string(p, "path") { Some(path) => { @@ -66,16 +67,23 @@ fn css_safe(text: &str) -> String { /// Each collection's variables as custom properties (named as generated code names them): the /// default mode's values on `:root`, every other mode's on `[data-=""]`; /// aliases are `var(--name)`. -fn css(doc: &Document, colls: &[&Collection]) -> String { +fn css(doc: &Document, colls: &[&Collection], tailwind: bool) -> String { let vars = &doc.variables; + // Tailwind theme names, unique per file and the same ones page code reads. + let theme = crate::tailwind::Theme::new(doc); + let name = |v: &Variable| if tailwind { theme.name(v) } else { css_var_of(v) }; // Lengths need a unit where CSS reads them (`border-radius: var(--radius)`); opacity and // font weight don't. let roles = crate::token_roles::Roles::new(doc); - let mut out = String::new(); + let mut out = if tailwind { "@import \"tailwindcss\";\n\n".to_string() } else { String::new() }; for c in colls { let attr = css_var_name(&c.name); for (i, m) in c.modes.iter().enumerate() { - let sel = if i == 0 { ":root".to_string() } else { format!("[data-{}=\"{}\"]", attr.trim_start_matches('-'), css_safe(&m.name)) }; + let sel = match i { + 0 if tailwind => "@theme".to_string(), + 0 => ":root".to_string(), + _ => format!("[data-{}=\"{}\"]", attr.trim_start_matches('-'), css_safe(&m.name)), + }; out.push_str(&format!("/* {} · {} */\n{sel} {{\n", css_safe(&c.name), css_safe(&m.name))); for v in vars.variables.iter().filter(|v| v.collection == c.id) { let value = match v.values.get(&m.id) { @@ -85,12 +93,12 @@ fn css(doc: &Document, colls: &[&Collection]) -> String { Some(VariableValue::String(t)) => format!("\"{}\"", css_safe(t)), Some(VariableValue::Boolean(b)) => b.to_string(), Some(VariableValue::Alias(a)) => match vars.get(a) { - Some(t) => format!("var({})", css_var_of(t)), + Some(t) => format!("var({})", name(t)), None => continue, }, None => continue, }; - out.push_str(&format!(" {}: {value};\n", css_var_of(v))); + out.push_str(&format!(" {}: {value};\n", name(v))); } out.push_str("}\n"); } diff --git a/crates/engine/src/codegen.rs b/crates/engine/src/codegen.rs index 0871f886..8997587c 100644 --- a/crates/engine/src/codegen.rs +++ b/crates/engine/src/codegen.rs @@ -18,7 +18,7 @@ pub fn specs() -> Vec { vec![spec!( "inspect.code", "Code for layer", - "{id?, language?: css|html|react|leptos|swiftui|compose (default css; html, react and leptos are the whole layer tree; components take their properties as parameters, instances pass their values; a component connected to code (codeConnect.set) gives its import and snippet instead), unit?: px|rem (CSS, HTML, React and Leptos; default px), rootFontSize? (rem: pixels per rem, default 16)} → {code, language, connected}", + "{id?, language?: css|html|react|leptos|tailwind|swiftui|compose (default css; html, react and leptos are the whole layer tree; components take their properties as parameters, instances pass their values; a component connected to code (codeConnect.set) gives its import and snippet instead; tailwind is React with Tailwind CSS v4 utilities for pages: fluid auto layout boxes, instances inlined with their overrides, bound variables as theme utilities), mobile? (tailwind: a mobile frame with the same layer names; the code is mobile first with the desktop layer's classes behind lg:), unit?: px|rem (CSS, HTML, React and Leptos; default px), rootFontSize? (rem: pixels per rem, default 16)} → {code, language, connected}", false, |s, p| { let cmd = "inspect.code"; @@ -40,7 +40,14 @@ pub fn specs() -> Vec { return Err(bad(cmd, "no such layer")); } let connected = crate::code_connect::link(doc, id, lang).is_some(); - let code = code_for(doc, id, lang); + let mobile = match get(p, "mobile") { + None | Some(serde_json::Value::Null) => None, + Some(v) => Some(id_of(v).filter(|m| doc.contains(*m)).ok_or_else(|| bad(cmd, "mobile: the id of a mobile frame"))?), + }; + let code = match (lang, mobile) { + (CodeLang::Tailwind, Some(m)) => crate::tailwind::code(doc, id, Some(m)), + _ => code_for(doc, id, lang), + }; let code = match rem { Some(root) if lang.is_web() => px_to_rem(&code, root), _ => code, @@ -61,18 +68,22 @@ pub enum CodeLang { React, /// A Leptos component (`view!` markup) with its stylesheet. Leptos, + /// A React function component styled with Tailwind CSS v4 utilities (no stylesheet). + Tailwind, SwiftUi, Compose, } impl CodeLang { - pub const ALL: [CodeLang; 6] = [CodeLang::Css, CodeLang::Html, CodeLang::React, CodeLang::Leptos, CodeLang::SwiftUi, CodeLang::Compose]; + pub const ALL: [CodeLang; 7] = + [CodeLang::Css, CodeLang::Html, CodeLang::React, CodeLang::Leptos, CodeLang::Tailwind, CodeLang::SwiftUi, CodeLang::Compose]; pub fn id(self) -> &'static str { match self { CodeLang::Css => "css", CodeLang::Html => "html", CodeLang::React => "react", CodeLang::Leptos => "leptos", + CodeLang::Tailwind => "tailwind", CodeLang::SwiftUi => "swiftui", CodeLang::Compose => "compose", } @@ -83,13 +94,14 @@ impl CodeLang { CodeLang::Html => "HTML + CSS", CodeLang::React => "React", CodeLang::Leptos => "Leptos", + CodeLang::Tailwind => "React + Tailwind", CodeLang::SwiftUi => "SwiftUI", CodeLang::Compose => "Compose", } } /// Languages whose lengths are CSS pixels (they can be shown in rem). pub fn is_web(self) -> bool { - matches!(self, CodeLang::Css | CodeLang::Html | CodeLang::React | CodeLang::Leptos) + matches!(self, CodeLang::Css | CodeLang::Html | CodeLang::React | CodeLang::Leptos | CodeLang::Tailwind) } pub fn from_id(s: &str) -> Option { if s.eq_ignore_ascii_case("tsx") || s.eq_ignore_ascii_case("jsx") { @@ -194,6 +206,7 @@ pub fn code_for(doc: &Document, id: NodeId, lang: CodeLang) -> String { match lang { CodeLang::Css => css(doc, id), CodeLang::Html => html(doc, id), + CodeLang::Tailwind => crate::tailwind::code(doc, id, None), CodeLang::React | CodeLang::Leptos | CodeLang::SwiftUi | CodeLang::Compose => crate::component_codegen::code(doc, id, lang), } } @@ -316,25 +329,32 @@ pub(crate) fn indent(depth: usize) -> String { /// The CSS custom properties generated code uses: name → fallback value, in first-use order. #[derive(Default)] -pub(crate) struct Tokens(pub Vec<(String, String)>); +pub(crate) struct Tokens { + vars: Vec<(String, String)>, + /// Name variables as Tailwind theme variables (`--color-accent`), not by their CSS name. + pub tailwind: bool, + /// The file's theme names (computed on first use). + theme: Option, +} impl Tokens { /// `var(--name, value)`, remembering the variable. - fn var(&mut self, variable: &Variable, value: String) -> String { - let name = css_var_of(variable); + fn var(&mut self, doc: &Document, variable: &Variable, value: String) -> String { + let name = + if self.tailwind { self.theme.get_or_insert_with(|| crate::tailwind::Theme::new(doc)).name(variable) } else { css_var_of(variable) }; let out = format!("var({name}, {value})"); - if !self.0.iter().any(|(n, _)| *n == name) { - self.0.push((name, value)); + if !self.vars.iter().any(|(n, _)| *n == name) { + self.vars.push((name, value)); } out } /// A `:root` rule declaring the variables (empty without any). pub fn root_rule(&self) -> String { - if self.0.is_empty() { + if self.vars.is_empty() { return String::new(); } - let decls: String = self.0.iter().map(|(n, v)| format!(" {n}: {v};\n")).collect(); + let decls: String = self.vars.iter().map(|(n, v)| format!(" {n}: {v};\n")).collect(); format!(":root {{\n{decls}}}\n") } } @@ -365,7 +385,7 @@ pub fn css_var_of(v: &Variable) -> String { /// `value`, or a reference to the variable bound to the first of `fields` that has one. fn tok(doc: &Document, n: &Node, fields: &[&str], value: String, t: &mut Tokens) -> String { match fields.iter().find_map(|f| crate::devinspect::bound_variable(doc, n, f)) { - Some(v) => t.var(v, value), + Some(v) => t.var(doc, v, value), None => value, } } @@ -659,6 +679,14 @@ pub(crate) struct Markup<'c, 'a> { /// Each layer's path in the tree (names with sibling counts), class and declarations, so /// variants can be compared layer by layer. pub rules: Vec<(String, String, String)>, + /// Instances as their own (overridden) layers instead of component calls, except those + /// connected to code (page code). + pub inline: bool, + /// Auto layout frames and text as fluid boxes (`width: 100%` up to their width) for pages. + pub fluid: bool, + /// With `fluid`, other layers at least this share of the root's width are fluid too (a + /// divider, a banner image); smaller ones (icons) keep their size. Default: none. + pub fluid_leaves: f64, } impl<'c, 'a> Markup<'c, 'a> { @@ -673,6 +701,9 @@ impl<'c, 'a> Markup<'c, 'a> { root_class: None, root_attrs: String::new(), rules: Vec::new(), + inline: false, + fluid: false, + fluid_leaves: f64::INFINITY, } } @@ -754,7 +785,10 @@ impl<'c, 'a> Markup<'c, 'a> { } } // Nested instances are calls (component code), in a wrapper that places them when needed. - if self.code() && !root && matches!(n.kind, NodeKind::Instance { .. }) { + // Page code inlines instances, except those connected to code (codeConnect.set): their + // snippet, e.g. a design-system `"}), + ); + let p = idv(&ex(&mut s, "frame.create", json!({"x": 0, "y": 300, "width": 1440, "height": 400, "name": "Landing"}))); + ex(&mut s, "layout.add", json!({"ids": [p], "direction": "vertical"})); + for text in ["Agendar diagnóstico", "Ver exemplos"] { + let i = idv(&ex(&mut s, "instance.create", json!({"component": comp, "x": 0, "y": 0, "parent": p}))); + ex(&mut s, "instance.setProperties", json!({"id": i, "properties": {"Label": text}})); + } + let out = code(&mut s, p, json!({})); + assert_eq!(out.matches("import { Button } from \"@/components/ui/button\";").count(), 1, "{out}"); + assert!(out.contains("`, with each import once at the top. A design + system mapped to shadcn/ui this way exports pages that use the project's own components. Bound variables become theme + utilities (`bg-accent`, `rounded-card`, `text-muted`) that `variable.export {format: "tailwind"}` + declares: `@import "tailwindcss";` and an `@theme` block named by namespace (`--color-*`, + `--radius-*`, `--text-*`, `--spacing-*`, `--font-*`; a number's namespace and unit come from what + layers bind it to), other modes on `[data-=""]`. With `mobile: ` (the + same layer names, mobile layout) the code is mobile first: the mobile frame's classes, the + desktop frame's that differ behind `lg:`, and layers only on desktop `hidden` plus `lg:flex` + (auto layout frames) or `lg:block` (other layers). - **Component code:** `inspect.code {id, language: react|leptos|swiftui|compose}` on a component, a component set or a variant writes the component as a reusable unit: React (TSX) with a props interface, Leptos with a `#[component]` function (`#[prop]` defaults, `view!` markup), SwiftUI From f0e75e183b86b31c16334aea39be2fd9e98768dd Mon Sep 17 00:00:00 2001 From: Ridzzz0Alam Date: Wed, 21 Oct 2026 21:06:59 +0200 Subject: [PATCH 08/50] M1: swap defaults past the layer cap say so (#981) Instance swap defaults that name an in-file main skipped by the layer cap were reported as "isn't in the file": only instance targets fed the capped-mains list. Defaults now feed it too. --- crates/format/src/fig/layer_cap_tests.rs | 21 +++++++++++++++++++++ crates/format/src/fig/map.rs | 21 +++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/crates/format/src/fig/layer_cap_tests.rs b/crates/format/src/fig/layer_cap_tests.rs index 6eeb15f4..2c562ba7 100644 --- a/crates/format/src/fig/layer_cap_tests.rs +++ b/crates/format/src/fig/layer_cap_tests.rs @@ -103,6 +103,27 @@ fn instances_of_a_main_the_cap_kept_out_say_so() { assert!(!doc.nodes().any(|n| n.name == "Local main")); } +#[test] +fn swap_defaults_the_cap_kept_out_say_so() { + // A kept main's instance swap default names a main with no instances, which comes after + // enough layers to be skipped at the cap. + let swap = o(vec![ + ("id", g(70)), + ("name", Kv::Str("Icon".into())), + ("type", Kv::Enum("INSTANCE_SWAP")), + ("initialValue", o(vec![("guidValue", g(900))])), + ]); + let mut nodes = vec![node(1, None, "DOCUMENT", "Document", vec![]), node(2, Some(1), "CANVAS", "Page", vec![])]; + nodes.push(node(50, Some(2), "SYMBOL", "Card", vec![("size", xy(10.0, 10.0)), ("componentPropDefs", Kv::Array(vec![swap]))])); + nodes.extend(main(60, 2, "Filler", 40)); + nodes.extend(main(900, 2, "Icon main", 10)); + let (doc, warnings) = import_at(&o(vec![("nodeChanges", Kv::Array(nodes))]), 30); + assert!(doc.nodes().any(|n| n.name == "Card")); + assert!(!doc.nodes().any(|n| n.name == "Icon main")); + assert!(warnings.iter().any(|w| w.starts_with("instance swap properties whose default component was past the layer limit")), "{warnings:?}"); + assert!(!warnings.iter().any(|w| w.contains("isn't in the file")), "{warnings:?}"); +} + #[test] fn a_whole_file_past_the_cap_keeps_its_library_links_and_says_so_once() { // A 1 001-layer library main used 210 times: about 210 000 layers in a file far too small to diff --git a/crates/format/src/fig/map.rs b/crates/format/src/fig/map.rs index 7eb974da..b18f8a2b 100644 --- a/crates/format/src/fig/map.rs +++ b/crates/format/src/fig/map.rs @@ -45,7 +45,7 @@ pub(super) fn to_rest(msg: &Kv, name: &str, max_nodes: usize) -> (Value, Vec= m.max_nodes { - let capped: Vec = m.instance_mains.difference(&m.mapped_mains).map(|id| json!(id)).collect(); + let capped: Vec = m.referenced_mains.difference(&m.mapped_mains).map(|id| json!(id)).collect(); if !capped.is_empty() { out[crate::rest::FIG_CAPPED_MAINS_FIELD] = Value::Array(capped); } @@ -397,9 +397,9 @@ struct Mapper<'a> { library_scan_count: usize, warnings: Vec, count: usize, - /// The mains in the file that instances name, and the mains mapped as layers: the difference - /// is what the layer cap kept out. - instance_mains: BTreeSet, + /// The mains in the file that instances or instance swap defaults name, and the mains mapped + /// as layers: the difference is what the layer cap kept out. + referenced_mains: BTreeSet, mapped_mains: BTreeSet, /// Most layers produced or scanned, instance expansion included; the one place the cap comes /// from (see [`super::layer_budget`]). @@ -478,7 +478,7 @@ impl<'a> Mapper<'a> { library_scan_count: 0, warnings: Vec::new(), count: 0, - instance_mains: BTreeSet::new(), + referenced_mains: BTreeSet::new(), mapped_mains: BTreeSet::new(), max_nodes, networks: Vec::new(), @@ -1869,7 +1869,12 @@ impl<'a> Mapper<'a> { "BOOL" => json!({"type": "BOOLEAN", "defaultValue": init.and_then(|i| i.get("boolValue")).and_then(Kv::bool).unwrap_or(true)}), "TEXT" => json!({"type": "TEXT", "defaultValue": init.and_then(prop_text).unwrap_or("")}), "INSTANCE_SWAP" => match init.and_then(|i| i.get("guidValue")).and_then(guid) { - Some(g) => json!({"type": "INSTANCE_SWAP", "defaultValue": g}), + Some(g) => { + if self.nodes.contains_key(&g) { + self.referenced_mains.insert(g.clone()); + } + json!({"type": "INSTANCE_SWAP", "defaultValue": g}) + } None => continue, }, "VARIANT" => json!({"type": "VARIANT"}), @@ -2013,8 +2018,8 @@ impl<'a> Mapper<'a> { self.warn("instances of components that aren't in the file show no layers"); return None; } - if !self.instance_mains.contains(&sym) { - self.instance_mains.insert(sym.clone()); + if !self.referenced_mains.contains(&sym) { + self.referenced_mains.insert(sym.clone()); } if outer.is_some_and(|i| i.symbols.contains(&sym)) { return None; From 9f2470b5bd132ac0fb889b21fbf8cdb4726b5f2e Mon Sep 17 00:00:00 2001 From: vetlucasmartins Date: Wed, 21 Oct 2026 21:00:02 +0100 Subject: [PATCH 09/50] Tailwind theme names: resolve collisions in linear time Clash detection compared every variable with every other, and suffixes rescanned the taken list, so a file with very many variables made the export quadratic. Counts in a HashMap, taken names in a HashSet and a next suffix per base keep it linear. --- crates/engine/src/tailwind.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/tailwind.rs b/crates/engine/src/tailwind.rs index 7f54c8aa..2a6453e4 100644 --- a/crates/engine/src/tailwind.rs +++ b/crates/engine/src/tailwind.rs @@ -32,14 +32,30 @@ impl Theme { let mut t = Theme { roles, names: HashMap::new() }; // Short names ("accent") where they are unique, the full path ("palette-accent") where two // variables would share one, and a numeric suffix as a last resort. - let short: Vec<(VariableId, String)> = vars.iter().map(|v| (v.id.clone(), t.candidate(v, false))).collect(); - let mut taken: Vec = Vec::new(); - for (v, (id, s)) in vars.iter().zip(&short) { - let clash = short.iter().any(|(o, n)| o != id && n == s); - let base = if clash { t.candidate(v, true) } else { s.clone() }; - let name = (1..).map(|k| if k == 1 { base.clone() } else { format!("{base}-{k}") }).find(|n| !taken.contains(n)).unwrap_or(base); - taken.push(name.clone()); - t.names.insert(id.clone(), name); + let short: Vec = vars.iter().map(|v| t.candidate(v, false)).collect(); + // Linear in the number of variables: counts for clashes, a set of names taken and the next + // suffix per base, so a file with very many variables can't make this quadratic. + let mut count: HashMap<&str, usize> = HashMap::new(); + for n in &short { + *count.entry(n.as_str()).or_default() += 1; + } + let mut taken: std::collections::HashSet = std::collections::HashSet::new(); + let mut next: HashMap = HashMap::new(); + for (v, s) in vars.iter().zip(&short) { + let base = if count.get(s.as_str()).copied().unwrap_or(0) > 1 { t.candidate(v, true) } else { s.clone() }; + let mut name = base.clone(); + if taken.contains(&name) { + let k = next.entry(base.clone()).or_insert(1); + loop { + *k += 1; + name = format!("{base}-{k}"); + if !taken.contains(&name) { + break; + } + } + } + taken.insert(name.clone()); + t.names.insert(v.id.clone(), name); } t } From 82b05803b18f6ebfd38e423aabf90b95cc4995f1 Mon Sep 17 00:00:00 2001 From: Ridzzz0Alam Date: Wed, 21 Oct 2026 22:48:51 +0200 Subject: [PATCH 10/50] M1: a refused browser download keeps the unsaved changes (#969) `file.saveAs {data: true}` marked the file saved before the UI handed the bytes to `Services::download`. When the download was refused, the toast said "Couldn't download" but the document was clean, so closing it no longer warned and the edits could be lost. The data result now leaves the save state alone. A new `file.markSaved` (the bookkeeping a native save already did: the file and its branch tabs) runs from `save_as_dialog` only once the download was delivered. It ends a version preview like the other commands that act on the document itself. Tests: the engine save test checks the file stays dirty until `file.markSaved`; `a_refused_download_says_so` checks the document is still dirty. --- crates/engine/src/cmd/file.rs | 39 +++++++++++++++++++--------- crates/engine/src/lib.rs | 3 ++- crates/ui-egui/locales/es.toml | 1 + crates/ui-egui/src/lib.rs | 1 + crates/ui-egui/src/web_save_tests.rs | 1 + 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index d5023372..aa2ea340 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -55,6 +55,13 @@ pub fn specs() -> Vec { false, save_as ), + spec!( + "file.markSaved", + "Mark saved", + "{} clears the unsaved changes of the active tab's file and its branch tabs: run it once the file from `file.saveAs {data: true}` was delivered (a refused download keeps them)", + false, + mark_saved + ), spec!( "file.export", "Export", @@ -869,24 +876,30 @@ fn save_to(s: &mut Session, path: Option) -> Result { Arc::make_mut(&mut snapshot.doc).name = file_stem(path); } let bytes = snapshot.encode()?; - if let Some(path) = &path { - write(path, &bytes)?; - } - ds.doc = snapshot.doc; - if path.is_some() { - ds.path.clone_from(&path); - } - ds.mark_saved(); - ds.revision += 1; - let (uid, name) = (ds.uid, format!("{}.figcraft", ds.doc.name)); - branch_tabs_saved(s, uid); let Some(path) = path else { + // The download can still be refused: the caller marks the file saved once it was delivered. + let name = format!("{}.figcraft", ds.doc.name); return Ok(json!({"name": name, "bytes": bytes.len(), "data": base64::engine::general_purpose::STANDARD.encode(&bytes)})); }; + write(&path, &bytes)?; + ds.doc = snapshot.doc; + ds.path = Some(path.clone()); + mark_saved(s, &json!({}))?; remember(s, &path); Ok(json!({"path": path, "bytes": bytes.len()})) } +/// The file of the active tab (with its branch tabs) now matches what was written or delivered. +fn mark_saved(s: &mut Session, _: &Value) -> Result { + let i = crate::branches::file_tab(s); + let ds = s.docs.get_mut(i).ok_or(EngineError::NoDocument)?; + ds.mark_saved(); + ds.revision += 1; + let uid = ds.uid; + branch_tabs_saved(s, uid); + Ok(json!({"saved": true})) +} + fn save(s: &mut Session, p: &Value) -> Result { if let Some(path) = string(p, "path") { return save_to(s, Some(path)); @@ -1590,7 +1603,7 @@ mod rest_import_tests { } #[test] - fn save_as_data_hands_back_the_file_and_marks_it_saved() { + fn save_as_data_hands_back_the_file_and_marks_it_saved_once_delivered() { // The browser has no paths: Save as returns the file for a download (#969). let mut s = Session::new(); s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap(); @@ -1598,6 +1611,8 @@ mod rest_import_tests { let recent = s.prefs.recent_files.clone(); let r = s.execute("file.saveAs", &json!({"data": true})).unwrap(); assert_eq!(r["name"], "Untitled.figcraft"); + assert!(s.ds().unwrap().is_dirty(), "not delivered yet: a refused download must not lose the edits"); + s.execute("file.markSaved", &json!({})).unwrap(); assert!(!s.ds().unwrap().is_dirty()); assert_eq!(s.ds().unwrap().path, None, "still no path to save over"); assert_eq!(s.prefs.recent_files, recent, "nothing on disk to remember"); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 79e7be0d..e32d7543 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -402,7 +402,8 @@ pub const PREVIEW_READ_ONLY: &str = "you're viewing an earlier version: restore /// Commands that first end a version preview: they act on the document itself. Saving does so /// only with a native destination; export copies and pending format choices keep the preview. -const ENDS_PREVIEW: &[&str] = &["file.save", "file.saveAs", "file.close", "file.revert", "file.saveVersion", "file.duplicate", "version.restore"]; +const ENDS_PREVIEW: &[&str] = + &["file.save", "file.saveAs", "file.markSaved", "file.close", "file.revert", "file.saveVersion", "file.duplicate", "version.restore"]; static NEXT_UID: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1); diff --git a/crates/ui-egui/locales/es.toml b/crates/ui-egui/locales/es.toml index bd572dbe..25f3f258 100644 --- a/crates/ui-egui/locales/es.toml +++ b/crates/ui-egui/locales/es.toml @@ -1920,6 +1920,7 @@ status = "draft — needs native review" "file.revert" = "Volver a lo guardado" "file.save" = "Guardar" "file.saveAs" = "Guardar como" +"file.markSaved" = "Marcar como guardado" "file.saveVersion" = "Guardar en el historial de versiones" "file.versionHistory" = "Mostrar historial de versiones" "fill.add" = "Añadir relleno" diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 788bbf4f..0707723d 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1146,6 +1146,7 @@ impl FigApp { if let Some(r) = self.run("file.saveAs", json!({"data": true})) && self.download(r["name"].as_str().unwrap_or_default(), &r) { + self.run("file.markSaved", json!({})); dialogs::file_saved(self, &r); } return; diff --git a/crates/ui-egui/src/web_save_tests.rs b/crates/ui-egui/src/web_save_tests.rs index 5fbb2524..4879add1 100644 --- a/crates/ui-egui/src/web_save_tests.rs +++ b/crates/ui-egui/src/web_save_tests.rs @@ -52,6 +52,7 @@ fn a_refused_download_says_so() { app.save_as_dialog(); assert_eq!(got.lock().unwrap().len(), 1); assert_eq!(toast(&app), "Couldn't download Untitled.figcraft"); + assert!(app.session.ds().unwrap().is_dirty(), "no file arrived: closing must still warn about the edits"); } #[test] From 85010e491afbb1fd1cbbd94281e7e8a92884015f Mon Sep 17 00:00:00 2001 From: RealtaNua Date: Wed, 21 Oct 2026 09:52:50 +0700 Subject: [PATCH 11/50] M7: missing fonts: follow each font variable's aliases once (#752) A file whose font family variables alias each other in several modes made the missing-fonts walk branch in every mode, billions of steps before the depth limit stopped it, freezing the app on open and `figcraft-cli info`. The walk now visits each variable once. Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/engine/src/fonts.rs | 12 ++++++++---- crates/engine/src/fonts_tests.rs | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/fonts.rs b/crates/engine/src/fonts.rs index 672d4f2c..bdda411c 100644 --- a/crates/engine/src/fonts.rs +++ b/crates/engine/src/fonts.rs @@ -64,16 +64,20 @@ pub fn missing(doc: &Document) -> Vec { used.into_values().filter(|(family, _)| !figcraft_text::has_family(family)).map(|(family, layers)| Missing { family, layers }).collect() } -/// Every string value of variable `id` in any mode, following aliases (at most 32 deep). +/// Every string value of variable `id` in any mode, following aliases (each variable once). fn string_values(vars: &Variables, id: &str) -> Vec { let mut out = Vec::new(); - let mut todo = vec![(id.to_string(), 0)]; - while let Some((id, depth)) = todo.pop() { + let mut seen = BTreeSet::new(); + let mut todo = vec![id.to_string()]; + while let Some(id) = todo.pop() { + if !seen.insert(id.clone()) { + continue; + } let Some(var) = vars.get(&id) else { continue }; for v in var.values.values() { match v { VariableValue::String(s) => out.push(s.clone()), - VariableValue::Alias(a) if depth < 32 => todo.push((a.clone(), depth + 1)), + VariableValue::Alias(a) => todo.push(a.clone()), _ => {} } } diff --git a/crates/engine/src/fonts_tests.rs b/crates/engine/src/fonts_tests.rs index 0fe6dcb3..5df9a854 100644 --- a/crates/engine/src/fonts_tests.rs +++ b/crates/engine/src/fonts_tests.rs @@ -119,6 +119,25 @@ fn blank_families_and_aliases_are_handled() { assert_eq!(families(&mut s), vec![("FigCraft Missing F".to_string(), 1), ("FigCraft Missing G".to_string(), 1)]); } +/// Aliases in several modes are followed once per variable: a chain that branches in every mode +/// would otherwise grow to billions of steps (a file can hold one). +#[test] +fn branching_alias_chains_are_walked_once_per_variable() { + let mut s = Session::new(); + s.execute("variable.createCollection", &json!({"name": "Type"})).unwrap(); + for i in 0..32 { + s.execute("variable.create", &json!({"collection": "Type", "name": format!("V{i}"), "type": "string", "value": "x"})).unwrap(); + } + let doc = s.doc_mut().unwrap(); + let ids: Vec = doc.variables.variables.iter().map(|v| v.id.clone()).collect(); + for (i, var) in doc.variables.variables.iter_mut().enumerate() { + let next = ids.get(i + 1).cloned().unwrap_or_else(|| "FigCraft Missing H".into()); + let leaf = |v: String| if i + 1 < ids.len() { VariableValue::Alias(v) } else { VariableValue::String(v) }; + var.values = [("m1".to_string(), leaf(next.clone())), ("m2".to_string(), leaf(next))].into(); + } + assert_eq!(string_values(&doc.variables, &ids[0]), vec!["FigCraft Missing H", "FigCraft Missing H"]); +} + #[test] fn needs_an_open_document() { let mut s = Session::empty(); From 0f85c2294e4637d2e8b09faea048a8469a382b56 Mon Sep 17 00:00:00 2001 From: F3R9 <214804886+F3R9@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:40:52 +0300 Subject: [PATCH 12/50] M9: avoid read-only snapshot rewrites and duplicate buffers Validated formatting, workspace Clippy, workspace tests excluding the two pre-existing localized startup assertion failures tracked in #1017, layers, assets, WASM and plugins. The startup tests are unchanged in this independent fix. --- ROADMAP.md | 5 +++ apps/figcraft-server/src/disk.rs | 9 +++--- apps/figcraft-server/src/store.rs | 14 ++++++--- apps/figcraft-server/src/store_tests.rs | 41 +++++++++++++++++++++++++ crates/collab/src/codec_tests.rs | 10 ++++++ crates/collab/src/message.rs | 12 +++++--- docs/server-memory-retention.md | 23 ++++++++++++++ 7 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 docs/server-memory-retention.md diff --git a/ROADMAP.md b/ROADMAP.md index f43cd015..cdabaeca 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,5 +1,10 @@ # FigCraft Roadmap +M9 / M7.4 server memory follow-up: read-only disconnects retain their durable client-id journal +without rebuilding the image-bearing snapshot. Snapshot encoding appends into its header buffer, +avoiding a second full payload copy while preserving the existing disk format. See +[`docs/server-memory-retention.md`](docs/server-memory-retention.md). + **Stage: alpha** · next: beta, ~26 points and ~162–292 h away (one Opus 5.5 agent; ~33–67 h wall-clock with 5 agents) > **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-17 · **Change:** minor (community batch #753: Selection colors, smart-selection spacing, a Present tab; language table re-measured from the catalogs; community fixes from #524 up (55 PRs: `.fig` import fidelity, paste from other apps, the Actions palette, editor fixes, server limits) and a boolean-op crash guard; number variables in the text content picker (#629); frames and sections convert into each other (#719); bounded canvas pan overscan; community fixes from #478 up and a control-channel fix (#589); bounded canvas pan overscan; Typography spacing icons support scrubbing (#373); font scans skip named pipes; system theme on first run; recent files as cards with thumbnails on the home screen; community fixes: lost images reported on loading (#207), SVG import budgets (#190), Leptos code (#223), full screen (#227), server snapshots readable again (#188), owner-only preferences (#200), ruzstd 0.9.1 (#182), layer cycle repair (#205), batch rollback, Direct3D 12 on Windows, plugin metering (#192); vector edit mode regions: hover hatch, selection and drag; SVG/PDF exports refuse over-depth documents (#208); bounded MCP/control framing, connections and queues (#201); plugin log limits (#191); live-session revert guard (#198); attached MCP no longer replays after a lost reply (#194); repeat command recursion fix; the Layout panel's constrain-proportions link scales the other side, #220; core editor leftovers: component playground, auto gap handles, variables inside styles, inner shadows and background blur on groups, command-made text readable on dark pages, a one-step frame/group convert, delays on mouse triggers and manual overlay offsets, wrapped-line alignment; `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; starter templates, a Templates tab and Getting started tips on the home screen; your online files; everyday editing partials: number fields, outline options, Hide when publishing, cursors, panel widths, dark pages; sharing with a join code; text box sizes measured against documents re-saved by other software; live sessions per document; .fig export checked by opening written files in other software; a public figcraft-server: open hosting, owner tokens, per-address limits, idle expiry, moderation, install.sh; experimental .fig export; keyboard shortcut parity suite and bindings; Simplified Chinese draft catalog; Latin American Spanish overlay; prototyping tail: gamepad triggers, widgets in prototypes, mode lookups; plugin directory on figcraft-server; Japanese and Korean draft catalogs and CJK UI fonts; plugin widgets and the plugin panel tail; French, German and Brazilian Portuguese draft catalogs; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and edit tail; dev resources links; extended collections tail; branch version history and finer list merges; headline percentages recomputed from the area table: feature breadth ~84%, core ~94%, mainstream ~50%; text lists, hanging punctuation and decoration styles; comments and version history behaviour suite and fixes; canvas navigation, guides and grids behaviour suite and fixes; export and inspect behaviour suite and fixes; .fig import: editable vector networks and more layer kinds; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; styles and variables behaviour suite and fixes; prototyping behaviour suite and fixes; components behaviour suite and fixes; embedded image colour profiles; layers panel keyboard: F2 rename, Shift+F10 context menu, keyboard box selection, 10k-layer QA; per-side stroke weight variables; text behaviour suite: CJK line breaking, metrics, vertical trim; selection and transform behaviour suite and fixes; `.fig` import, best effort; Windows QA pass with eight fixes; auto layout behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; localization layer with a draft Spanish catalog; hosting figcraft-server: wss in the desktop app, server releases, deployment guide; plugin panels and settings; canvas fixes: boolean hit testing on the result, group drags, frame outlines and slices; code connect; stretch and scatter brushes, pen pressure; text on a path and pattern fills; team libraries on the server and swap library; branches: create, update from main, review and merge; animated GIF fills and TIFF images; Open recent, outlines for the selection and mask outlines: menu breadth 100%; extended collections, variables import/export, gradient stop and variant bindings; feature breadth ~80%; ready ~49%) · **Target:** Figma Design (desktop app 126.10.7) diff --git a/apps/figcraft-server/src/disk.rs b/apps/figcraft-server/src/disk.rs index af6e0f99..b0699736 100644 --- a/apps/figcraft-server/src/disk.rs +++ b/apps/figcraft-server/src/disk.rs @@ -127,13 +127,14 @@ fn u64_at(b: &[u8], at: usize) -> Option { /// A snapshot file's bytes. pub fn encode_snapshot(generation: u64, state: &SessionState) -> Result, String> { - let body = message::encode(state).map_err(|e| e.to_string())?; - let mut out = Vec::with_capacity(SNAP_HEADER + body.len()); + let mut out = Vec::with_capacity(SNAP_HEADER); out.extend_from_slice(SNAP_MAGIC); out.push(FORMAT); out.extend_from_slice(&generation.to_le_bytes()); - out.extend_from_slice(&crc(&body).to_le_bytes()); - out.extend_from_slice(&body); + out.extend_from_slice(&0u32.to_le_bytes()); + let mut out = message::encode_into(state, out).map_err(|e| e.to_string())?; + let sum = crc(&out[SNAP_HEADER..]); + out[13..SNAP_HEADER].copy_from_slice(&sum.to_le_bytes()); Ok(out) } diff --git a/apps/figcraft-server/src/store.rs b/apps/figcraft-server/src/store.rs index ea9bc626..1fadf3a1 100644 --- a/apps/figcraft-server/src/store.rs +++ b/apps/figcraft-server/src/store.rs @@ -1385,14 +1385,18 @@ impl Backend for Store { } fn idle(&mut self, file: &str, server: &mut Server) -> bool { - let dirty = self.files.get_mut(file).and_then(|e| e.log.as_mut()).is_some_and(|log| { - let _ = flush_log(file, log); - log.dirty + let compact = self.files.get_mut(file).is_some_and(|entry| { + let snapshot_seq = entry.meta.seq; + entry.log.as_mut().is_some_and(|log| { + // Issued client ids and refusals are durable in the log; only edits need a + // new image-bearing snapshot. Still try a snapshot if syncing the log failed. + flush_log(file, log).is_err() || (log.dirty && server.seq() > snapshot_seq) + }) }); - if dirty { + if compact { self.compact(file, server); } - // It closes anyway, everything in its snapshot: a compaction cut short needs no report. + // It closes anyway, with its state in the snapshot and durable log. self.cut_short.retain(|f| f != file); if let Some(e) = self.files.get_mut(file) { e.log = None; diff --git a/apps/figcraft-server/src/store_tests.rs b/apps/figcraft-server/src/store_tests.rs index f380568c..2bbbaf0e 100644 --- a/apps/figcraft-server/src/store_tests.rs +++ b/apps/figcraft-server/src/store_tests.rs @@ -127,6 +127,34 @@ fn a_file_survives_a_crash_and_compacts() { assert_eq!(store.list(&|_| None)[0].seq, seq, "the description follows"); } +#[test] +fn read_only_sessions_keep_client_ids_without_rewriting_the_snapshot() { + let dir = TempDir::new("read-only-reconnects"); + let c = StoreConfig { compact_after: 1000, ..cfg(dir.path()) }; + let (id, original) = { + let mut store = Store::open(dir.path(), c.clone()).unwrap(); + let (id, _, _) = publish(&mut store, "Read only"); + let bytes = fs::read(dir.path().join(FILES).join(&id).join(SNAPSHOT)).unwrap(); + (id, bytes) + }; + let mut last_client = 0; + for _ in 0..6 { + let mut store = Store::open(dir.path(), c.clone()).unwrap(); + let mut server = store.open(&id).unwrap(); + let client = join(&mut server, Access::View); + assert!(client.id() > last_client, "issued ids survive closing and reopening the store"); + last_client = client.id(); + store.changed(&id, &mut server); + // Idle must sync even if no periodic flush ran before the connection closed. + assert!(store.idle(&id, &mut server)); + assert_eq!(store.compactions(), 0, "a client id does not require rebuilding the image-bearing snapshot"); + assert_eq!(fs::read(dir.path().join(FILES).join(&id).join(SNAPSHOT)).unwrap(), original); + let log = disk::read_log(&fs::read(dir.path().join(FILES).join(&id).join(LOG)).unwrap()).unwrap(); + assert!(!log.entries.is_empty()); + assert_eq!(server.seq(), 0); + } +} + #[test] fn a_long_log_is_compacted_while_open() { let dir = TempDir::new("compact"); @@ -241,6 +269,19 @@ fn temporary_directories_are_removed() { assert!(!path.exists()); } +#[test] +fn snapshot_encoding_keeps_the_existing_framing_and_checksum() { + let state = Server::new(doc("Snapshot framing"), "", figcraft_collab::Limits::default()).state().unwrap(); + let body = figcraft_collab::message::encode(&state).unwrap(); + let mut legacy = b"FCSN\x01".to_vec(); + legacy.extend_from_slice(&37u64.to_le_bytes()); + legacy.extend_from_slice(&crc32fast::hash(&body).to_le_bytes()); + legacy.extend_from_slice(&body); + let encoded = disk::encode_snapshot(37, &state).unwrap(); + assert_eq!(encoded, legacy); + assert_eq!(disk::decode_snapshot(&encoded).unwrap(), (37, state)); +} + #[test] fn random_bytes_never_panic_the_readers() { let mut rng = Rng::new(7); diff --git a/crates/collab/src/codec_tests.rs b/crates/collab/src/codec_tests.rs index 9f5d12fb..30d41490 100644 --- a/crates/collab/src/codec_tests.rs +++ b/crates/collab/src/codec_tests.rs @@ -11,6 +11,16 @@ use crate::message::{ use crate::sim::Rng; use crate::{Error, Replica, diff}; +#[test] +fn encoding_into_a_prefix_keeps_the_wire_body() { + let msg = moved_layer(); + let prefix = b"container header".to_vec(); + let bytes = crate::message::encode_into(&msg, prefix.clone()).unwrap(); + assert_eq!(&bytes[..prefix.len()], prefix); + assert_eq!(&bytes[prefix.len()..], encode(&msg).unwrap()); + assert_eq!(decode::(&bytes[prefix.len()..], bytes.len()).unwrap(), msg); +} + /// A typical edit: one layer dragged (its transform). fn moved_layer() -> ClientMsg { let mut doc = Document::new("f"); diff --git a/crates/collab/src/message.rs b/crates/collab/src/message.rs index 4fda776a..6a1a0e1e 100644 --- a/crates/collab/src/message.rs +++ b/crates/collab/src/message.rs @@ -732,11 +732,13 @@ pub fn utc_date(secs: u64) -> String { /// The binary form of `msg`: [`WIRE_VERSION`], then postcard. pub fn encode(msg: &T) -> Result, Error> { - let body = postcard::to_allocvec(msg).map_err(|e| Error::Encode(e.to_string()))?; - let mut out = Vec::with_capacity(body.len() + 1); - out.push(WIRE_VERSION); - out.extend(body); - Ok(out) + encode_into(msg, Vec::new()) +} + +/// Append the binary form of `msg` to an owned prefix, without a second payload-sized buffer. +pub fn encode_into(msg: &T, mut prefix: Vec) -> Result, Error> { + prefix.push(WIRE_VERSION); + postcard::to_extend(msg, prefix).map_err(|e| Error::Encode(e.to_string())) } /// Read a binary message of at most `max_bytes` (untrusted input: never panics, allocates at most diff --git a/docs/server-memory-retention.md b/docs/server-memory-retention.md new file mode 100644 index 00000000..ef4e0b94 --- /dev/null +++ b/docs/server-memory-retention.md @@ -0,0 +1,23 @@ +# Server memory follow-up + +Joining a persisted session issues a client id and makes its journal dirty, even if nobody edits +the document. Previously, the last client leaving caused a full snapshot rewrite for that id. +For image-heavy documents this creates large temporary allocations and unnecessary disk writes; +an allocator can retain the freed memory after the room closes. + +On idle, the server now flushes the journal and only compacts when the document sequence is newer +than the stored snapshot, or when flushing failed and a snapshot must be attempted as a fallback. +Issued ids and refusals remain durable in the journal. Existing size/count compaction thresholds +remain in effect, and edited documents still compact when the last participant leaves. + +Snapshot encoding also appends the versioned postcard body directly to the snapshot header's +buffer, then fills the checksum. It no longer holds a separate complete encoded body alongside +the finished snapshot. The bytes, generation, checksum and file format are unchanged. + +Regression coverage uses synthetic documents: six read-only sessions across store reopenings +must preserve increasing client ids without rewriting the snapshot; exact legacy framing and +checksum must match; the binary message body must be unchanged when appended to a prefix. +Existing crash recovery, damaged-input and edit compaction tests continue to apply. + +This reduces unnecessary temporary allocations. It does not promise that the operating system +immediately reclaims every freed allocation, or that all large-document memory costs are solved. From 5a3dddc46fe1064b6e2e2b8ff04d220d0c0f9706 Mon Sep 17 00:00:00 2001 From: Gert Pellin Date: Thu, 22 Oct 2026 21:29:58 +0200 Subject: [PATCH 13/50] M9: fall back to the Noto symbol and math fonts on Linux (#1156) Signs such as U+2316 and U+2912 are in no text face. The fallback list had the macOS and Windows symbol fonts (Apple Symbols, Segoe UI Symbol) but nothing a Linux install has, so they drew as empty boxes there even with Noto Sans Symbols 2 or Noto Sans Math installed. Adds Noto Sans Symbols, Noto Sans Symbols 2 (and the Symbols2 spelling some packages use) and Noto Sans Math after them. --- crates/text/src/behaviour_tests.rs | 22 ++++++++++++++++++++++ crates/text/src/fontdb.rs | 10 ++++++++-- crates/text/src/fontdb_tests.rs | 13 +++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/crates/text/src/behaviour_tests.rs b/crates/text/src/behaviour_tests.rs index b3cb4884..95491fed 100644 --- a/crates/text/src/behaviour_tests.rs +++ b/crates/text/src/behaviour_tests.rs @@ -265,6 +265,28 @@ fn hangul_comes_from_a_korean_font_when_one_is_installed() { } } +#[test] +fn symbols_come_from_a_symbol_font_when_one_is_installed() { + // ⌖ (U+2316) and ⤒ (U+2912) are in no Latin text face. With a symbol font that has them (Apple + // Symbols on macOS, Segoe UI Symbol on Windows, Noto Sans Symbols 2 and Noto Sans Math on + // Linux) the fallback draws them instead of the missing-glyph box (#1156). Each character + // skips on a machine with no installed fallback family that has it. + let Some(f) = face() else { return }; + let families = ["Apple Symbols", "Segoe UI Symbol", "Noto Sans Symbols", "Noto Sans Symbols 2", "Noto Sans Math"]; + for c in ['\u{2316}', '\u{2912}'] { + if f.has_char(c) || !families.iter().any(|k| find_face(k, "Regular").is_some_and(|k| k.has_char(c))) { + continue; + } + let t = text(&format!("A {c}"), TextAutoResize::WidthAndHeight); + let l = layout(&t, None, None); + let drawn: Vec<_> = l.glyphs.iter().filter(|g| g.char_start == 2).collect(); + assert!(!drawn.is_empty(), "U+{:04X} has a glyph", c as u32); + for g in drawn { + assert!(g.face.has_char(c), "U+{:04X} drawn by {} {}, which lacks it", c as u32, g.face.family, g.face.style); + } + } +} + #[test] fn break_opportunities() { // (before, after, may break between, derivation) diff --git a/crates/text/src/fontdb.rs b/crates/text/src/fontdb.rs index 604f3eee..c3ae3abd 100644 --- a/crates/text/src/fontdb.rs +++ b/crates/text/src/fontdb.rs @@ -405,8 +405,10 @@ fn names(f: &skrifa::FontRef) -> (Option, Option) { (family, style) } -/// Families tried, in order, for characters a text's own font lacks. -const FALLBACK_FAMILIES: [&str; 20] = [ +/// Families tried, in order, for characters a text's own font lacks. The symbol fonts come last: +/// Apple Symbols (macOS), Segoe UI Symbol (Windows) and the Noto symbol and math fonts (Linux), for +/// signs such as ⌖ and ⤒ that no text face has. +const FALLBACK_FAMILIES: [&str; 24] = [ "Inter", "Helvetica Neue", "Arial", @@ -427,6 +429,10 @@ const FALLBACK_FAMILIES: [&str; 20] = [ "Noto Sans Arabic", "Apple Symbols", "Segoe UI Symbol", + "Noto Sans Symbols", + "Noto Sans Symbols 2", + "Noto Sans Symbols2", + "Noto Sans Math", ]; /// A system font file entry not yet loaded. diff --git a/crates/text/src/fontdb_tests.rs b/crates/text/src/fontdb_tests.rs index f2456d28..f227910e 100644 --- a/crates/text/src/fontdb_tests.rs +++ b/crates/text/src/fontdb_tests.rs @@ -192,6 +192,19 @@ fn fallback_faces_follow_the_runs_style() { } } +#[test] +fn every_platform_has_a_symbol_font_in_the_fallbacks() { + // Symbols such as ⌖ (U+2316) and ⤒ (U+2912) are in no text face (#1156): macOS has Apple + // Symbols, Windows Segoe UI Symbol, and Linux the Noto symbol and math fonts (fontconfig names + // "Noto Sans Symbols 2"; some packages name it "Noto Sans Symbols2"). + for family in ["Apple Symbols", "Segoe UI Symbol", "Noto Sans Symbols", "Noto Sans Symbols 2", "Noto Sans Symbols2", "Noto Sans Math"] { + assert!(FALLBACK_FAMILIES.contains(&family), "{family} is a fallback"); + } + // Text faces come first: a symbol font only draws what they lack. + let at = |f: &str| FALLBACK_FAMILIES.iter().position(|x| *x == f).unwrap(); + assert!(at("Noto Sans") < at("Noto Sans Symbols") && at("DejaVu Sans") < at("Noto Sans Math")); +} + #[cfg(all(unix, not(target_os = "macos")))] #[test] fn user_font_dirs_follow_xdg_data_home() { From c7d2a5f019d0ec8fd1fef01f344ac0b6042b37e8 Mon Sep 17 00:00:00 2001 From: Gert Pellin Date: Thu, 22 Oct 2026 21:46:12 +0200 Subject: [PATCH 14/50] M9: the symbol test also looks for the Noto Sans Symbols2 spelling (#1156) --- crates/text/src/behaviour_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/text/src/behaviour_tests.rs b/crates/text/src/behaviour_tests.rs index 95491fed..4db53184 100644 --- a/crates/text/src/behaviour_tests.rs +++ b/crates/text/src/behaviour_tests.rs @@ -272,7 +272,7 @@ fn symbols_come_from_a_symbol_font_when_one_is_installed() { // Linux) the fallback draws them instead of the missing-glyph box (#1156). Each character // skips on a machine with no installed fallback family that has it. let Some(f) = face() else { return }; - let families = ["Apple Symbols", "Segoe UI Symbol", "Noto Sans Symbols", "Noto Sans Symbols 2", "Noto Sans Math"]; + let families = ["Apple Symbols", "Segoe UI Symbol", "Noto Sans Symbols", "Noto Sans Symbols 2", "Noto Sans Symbols2", "Noto Sans Math"]; for c in ['\u{2316}', '\u{2912}'] { if f.has_char(c) || !families.iter().any(|k| find_face(k, "Regular").is_some_and(|k| k.has_char(c))) { continue; From 6cdc36f6c3672939ee34145455e73dd17479c698 Mon Sep 17 00:00:00 2001 From: saturngod Date: Thu, 22 Oct 2026 16:03:23 -0500 Subject: [PATCH 15/50] Fix stroke-only boolean operand outlines --- crates/render/src/boolean_cache_tests.rs | 100 +++++++++++++++++++++++ crates/render/src/draw.rs | 36 +++++++- 2 files changed, 132 insertions(+), 4 deletions(-) diff --git a/crates/render/src/boolean_cache_tests.rs b/crates/render/src/boolean_cache_tests.rs index 08a89d3a..6e10f746 100644 --- a/crates/render/src/boolean_cache_tests.rs +++ b/crates/render/src/boolean_cache_tests.rs @@ -153,3 +153,103 @@ fn deep_boolean_nesting_stops_at_the_outline_depth_limit() { d.create(inner, NodeKind::Rectangle, "R", 40.0, 10.0, 20.0, 20.0).unwrap(); assert!((outline(&d, b).area().abs() - 2.0 * 20.0 * 20.0).abs() < 0.5); } + +#[test] +fn stroke_only_boolean_operands_keep_their_holes() { + use figcraft_doc::StrokeAlign; + use figcraft_geom::Point; + + for kind in [NodeKind::Polygon { count: 6 }, NodeKind::Rectangle, NodeKind::Line] { + for align in [StrokeAlign::Inside, StrokeAlign::Center, StrokeAlign::Outside] { + let mut d = Document::new("stroke operands"); + let page = d.first_page().unwrap(); + let b = d.create(page, NodeKind::BooleanOp { op: BoolOp::Subtract }, "B", 0.0, 0.0, 100.0, 100.0).unwrap(); + d.get_mut(b).unwrap().fills = vec![Paint::solid(Color::BLACK)]; + // A nested group exercises the same path as a direct operand. + let g = d.create(b, NodeKind::Group, "G", 0.0, 0.0, 100.0, 100.0).unwrap(); + let id = d.create(g, kind.clone(), "stroke", 10.0, 10.0, 80.0, 80.0).unwrap(); + let n = d.get_mut(id).unwrap(); + let mut hidden_fill = Paint::solid(Color::BLACK); + hidden_fill.visible = false; + n.fills = vec![hidden_fill]; + n.strokes = vec![Paint::solid(Color::BLACK)]; + n.stroke.weight = 6.0; + n.stroke.align = align; + let path = outline(&d, b); + assert_eq!(path.winding(Point::new(50.0, 45.0)), 0, "{kind:?} {align:?}: empty interior"); + assert!(path.area().abs() > 100.0, "{kind:?} {align:?}: stroke survives"); + assert!(!dark(&render(&d, page), 50, 45)); + if !matches!(kind, NodeKind::Line) { + // Changing only stroke weight invalidates the boolean result. + let area = path.area().abs(); + d.get_mut(id).unwrap().stroke.weight = 3.0; + assert!(outline(&d, b).area().abs() < area); + d.get_mut(id).unwrap().fills[0].visible = true; + assert_ne!(outline(&d, b).winding(Point::new(50.0, 45.0)), 0, "visible fills keep the interior"); + } + } + } +} + +#[test] +fn boolean_operands_preserve_side_borders_and_container_children() { + use figcraft_doc::StrokeAlign; + use figcraft_geom::Point; + for kind in [NodeKind::Rectangle, NodeKind::Frame] { + let mut d = Document::new("borders"); + let page = d.first_page().unwrap(); + let b = d.create(page, NodeKind::BooleanOp { op: BoolOp::Union }, "B", 0.0, 0.0, 100.0, 100.0).unwrap(); + let id = d.create(b, kind.clone(), "operand", 0.0, 0.0, 100.0, 100.0).unwrap(); + let n = d.get_mut(id).unwrap(); + n.fills.clear(); + n.strokes = vec![Paint::solid(Color::BLACK)]; + n.stroke.weight = 8.0; + n.stroke.align = StrokeAlign::Inside; + n.stroke.sides = Some([8.0, 0.0, 0.0, 0.0]); + if matches!(kind, NodeKind::Frame) { + d.create(id, NodeKind::Rectangle, "child", 40.0, 40.0, 20.0, 20.0).unwrap(); + } + let p = outline(&d, b); + assert_ne!(p.winding(Point::new(50.0, 4.0)), 0, "top border"); + assert_eq!(p.winding(Point::new(98.0, 50.0)), 0, "no right border"); + assert_eq!(p.winding(Point::new(50.0, 98.0)), 0, "no bottom border"); + if matches!(kind, NodeKind::Frame) { + assert_ne!(p.winding(Point::new(50.0, 50.0)), 0, "child retained"); + } + d.get_mut(id).unwrap().stroke.sides = Some([0.0, 8.0, 0.0, 0.0]); + let p = outline(&d, b); + assert_eq!(p.winding(Point::new(50.0, 4.0)), 0, "side edit removes top"); + assert_ne!(p.winding(Point::new(98.0, 50.0)), 0, "side edit adds right"); + d.get_mut(id).unwrap().stroke.sides = None; + assert_ne!(outline(&d, b).winding(Point::new(50.0, 4.0)), 0, "uniform container border"); + } +} + +#[test] +fn stroke_only_text_operands_use_glyphs_instead_of_the_text_box() { + use figcraft_doc::{StrokeAlign, TextData}; + let mut d = Document::new("text strokes"); + let page = d.first_page().unwrap(); + let b = d.create(page, NodeKind::BooleanOp { op: BoolOp::Union }, "B", 0.0, 0.0, 400.0, 100.0).unwrap(); + let mut text = TextData::new("Hi"); + text.style.font_size = 32.0; + let id = d.create(b, NodeKind::Text(text), "text", 0.0, 0.0, 400.0, 100.0).unwrap(); + let n = d.get_mut(id).unwrap(); + n.fills.clear(); + n.strokes = vec![Paint::solid(Color::BLACK)]; + n.stroke.weight = 2.0; + n.stroke.align = StrokeAlign::Center; + let glyphs = outline(&d, id); + let result = outline(&d, b); + assert_eq!(result.elements().is_empty(), glyphs.elements().is_empty()); + if !glyphs.elements().is_empty() { + let expected = glyphs.bounding_box().inflate(3.0, 3.0); + let actual = result.bounding_box(); + assert!(actual.x0 >= expected.x0 && actual.x1 <= expected.x1); + assert!(actual.y0 >= expected.y0 && actual.y1 <= expected.y1); + assert!(actual.x1 < 200.0, "the unused text box must not contribute a border"); + } + let NodeKind::Text(text) = &mut d.get_mut(id).unwrap().kind else { panic!() }; + text.characters = " ".into(); + assert!(outline(&d, b).elements().is_empty(), "spaces have no stroked glyphs"); +} diff --git a/crates/render/src/draw.rs b/crates/render/src/draw.rs index 63b38220..a80cd063 100644 --- a/crates/render/src/draw.rs +++ b/crates/render/src/draw.rs @@ -205,6 +205,18 @@ pub fn stroke_area(n: &Node, path: &BezPath, closed: bool) -> Arc { return Arc::new(o); } } + cached_stroke_outline(n, path, closed) +} + +/// A non-zero stroke outline, shared by painting and boolean operands. +fn cached_stroke_outline(n: &Node, path: &BezPath, closed: bool) -> Arc { + let props = &n.stroke; + if let Some(sides) = props.sides + && matches!(n.kind, NodeKind::Rectangle | NodeKind::Frame | NodeKind::Component { .. } | NodeKind::Instance { .. }) + && n.corners.uniform() == Some(0.0) + { + return Arc::new(figcraft_pathops::rect_side_strokes(n.width, n.height, sides, props.align)); + } let mut h = std::collections::hash_map::DefaultHasher::new(); hash_path(path, &mut h); (props.weight.to_bits(), props.align as u8, props.cap_start as u8, props.cap_end as u8, props.join as u8, props.miter_limit.to_bits(), closed) @@ -276,7 +288,7 @@ fn node_outline_at(doc: &Document, n: &Node, depth: usize) -> Option<(BezPath, F .filter_map(|c| doc.node(*c)) .filter(|c| c.visible) .filter_map(|c| { - let (mut p, _) = subtree_outline(doc, c, depth + 1)?; + let (mut p, _) = subtree_outline_at(doc, c, depth + 1, true)?; p.apply_affine(c.transform); Some((p, c.bool_op.unwrap_or(*op))) }) @@ -300,6 +312,11 @@ fn node_outline_at(doc: &Document, n: &Node, depth: usize) -> Option<(BezPath, F /// The union outline of a node and its descendants (for booleans of groups/frames). pub fn subtree_outline(doc: &Document, n: &Node, depth: usize) -> Option<(BezPath, FillRule)> { + subtree_outline_at(doc, n, depth, false) +} + +/// Boolean operands with only a stroke contribute the painted band, not their interior. +fn subtree_outline_at(doc: &Document, n: &Node, depth: usize, stroke_only: bool) -> Option<(BezPath, FillRule)> { if depth > 64 { return None; } @@ -308,21 +325,32 @@ pub fn subtree_outline(doc: &Document, n: &Node, depth: usize) -> Option<(BezPat let mut out = BezPath::new(); if n.kind.is_frame_like() && let Some(p) = figcraft_doc::geometry::shape_path(n) - && n.fills.iter().any(|f| f.visible) { - out.extend(p.elements().iter().copied()); + if n.fills.iter().any(|f| f.visible) { + out.extend(p.elements().iter().copied()); + } else if stroke_only && n.has_visible_stroke() { + out.extend(cached_stroke_outline(n, &p, true).elements().iter().copied()); + } } for c in n.children.iter().filter_map(|c| doc.node(*c)) { if !c.visible { continue; } - if let Some((mut p, _)) = subtree_outline(doc, c, depth + 1) { + if let Some((mut p, _)) = subtree_outline_at(doc, c, depth + 1, stroke_only) { p.apply_affine(c.transform); out.extend(p.elements().iter().copied()); } } Some((out, FillRule::Winding)) } + _ if stroke_only && !n.fills.iter().any(|p| p.visible) && n.has_visible_stroke() => { + let (path, _) = node_outline_at(doc, n, depth)?; + let path = if matches!(n.kind, NodeKind::Text(_)) { path } else { figcraft_doc::geometry::stroke_geometry(n).unwrap_or(path) }; + let closed = figcraft_doc::geometry::is_closed(n) || matches!(n.kind, NodeKind::BooleanOp { .. }); + // Boolean folding uses non-zero winding; the canvas stroke cache also contains + // even-odd rectangle rings, so use the winding-correct stroke outline here. + Some(((*cached_stroke_outline(n, &path, closed)).clone(), FillRule::Winding)) + } _ => node_outline_at(doc, n, depth), } } From 7a2568fe55a26fd609dc4335343162e16f498187 Mon Sep 17 00:00:00 2001 From: vetlucasmartins Date: Sat, 24 Oct 2026 00:50:53 +0100 Subject: [PATCH 16/50] tailwind: emit @theme static; fix assertion precedence in tests Tailwind v4 drops theme variables no utility uses, but page code also reads tokens through var() and (--name) utilities, so the export keeps them all. Two test assertions mixed && and || without parentheses. --- crates/engine/src/cmd/variables_io.rs | 4 +++- crates/engine/src/tailwind_tests.rs | 6 +++--- docs/mcp.md | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/variables_io.rs b/crates/engine/src/cmd/variables_io.rs index c74c46fe..eee312c2 100644 --- a/crates/engine/src/cmd/variables_io.rs +++ b/crates/engine/src/cmd/variables_io.rs @@ -80,7 +80,9 @@ fn css(doc: &Document, colls: &[&Collection], tailwind: bool) -> String { let attr = css_var_name(&c.name); for (i, m) in c.modes.iter().enumerate() { let sel = match i { - 0 if tailwind => "@theme".to_string(), + // `static`: Tailwind otherwise drops theme variables no utility uses, and pages also + // read them through `var()` and `(--name)` utilities. + 0 if tailwind => "@theme static".to_string(), 0 => ":root".to_string(), _ => format!("[data-{}=\"{}\"]", attr.trim_start_matches('-'), css_safe(&m.name)), }; diff --git a/crates/engine/src/tailwind_tests.rs b/crates/engine/src/tailwind_tests.rs index 615a6cec..3080a15d 100644 --- a/crates/engine/src/tailwind_tests.rs +++ b/crates/engine/src/tailwind_tests.rs @@ -66,7 +66,7 @@ fn per_side_strokes_are_borders_on_those_sides() { let css = ex(&mut s, "inspect.code", json!({"id": f, "language": "css"}))["code"].as_str().unwrap_or_default().to_string(); assert!(css.contains("border-bottom: 1px solid") && !css.contains("border:"), "{css}"); let tw = code(&mut s, f, json!({})); - assert!(tw.contains("border-b ") && tw.contains("border-[#262a31]") || tw.contains("border-[#262A31]"), "{tw}"); + assert!(tw.contains("border-b ") && (tw.contains("border-[#262a31]") || tw.contains("border-[#262A31]")), "{tw}"); // Without per-side weights it is one border. ex(&mut s, "node.set", json!({"id": f, "props": {"strokeSides": null, "strokeWeight": 2}})); let css = ex(&mut s, "inspect.code", json!({"id": f, "language": "css"}))["code"].as_str().unwrap_or_default().to_string(); @@ -140,7 +140,7 @@ fn variables_export_with_units_and_as_a_tailwind_theme() { let css = ex(&mut s, "variable.export", json!({"format": "css"}))["text"].as_str().unwrap_or_default().to_string(); assert!(css.contains("--card: 12px;") && css.contains("--fade: 0.5;"), "{css}"); let tw = ex(&mut s, "variable.export", json!({"format": "tailwind"}))["text"].as_str().unwrap_or_default().to_string(); - for want in ["@import \"tailwindcss\";", "@theme {", "--color-accent: #3ddc97;", "--radius-card: 12px;", "--fade: 0.5;"] { + for want in ["@import \"tailwindcss\";", "@theme static {", "--color-accent: #3ddc97;", "--radius-card: 12px;", "--fade: 0.5;"] { assert!(tw.to_lowercase().contains(&want.to_lowercase()), "{want} in {tw}"); } } @@ -192,7 +192,7 @@ fn slashed_layer_names_and_phone_widths_merge_right() { assert!(button.contains("self-stretch") && button.contains("lg:self-auto"), "the slashed name keeps its mobile classes: {out}"); assert!(!out.contains("max-w-[342px] ") || out.contains("lg:max-w-[342px]"), "no phone-width cap below lg: {out}"); assert!(out.contains("Only in the mobile frame") && out.contains("Tag"), "{out}"); - let divider = out.lines().filter(|l| l.contains("{"See examples"}`, with each import once at the top. A design system mapped to shadcn/ui this way exports pages that use the project's own components. Bound variables become theme utilities (`bg-accent`, `rounded-card`, `text-muted`) that `variable.export {format: "tailwind"}` - declares: `@import "tailwindcss";` and an `@theme` block named by namespace (`--color-*`, + declares: `@import "tailwindcss";` and an `@theme static` block (every token is emitted, also those only read through `var()`) named by namespace (`--color-*`, `--radius-*`, `--text-*`, `--spacing-*`, `--font-*`; a number's namespace and unit come from what layers bind it to), other modes on `[data-=""]`. With `mobile: ` (the same layer names, mobile layout) the code is mobile first: the mobile frame's classes, the From 9361b230b55773782141151ee4f8d2030c7073ff Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 24 Oct 2026 12:57:43 +0700 Subject: [PATCH 17/50] #1011: explicit imports, a method reference --- crates/engine/src/tailwind.rs | 4 ++-- crates/engine/src/tailwind_tests.rs | 2 +- crates/engine/src/token_roles.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/tailwind.rs b/crates/engine/src/tailwind.rs index 2a6453e4..d52aa29c 100644 --- a/crates/engine/src/tailwind.rs +++ b/crates/engine/src/tailwind.rs @@ -7,7 +7,7 @@ use std::collections::{BTreeMap, HashMap}; -use figcraft_doc::*; +use figcraft_doc::{Document, NodeId, NodeKind, Variable, VariableId, VariableType}; use crate::codegen::{CodeLang, Ctx, Markup, css_var_name, css_var_of, num}; use crate::component_codegen::component_type_name; @@ -454,7 +454,7 @@ pub fn code(doc: &Document, id: NodeId, mobile: Option) -> String { // ponytail: layers only on mobile are listed, not merged in; their place in the tree is ambiguous. let only_mobile: Vec = small .iter() - .flat_map(|m| m.keys()) + .flat_map(BTreeMap::keys) .filter(|p| !rules.iter().any(|(d, _, _)| d == *p)) .map(|p| p.trim_start_matches('/').split('/').map(|seg| seg.rsplit_once('#').map_or(seg, |(n, _)| n)).collect::>().join(" › ")) .take(20) diff --git a/crates/engine/src/tailwind_tests.rs b/crates/engine/src/tailwind_tests.rs index 3080a15d..224c4928 100644 --- a/crates/engine/src/tailwind_tests.rs +++ b/crates/engine/src/tailwind_tests.rs @@ -5,7 +5,7 @@ use crate::Session; use crate::components::tests::{ex, idv}; use crate::tailwind::{classes, merge}; -use figcraft_doc::*; +use figcraft_doc::NodeId; use serde_json::json; fn code(s: &mut Session, id: NodeId, extra: serde_json::Value) -> String { diff --git a/crates/engine/src/token_roles.rs b/crates/engine/src/token_roles.rs index dc609640..3827ecbe 100644 --- a/crates/engine/src/token_roles.rs +++ b/crates/engine/src/token_roles.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; -use figcraft_doc::*; +use figcraft_doc::{Document, Variable, VariableId, VariableType, VariableValue}; use crate::codegen::num; From 647e5f17d905fa4f84032e9202afc46085c1e71c Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 24 Oct 2026 12:57:52 +0700 Subject: [PATCH 18/50] #1011: single-call Tailwind variables, rem only where it converts --- crates/engine/src/codegen.rs | 5 +++-- crates/engine/src/tailwind.rs | 15 ++++++++++++++- crates/engine/src/tailwind_tests.rs | 7 +++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/codegen.rs b/crates/engine/src/codegen.rs index c0b8e891..18db85c8 100644 --- a/crates/engine/src/codegen.rs +++ b/crates/engine/src/codegen.rs @@ -99,9 +99,10 @@ impl CodeLang { CodeLang::Compose => "Compose", } } - /// Languages whose lengths are CSS pixels (they can be shown in rem). + /// Languages whose lengths are CSS pixels that can be shown in rem (not Tailwind: its lengths + /// are utility classes). pub fn is_web(self) -> bool { - matches!(self, CodeLang::Css | CodeLang::Html | CodeLang::React | CodeLang::Leptos | CodeLang::Tailwind) + matches!(self, CodeLang::Css | CodeLang::Html | CodeLang::React | CodeLang::Leptos) } pub fn from_id(s: &str) -> Option { if s.eq_ignore_ascii_case("tsx") || s.eq_ignore_ascii_case("jsx") { diff --git a/crates/engine/src/tailwind.rs b/crates/engine/src/tailwind.rs index d52aa29c..70a562a9 100644 --- a/crates/engine/src/tailwind.rs +++ b/crates/engine/src/tailwind.rs @@ -105,9 +105,22 @@ fn arb(v: &str) -> String { format!("[{}]", v.trim().replace('_', "\\_").replace(' ', "_")) } -/// The custom property a `var(--name, fallback)` value reads. +/// The custom property a `var(--name, fallback)` value reads, when that one call is the whole +/// value (not `var(--a, 4px) 8px`, four corners of which only the first is a variable). fn var_name(v: &str) -> Option<&str> { let inner = v.trim().strip_prefix("var(")?; + let mut depth = 1usize; + let close = inner.char_indices().find_map(|(i, c)| { + match c { + '(' => depth += 1, + ')' => depth -= 1, + _ => {} + } + (depth == 0).then_some(i) + })?; + if close + 1 != inner.len() { + return None; + } Some(inner.split([',', ')']).next()?.trim()) } diff --git a/crates/engine/src/tailwind_tests.rs b/crates/engine/src/tailwind_tests.rs index 224c4928..9e41fecc 100644 --- a/crates/engine/src/tailwind_tests.rs +++ b/crates/engine/src/tailwind_tests.rs @@ -333,3 +333,10 @@ fn review_desktop_without_fill_clears_a_mobile_image_or_gradient() { let got = merge(Some(&[("background".to_string(), "[background:url(image.png)_center_/_cover]".to_string())]), &[]); assert!(got.contains(&"lg:bg-none".to_string()) && got.contains(&"lg:bg-transparent".to_string()), "{got:?}"); } + +#[test] +fn per_corner_radii_with_a_variable_first_keep_every_corner() { + let got: Vec = + classes("border-radius: var(--radius-a, 4px) 8px 8px 8px;\nborder-radius: var(--radius-card, 4px);\n").into_iter().map(|(_, c)| c).collect(); + assert_eq!(got, ["rounded-[var(--radius-a,_4px)_8px_8px_8px]", "rounded-card"]); +} From 9b78ff8c4a17ac78a253ca1545e0d5b48aa2383f Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 24 Oct 2026 13:02:24 +0700 Subject: [PATCH 19/50] #989: explicit imports, the .fig test helper named main_component --- crates/format/src/fig/layer_cap_tests.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/format/src/fig/layer_cap_tests.rs b/crates/format/src/fig/layer_cap_tests.rs index 2c562ba7..e7bb769c 100644 --- a/crates/format/src/fig/layer_cap_tests.rs +++ b/crates/format/src/fig/layer_cap_tests.rs @@ -5,7 +5,7 @@ use figcraft_doc::{Document, NodeKind}; use super::kiwi::{Kv, Schema}; -use super::*; +use super::{MAX_FIG_NODES, export, import, layer_budget, map}; type Fields = Vec<(&'static str, Kv<'static>)>; @@ -36,7 +36,7 @@ fn instance(id: u64, page: u64, main: u64) -> Kv<'static> { } /// A main `id` of `layers` rectangles under `parent`. -fn main(id: u64, parent: u64, name: &str, layers: u64) -> Vec> { +fn main_component(id: u64, parent: u64, name: &str, layers: u64) -> Vec> { let mut out = vec![node(id, Some(parent), "SYMBOL", name, vec![("size", xy(10.0, 10.0))])]; out.extend((1..=layers).map(|i| node(id * 10_000 + i, Some(id), "RECTANGLE", "R", vec![("size", xy(1.0, 1.0))]))); out @@ -50,7 +50,7 @@ fn library_message(count: u64, main_layers: u64) -> Kv<'static> { node(2, Some(1), "CANVAS", "Screens", vec![]), node(3, Some(1), "CANVAS", "Internal", vec![("internalOnly", Kv::Bool(true))]), ]; - nodes.extend(main(20, 3, "Library main", main_layers)); + nodes.extend(main_component(20, 3, "Library main", main_layers)); nodes.extend((0..count).map(|i| instance(1_000 + i, 2, 20))); o(vec![("nodeChanges", Kv::Array(nodes))]) } @@ -96,7 +96,7 @@ fn instances_of_a_main_the_cap_kept_out_say_so() { // file has it. let mut nodes = vec![node(1, None, "DOCUMENT", "Document", vec![]), node(2, Some(1), "CANVAS", "Page", vec![])]; nodes.extend((0..20).map(|i| instance(100 + i, 2, 900))); - nodes.extend(main(900, 2, "Local main", 10)); + nodes.extend(main_component(900, 2, "Local main", 10)); let (doc, warnings) = import_at(&o(vec![("nodeChanges", Kv::Array(nodes))]), 60); assert!(warnings.iter().any(|w| w.starts_with("instances whose component was past the layer limit were imported as frames")), "{warnings:?}"); assert!(!warnings.iter().any(|w| w.contains("aren't in the file")), "{warnings:?}"); @@ -115,8 +115,8 @@ fn swap_defaults_the_cap_kept_out_say_so() { ]); let mut nodes = vec![node(1, None, "DOCUMENT", "Document", vec![]), node(2, Some(1), "CANVAS", "Page", vec![])]; nodes.push(node(50, Some(2), "SYMBOL", "Card", vec![("size", xy(10.0, 10.0)), ("componentPropDefs", Kv::Array(vec![swap]))])); - nodes.extend(main(60, 2, "Filler", 40)); - nodes.extend(main(900, 2, "Icon main", 10)); + nodes.extend(main_component(60, 2, "Filler", 40)); + nodes.extend(main_component(900, 2, "Icon main", 10)); let (doc, warnings) = import_at(&o(vec![("nodeChanges", Kv::Array(nodes))]), 30); assert!(doc.nodes().any(|n| n.name == "Card")); assert!(!doc.nodes().any(|n| n.name == "Icon main")); From b6489aba3bdd6d22d3509e5e563dad45aff1a76e Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 24 Oct 2026 13:02:25 +0700 Subject: [PATCH 20/50] #989: .fig pages keep room for their top-level layers past large library copies --- crates/format/src/fig/layer_cap_tests.rs | 10 ++++++++ crates/format/src/fig/map.rs | 29 +++++++++++++++++------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/crates/format/src/fig/layer_cap_tests.rs b/crates/format/src/fig/layer_cap_tests.rs index e7bb769c..1b869ea2 100644 --- a/crates/format/src/fig/layer_cap_tests.rs +++ b/crates/format/src/fig/layer_cap_tests.rs @@ -136,3 +136,13 @@ fn a_whole_file_past_the_cap_keeps_its_library_links_and_says_so_once() { assert!(!warnings.iter().any(|w| w.contains("aren't in the file")), "{warnings:?}"); assert!(linked_to(&doc, "Library main") >= 190, "{warnings:?}"); } + +#[test] +fn a_library_main_larger_than_the_cap_leaves_the_pages_room() { + // A main of 300 layers with room for 100: mapped first, it took the whole budget and the page + // came out empty. + let (doc, warnings) = import_at(&library_message(5, 300), 100); + let page = doc.nodes().find(|n| n.name == "Screens").expect("the page"); + let top = page.children.len(); + assert!(top >= 1, "the page kept {top} layers: {warnings:?}"); +} diff --git a/crates/format/src/fig/map.rs b/crates/format/src/fig/map.rs index 36348ded..ca491e0b 100644 --- a/crates/format/src/fig/map.rs +++ b/crates/format/src/fig/map.rs @@ -404,6 +404,9 @@ struct Mapper<'a> { /// Most layers produced or scanned, instance expansion included; the one place the cap comes /// from (see [`super::layer_budget`]). max_nodes: usize, + /// Layers kept back for the visible pages' top level while library copies are mapped, so the + /// copies can't take the whole budget and leave the pages empty. + reserved: usize, /// Vector networks, each built once: the layers that show one (every instance of a main /// holding it) name it by `vectorNetworkRef`. Kept out of the JSON, where a large file's /// networks took gigabytes. @@ -481,6 +484,7 @@ impl<'a> Mapper<'a> { referenced_mains: BTreeSet::new(), mapped_mains: BTreeSet::new(), max_nodes, + reserved: 0, networks: Vec::new(), network_ids: HashMap::new(), } @@ -563,6 +567,11 @@ impl<'a> Mapper<'a> { scope } + /// How many layers may be produced now: the cap, less what is kept for the visible pages. + fn budget(&self) -> usize { + self.max_nodes.saturating_sub(self.reserved) + } + /// The DOCUMENT with its pages. fn document(&mut self) -> Value { let doc_id = self.nodes.iter().find(|(_, n)| n.get("type").and_then(Kv::str) == Some("DOCUMENT")).map(|(id, _)| id.clone()); @@ -589,11 +598,15 @@ impl<'a> Mapper<'a> { // last layers are skipped rather than the mains every instance of them needs (#981). let visible_pages: Vec = visible.iter().map(|(p, _)| p.clone()).collect(); let required_mains = self.referenced_component_mains(&visible_pages); + // The pages and their top-level layers, up to half the cap, stay for the pages. + let top: usize = visible_pages.iter().map(|p| 1 + self.children(p).len()).sum(); + self.reserved = top.min(self.max_nodes / 2); for (id, canvas) in internal { if let Some(context) = self.library_context(&id, canvas, &required_mains) { self.library_contexts.push(context); } } + self.reserved = 0; let out: Vec = visible.into_iter().map(|(p, n)| self.page(&p, n)).collect(); if out.is_empty() { self.warn("the file has no pages"); @@ -838,7 +851,7 @@ impl<'a> Mapper<'a> { self.warn(format!("layers nested deeper than {MAX_DEPTH} levels were skipped")); return None; } - if self.count >= self.max_nodes { + if self.count >= self.budget() { let max = self.max_nodes; self.warn(format!("the file has more than {max} layers; the rest were skipped")); return None; @@ -875,7 +888,7 @@ impl<'a> Mapper<'a> { let connector_snapshot = own == "CONNECTOR" && self.connector_snapshot_supported(&view); // Only a connector with a saved label needs the frame wrapper; an unlabelled one stays a single vector. let connector_terminal = - connector_snapshot && (!connector_has_saved_label(&view) || depth >= MAX_DEPTH || self.count.saturating_add(1) >= self.max_nodes); + connector_snapshot && (!connector_has_saved_label(&view) || depth >= MAX_DEPTH || self.count.saturating_add(1) >= self.budget()); // A supported connector snapshot has its own note below instead of the generic stand-in one. let stand = stand_in(own).filter(|_| !connector_snapshot); let ty = match own { @@ -1023,7 +1036,7 @@ impl<'a> Mapper<'a> { fn shape_with_text(&mut self, o: &mut Obj, v: &View<'a>, own: &str, rest_id: &str) -> Option { let shape = v.str("shapeWithTextType").unwrap_or("SQUARE"); let outlined = !v.list("fillGeometry").is_empty() || !v.list("strokeGeometry").is_empty(); - if own != "SHAPE_WITH_TEXT" || matches!(shape, "SQUARE" | "ROUNDED_RECTANGLE") || !outlined || self.count >= self.max_nodes { + if own != "SHAPE_WITH_TEXT" || matches!(shape, "SQUARE" | "ROUNDED_RECTANGLE") || !outlined || self.count >= self.budget() { return None; } let mut s = Obj::new(); @@ -1055,7 +1068,7 @@ impl<'a> Mapper<'a> { /// layer filling it, inset a little; centred unless it's a note. fn inner_text(&mut self, o: &Obj, v: &View<'a>, rest_id: &str, note: bool) -> Option { let chars = own_text(v)?; - if self.count >= self.max_nodes { + if self.count >= self.budget() { return None; } self.count += 1; @@ -1190,7 +1203,7 @@ impl<'a> Mapper<'a> { out.insert("opacity".into(), json!(root_opacity * line_opacity)); } if connector_has_saved_label(v) { - let reason = if self.count >= self.max_nodes { "node budget" } else { "depth limit" }; + let reason = if self.count >= self.budget() { "node budget" } else { "depth limit" }; self.warn(format!("connector label was skipped: {reason} prevents nested snapshot children")); } } @@ -1220,7 +1233,7 @@ impl<'a> Mapper<'a> { /// Snapshot the straight, manual connector contract carried by its generated children. fn connector_snapshot_children(&mut self, v: &View<'a>, rest_id: &str) -> Vec { - if self.count >= self.max_nodes { + if self.count >= self.budget() { self.warn(format!("the file has more than {} layers; connector snapshot children were skipped", self.max_nodes)); return Vec::new(); } @@ -1283,7 +1296,7 @@ impl<'a> Mapper<'a> { }; let background_view = View::of(background).with([background_style]); if !background_view.list("fillPaints").is_empty() { - if self.count >= self.max_nodes { + if self.count >= self.budget() { self.warn(format!("the file has more than {} layers; connector label background was skipped", self.max_nodes)); } else { let mut rect = Obj::new(); @@ -1311,7 +1324,7 @@ impl<'a> Mapper<'a> { transform: Affine, view: &View<'a>, ) { - if self.count >= self.max_nodes { + if self.count >= self.budget() { self.warn(format!("the file has more than {} layers; connector label was skipped", self.max_nodes)); return; } From a6949ec2e9bf2898af8c7f4f0941acce82e63630 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 24 Oct 2026 13:02:34 +0700 Subject: [PATCH 21/50] #1010: a zip export stops at 256 MB of files, which are all in memory at once --- crates/engine/src/cmd/file.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index 53f51cc2..d74b8dae 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -1166,6 +1166,20 @@ fn size_param(cmd: &str, p: &Value) -> Result> { /// Most files one `file.exportLayers` writes. const MAX_EXPORT_FILES: usize = 1000; +/// Most bytes the files of one zip export add up to: the files, the archive and its base64 copy +/// are all in memory at once (in the browser too). +const MAX_ZIP_BYTES: usize = 256 << 20; + +/// Keep `bytes` as zip member `name`, unless the members would pass `limit` bytes together. +fn add_member<'a>(members: &mut Vec<(&'a str, Vec)>, name: &'a str, bytes: Vec, limit: usize) -> Result<()> { + let total = members.iter().map(|(_, b)| b.len()).sum::().saturating_add(bytes.len()); + if total > limit { + let mb = limit >> 20; + return Err(bad("file.exportLayers", format!("the files would pass {mb} MB as one zip: export fewer layers at a time, or to a folder"))); + } + members.push((name, bytes)); + Ok(()) +} /// One file of a layer export: the layer, its setting and the file name. pub struct ExportJob { @@ -1259,7 +1273,7 @@ fn export_layers(s: &mut Session, p: &Value) -> Result { write(&path, &bytes)?; f["path"] = json!(path); } - None if zip => members.push((job.file.as_str(), bytes)), + None if zip => add_member(&mut members, job.file.as_str(), bytes, MAX_ZIP_BYTES)?, None => f["data"] = json!(base64::engine::general_purpose::STANDARD.encode(&bytes)), } files.push(f); @@ -1803,3 +1817,18 @@ mod staging_write_tests { let _ = std::fs::remove_dir_all(&d); } } + +#[cfg(test)] +mod zip_cap_tests { + use super::add_member; + + #[test] + fn zip_members_stop_at_the_limit_and_keep_what_fit() { + let mut members = Vec::new(); + add_member(&mut members, "a.png", vec![0; 6], 10).unwrap(); + add_member(&mut members, "b.png", vec![0; 4], 10).unwrap(); + let err = add_member(&mut members, "c.png", vec![0; 1], 10).unwrap_err().to_string(); + assert!(err.contains("as one zip"), "{err}"); + assert_eq!(members.iter().map(|(n, _)| *n).collect::>(), ["a.png", "b.png"]); + } +} From 494387a6a8754f07d6884e142f76f2c630e99c37 Mon Sep 17 00:00:00 2001 From: Ridzzz0Alam Date: Sat, 24 Oct 2026 12:13:40 +0200 Subject: [PATCH 22/50] M1: a dash pattern too fine for its path strokes solid (#1060) stroke_center handed any dash pattern to kurbo::stroke, which makes one outline per dash: a 0.01/0.01 pattern on a 10,000-unit line made 2.5M path elements, and a long line with a tiny pattern ran out of memory. The variable width stroke already drew solid past MAX_DASHES (20,000); that estimate is now width::dashes_fit and stroke_center uses it too, so both strokes follow one rule. The path length is only measured for dashed strokes. Test: a_dash_pattern_too_fine_for_its_path_strokes_solid (2.5M elements on the old code). --- crates/pathops/src/lib.rs | 15 ++++++++++++++- crates/pathops/src/width.rs | 10 ++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/pathops/src/lib.rs b/crates/pathops/src/lib.rs index f4b30e10..45d5122f 100644 --- a/crates/pathops/src/lib.rs +++ b/crates/pathops/src/lib.rs @@ -292,7 +292,7 @@ pub fn stroke_center(path: &BezPath, width: f64, props: &StrokeProps) -> BezPath .with_miter_limit(props.miter_limit.clamp(1.0, 100.0)) .with_start_cap(kcap(props.cap_start)) .with_end_cap(kcap(props.cap_end)); - if let Some(pat) = width::dash_pattern(props) { + if let Some(pat) = width::dash_pattern(props).filter(|p| width::dashes_fit(path.perimeter(1.0), p)) { style = style.with_dashes(0.0, pat); } kurbo::stroke(path.iter(), &style, &kurbo::StrokeOpts::default(), 0.05) @@ -719,6 +719,19 @@ mod tests { assert!((s.area().abs() - 100.0).abs() < 2.0, "{}", s.area()); } + #[test] + fn a_dash_pattern_too_fine_for_its_path_strokes_solid() { + // ~500k dashes on this line (#1060): drawn solid, as a variable width stroke is past + // `MAX_DASHES`, rather than one outline per dash. + let mut line = BezPath::new(); + line.move_to((0.0, 0.0)); + line.line_to((10_000.0, 0.0)); + let props = StrokeProps { weight: 2.0, dashes: vec![0.01, 0.01], align: StrokeAlign::Center, ..Default::default() }; + let s = stroke_center(&line, 2.0, &props); + assert!(s.elements().len() < 100, "{} elements", s.elements().len()); + assert!((s.area().abs() - 20_000.0).abs() < 10.0, "{}", s.area()); + } + #[test] fn inside_and_outside_strokes_respect_an_even_odd_hole() { // A ring: both loops run the same way, so only the even-odd rule leaves the hole open. diff --git a/crates/pathops/src/width.rs b/crates/pathops/src/width.rs index 03240284..312c5b91 100644 --- a/crates/pathops/src/width.rs +++ b/crates/pathops/src/width.rs @@ -17,7 +17,7 @@ pub use figcraft_geom::measure::{Polyline, polylines}; /// Every subpath gets at least this many width samples, so the width varies smoothly along long /// straight runs. const SAMPLES_PER_SUBPATH: f64 = 128.0; -/// The most dashes a dashed variable width stroke makes. +/// The most dashes a dashed stroke makes ([`dashes_fit`]). const MAX_DASHES: usize = 20_000; /// The nearest point of the stroke path to `p`: (subpath index, t by length, distance). @@ -242,6 +242,12 @@ pub fn dash_pattern(props: &StrokeProps) -> Option> { Some(if dashes.len() % 2 == 1 { [dashes.clone(), dashes].concat() } else { dashes }) } +/// Whether `pattern` (from [`dash_pattern`]) makes at most [`MAX_DASHES`] dashes along `len`; +/// past that a stroke draws solid instead of one outline per dash (#1060). +pub(crate) fn dashes_fit(len: f64, pattern: &[f64]) -> bool { + len / pattern.iter().sum::() * (pattern.len() as f64) < MAX_DASHES as f64 +} + /// Resample a polyline so no step is longer than `max_step`; returns the points and the length at /// each, or `None` past the sample budget. fn resample(line: &Polyline, max_step: f64, budget: &mut usize) -> Option<(Vec, Vec)> { @@ -294,7 +300,7 @@ pub fn variable_outline(path: &BezPath, width: f64, props: &StrokeProps, profile }) .collect(); match &pattern { - Some(pat) if len / pat.iter().sum::() * (pat.len() as f64) < MAX_DASHES as f64 => { + Some(pat) if dashes_fit(len, pat) => { for (p, h) in dashes(&pts, &hw, pat) { outline_piece(&mut out, &p, &h, false, style); } From 2baeff3452f2c49a0017d2a826b3bdf9715c3bad Mon Sep 17 00:00:00 2001 From: Ridzzz0Alam Date: Sat, 24 Oct 2026 12:44:55 +0200 Subject: [PATCH 23/50] M1: dash limit counts the pattern restarting at each subpath (#1060) kurbo restarts the dash pattern at every MoveTo, so many short subpaths with a pattern of tiny dashes before a long gap made ~1M dashes (5M path elements) while the length-based estimate allowed them. stroke_center now adds one pattern's length per subpath to the estimate: an upper bound on the dashes kurbo makes. Test: each_subpath_restarting_the_dash_pattern_counts_toward_the_limit (5M elements before). Reported by CodeRabbit on #1278. --- crates/pathops/src/lib.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/pathops/src/lib.rs b/crates/pathops/src/lib.rs index 45d5122f..7fe7a64e 100644 --- a/crates/pathops/src/lib.rs +++ b/crates/pathops/src/lib.rs @@ -292,7 +292,9 @@ pub fn stroke_center(path: &BezPath, width: f64, props: &StrokeProps) -> BezPath .with_miter_limit(props.miter_limit.clamp(1.0, 100.0)) .with_start_cap(kcap(props.cap_start)) .with_end_cap(kcap(props.cap_end)); - if let Some(pat) = width::dash_pattern(props).filter(|p| width::dashes_fit(path.perimeter(1.0), p)) { + // Each subpath restarts the pattern, so it can add up to one more pattern's worth of dashes. + let subpaths = path.elements().iter().filter(|e| matches!(e, PathEl::MoveTo(_))).count() as f64; + if let Some(pat) = width::dash_pattern(props).filter(|p| width::dashes_fit(path.perimeter(1.0) + subpaths * p.iter().sum::(), p)) { style = style.with_dashes(0.0, pat); } kurbo::stroke(path.iter(), &style, &kurbo::StrokeOpts::default(), 0.05) @@ -732,6 +734,22 @@ mod tests { assert!((s.area().abs() - 20_000.0).abs() < 10.0, "{}", s.area()); } + #[test] + fn each_subpath_restarting_the_dash_pattern_counts_toward_the_limit() { + // The pattern restarts at every subpath: on 10,000 short lines its 199 tiny dashes come + // round each time (~1M dashes), though the length alone suggests a few hundred. + let mut path = BezPath::new(); + for i in 0..10_000 { + path.move_to((0.0, f64::from(i) * 4.0)); + path.line_to((2.0, f64::from(i) * 4.0)); + } + let mut dashes = vec![0.01; 199]; + dashes.push(10_000.0); + let props = StrokeProps { weight: 1.0, dashes, align: StrokeAlign::Center, ..Default::default() }; + let s = stroke_center(&path, 1.0, &props); + assert!(s.elements().len() < 100_000, "{} elements", s.elements().len()); + } + #[test] fn inside_and_outside_strokes_respect_an_even_odd_hole() { // A ring: both loops run the same way, so only the even-odd rule leaves the hole open. From 42fbe8f00c0a8a4fc80548d5ca5440847306b5ba Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sat, 24 Oct 2026 18:52:03 +0000 Subject: [PATCH 24/50] Skip zero-length segments when finding arrowhead direction Found while testing crates/pathops/src/lib.rs:352 (path_end, used by arrowhead) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/pathops/src/lib.rs | 69 ++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/crates/pathops/src/lib.rs b/crates/pathops/src/lib.rs index f4b30e10..46793f98 100644 --- a/crates/pathops/src/lib.rs +++ b/crates/pathops/src/lib.rs @@ -359,36 +359,35 @@ pub fn stroke_outline_of(path: &BezPath, props: &StrokeProps, closed_shape: bool /// End point and outward direction of an open path at its start or end. fn path_end(path: &BezPath, at_end: bool) -> Option<(Point, Vec2)> { - let segs: Vec = path.segments().collect(); - let seg = if at_end { segs.last()? } else { segs.first()? }; use kurbo::ParamCurve; use kurbo::ParamCurveDeriv; - let (p, d) = if at_end { - let d = match seg { - PathSeg::Line(l) => l.p1 - l.p0, - PathSeg::Quad(q) => q.deriv().eval(1.0).to_vec2(), - PathSeg::Cubic(c) => { - let d = c.deriv().eval(1.0).to_vec2(); - if d.hypot() < 1e-9 { c.p3 - c.p2 } else { d } - } + let dir_of = |seg: &PathSeg| -> Option<(Point, Vec2)> { + let (p, d) = if at_end { + let d = match seg { + PathSeg::Line(l) => l.p1 - l.p0, + PathSeg::Quad(q) => q.deriv().eval(1.0).to_vec2(), + PathSeg::Cubic(c) => { + let d = c.deriv().eval(1.0).to_vec2(); + if d.hypot() < 1e-9 { c.p3 - c.p2 } else { d } + } + }; + (seg.end(), d) + } else { + let d = match seg { + PathSeg::Line(l) => l.p0 - l.p1, + PathSeg::Quad(q) => -q.deriv().eval(0.0).to_vec2(), + PathSeg::Cubic(c) => { + let d = -c.deriv().eval(0.0).to_vec2(); + if d.hypot() < 1e-9 { c.p0 - c.p1 } else { d } + } + }; + (seg.start(), d) }; - (seg.end(), d) - } else { - let d = match seg { - PathSeg::Line(l) => l.p0 - l.p1, - PathSeg::Quad(q) => -q.deriv().eval(0.0).to_vec2(), - PathSeg::Cubic(c) => { - let d = -c.deriv().eval(0.0).to_vec2(); - if d.hypot() < 1e-9 { c.p0 - c.p1 } else { d } - } - }; - (seg.start(), d) + let len = d.hypot(); + (len >= 1e-12).then(|| (p, d / len)) }; - let len = d.hypot(); - if len < 1e-12 { - return None; - } - Some((p, d / len)) + // Skip zero-length segments (repeated vertices) and use the nearest one with a direction. + if at_end { path.segments().collect::>().iter().rev().find_map(dir_of) } else { path.segments().find_map(|s| dir_of(&s)) } } /// The filled arrowhead shape for `cap` at one end of an open path. @@ -742,4 +741,22 @@ mod tests { let s = stroke_outline_of(&ring, &inside, true, Some(&nz)); assert!(s.winding(material) != 0 && s.winding(hole) != 0); } + + #[test] + fn arrowhead_skips_zero_length_end_segments() { + let mut p = BezPath::new(); + p.move_to((0.0, 0.0)); + p.line_to((100.0, 0.0)); + assert!(arrowhead(&p, StrokeCap::TriangleArrow, 2.0, true).is_some()); + p.line_to((100.0, 0.0)); + let (tip, dir) = path_end(&p, true).expect("end direction"); + assert_eq!((tip, dir), (Point::new(100.0, 0.0), Vec2::new(1.0, 0.0))); + assert!(arrowhead(&p, StrokeCap::TriangleArrow, 2.0, true).is_some()); + let mut q = BezPath::new(); + q.move_to((0.0, 0.0)); + q.line_to((0.0, 0.0)); + q.line_to((100.0, 0.0)); + let (tip, dir) = path_end(&q, false).expect("start direction"); + assert_eq!((tip, dir), (Point::new(0.0, 0.0), Vec2::new(-1.0, 0.0))); + } } From a6a8d7149cb2a70b2bec86c0b5544b77a8b70785 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sun, 25 Oct 2026 03:52:14 +0000 Subject: [PATCH 25/50] Scale the path of text on a path in transform.scale Found while testing crates/engine/src/cmd/arrange.rs:~495 (scale_node, the Text branch). Compare crates/layout/src/lib.rs:136, which calls TextPath::scale on resize. Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/engine/src/cmd/arrange.rs | 3 +++ crates/engine/src/draw_tools_tests.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/crates/engine/src/cmd/arrange.rs b/crates/engine/src/cmd/arrange.rs index 10ad13e5..72f2118a 100644 --- a/crates/engine/src/cmd/arrange.rs +++ b/crates/engine/src/cmd/arrange.rs @@ -494,6 +494,9 @@ pub fn scale_node(doc: &mut Document, id: NodeId, k: f64) -> Result<()> { t.paragraph_spacing *= k; t.paragraph_indent *= k; t.list_spacing *= k; + if let Some(tp) = &mut t.path { + tp.scale(k, k); + } } if let NodeKind::Vector { network } = &mut n.kind { network.scale(k, k); diff --git a/crates/engine/src/draw_tools_tests.rs b/crates/engine/src/draw_tools_tests.rs index d67b0af4..adfbb32d 100644 --- a/crates/engine/src/draw_tools_tests.rs +++ b/crates/engine/src/draw_tools_tests.rs @@ -60,6 +60,18 @@ fn text_goes_onto_a_path_and_off_again() { assert!(s.doc().unwrap().node(v).is_some() && text_path(&s, t).is_none(), "undo brings the path back"); } +#[test] +fn scaling_text_scales_its_path() { + let mut s = Session::new(); + let t = id(s.execute("text.create", &json!({"text": "Around", "x": 0, "y": 0})).unwrap()); + let v = id(s.execute("vector.create", &json!({"path": "M0 0 C50 -50 150 -50 200 0", "x": 40, "y": 100})).unwrap()); + s.execute("text.onPath", &json!({"ids": [t, v]})).unwrap(); + let w0 = figcraft_geom::Shape::bounding_box(&text_path(&s, t).unwrap().path()).width(); + s.execute("transform.scale", &json!({"ids": [t], "factor": 2.0})).unwrap(); + let w1 = figcraft_geom::Shape::bounding_box(&text_path(&s, t).unwrap().path()).width(); + assert!((w1 - w0 * 2.0).abs() < 1.0, "path width {w0} -> {w1}"); +} + #[test] fn svg_text_paths_import_as_text_on_a_path() { // SVG text is parsed with Inter standing in for every family (CI has no fonts). From 2ef3ebb45d225217d1031d32e424bb61f15721aa Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Sun, 25 Oct 2026 05:17:15 +0100 Subject: [PATCH 26/50] E21: require release font coverage and stabilize capture deadline tests --- .github/workflows/ci.yml | 9 +- .github/workflows/freebsd.yml | 2 +- .github/workflows/release.yml | 9 +- ATTRIBUTION.md | 7 +- ROADMAP.md | 5 +- crates/text/build.rs | 173 +++++++++++++++--- crates/text/tests/build_input.rs | 4 + crates/text/tests/fixtures/latin-families.txt | 52 ++++++ crates/ui-egui/src/idle_tests.rs | 7 +- crates/ui-egui/src/windows_tests.rs | 4 +- docs/egui-037-local-followups.md | 51 ++++-- docs/egui-037-migration-plan.md | 4 + docs/releasing.md | 13 +- 13 files changed, 274 insertions(+), 66 deletions(-) create mode 100644 crates/text/tests/build_input.rs create mode 100644 crates/text/tests/fixtures/latin-families.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7abae66a..b79af502 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,11 +21,10 @@ jobs: # Tracks @main so suite-wide CI fixes reach every app without a PR in each repository. uses: storytold/craft-common-actions/.github/workflows/gate.yml@main with: - # The craft-fonts commit release.yml builds with. Needs fonts/latin-manifest.txt (Inter): - # crates/text/build.rs fails a build that requires craft-fonts without it. Only craft-fonts' - # pr/latin-presentation-fonts has it; its main has Noto Sans Georgian but no Inter. Re-pin - # once one commit has both (storytold/craft-fonts#42). - craft-fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83 + # Combined Latin presentation and core UI catalog. Required web builds enforce + # Inter Regular/SemiBold and Noto Sans Georgian Regular after asset-policy filtering. + craft-fonts-ref: 37827adc41fd165f9a9234ac40f94dbad353aa69 + require-craft-fonts: true packages: >- libxkbcommon-dev libwayland-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libgtk-3-dev diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml index e030b167..80adf16a 100644 --- a/.github/workflows/freebsd.yml +++ b/.github/workflows/freebsd.yml @@ -32,4 +32,4 @@ jobs: uses: storytold/craft-common-actions/.github/workflows/freebsd.yml@main with: run-package-check: true - craft-fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83 + craft-fonts-ref: 37827adc41fd165f9a9234ac40f94dbad353aa69 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8b37ee39..f93219fa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,13 +24,12 @@ jobs: with: app-name: figcraft app-title: FigCraft - # Needs fonts/latin-manifest.txt (Inter): crates/text/build.rs fails a release without it. Only - # craft-fonts' pr/latin-presentation-fonts has it; its main has Noto Sans Georgian but no Inter. - # Re-pin once one commit has both (storytold/craft-fonts#42). - craft-fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83 + # Combined Latin presentation and core UI catalog. Required web builds enforce + # Inter Regular/SemiBold and Noto Sans Georgian Regular after asset-policy filtering. + craft-fonts-ref: 37827adc41fd165f9a9234ac40f94dbad353aa69 has-server: true # The browser has no system fonts: without craft-fonts the web build can't draw text (#885). - # crates/text/build.rs keeps the web build to Inter. + # crates/text/build.rs keeps the web allowlist small (Inter and Georgian). web-craft-fonts: true version: ${{ inputs.version }} secrets: diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index bf6fdece..46b789a8 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -26,9 +26,12 @@ Release builds embed fonts from the optional craft-fonts build input |---|---|---| | Inter | SIL Open Font License 1.1 | https://github.com/rsms/inter | | Archivo | SIL Open Font License 1.1 | [Google Fonts / Archivo](https://github.com/google/fonts/tree/6c70c829f09ea345d3590406693220ea35c6553f/ofl/archivo) | -| Roboto, Montserrat, Lato, Open Sans, Poppins, Nunito Sans, Merriweather, Playfair Display, Source Sans 3, Source Serif 4, Carlito, Caladea | SIL Open Font License 1.1 | Google Fonts / upstream repositories (see craft-fonts) | +| Roboto, Montserrat, Lato, Open Sans, Poppins, Nunito Sans, Merriweather, Playfair Display, Carlito, Caladea | SIL Open Font License 1.1 | Google Fonts / upstream repositories (see craft-fonts) | | Liberation Sans, Serif, Mono | SIL Open Font License 1.1 | https://github.com/liberationfonts | -| BIZ UDPGothic, BIZ UDMincho, Shippori Mincho, Noto Sans Arabic | SIL Open Font License 1.1 | Google Fonts (see craft-fonts) | +| BIZ UDPGothic, BIZ UDMincho, Shippori Mincho, Noto Sans Arabic, Noto Sans Georgian | SIL Open Font License 1.1 | Google Fonts (see craft-fonts) | + +The central catalog also contains Adobe-authored Source Sans 3 and Source Serif 4. +FigCraft filters both families from every build in accordance with its asset policy. egui's default fonts (compiled into the `egui`/`epaint` crates) keep their own licences (OFL / Apache-2.0 / Ubuntu Font Licence); see those crates. diff --git a/ROADMAP.md b/ROADMAP.md index a27cc4df..0af8cbac 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -2,7 +2,7 @@ **Stage: alpha** · next: beta, ~26 points and ~162–292 h away (one Opus 5.5 agent; ~33–67 h wall-clock with 5 agents) -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-24 · **Change:** minor (Dev Mode measurements kept on the canvas and a read-only layers panel; boards: a board area row and progress entry; community fixes in #507, #510, #529 and #530: auto-save, a text box by dragging, batch step references, removing someone from a live session, Russian and Turkish catalogs reviewed, Czech and Indonesian drafts, the Japanese draft completed, zoom previews, the web clipboard, Alt-drag snapping and Cmd+D repeat, recovery copies, crash and rollback fixes, colour emoji, `.fig` import fixes; earlier changes are in the revision history below) · **Target:** Figma Design (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (egui 0.37 hidden-capture deadline contract; Dev Mode measurements kept on the canvas and a read-only layers panel; boards: a board area row and progress entry; community fixes in #507, #510, #529 and #530: auto-save, a text box by dragging, batch step references, removing someone from a live session, Russian and Turkish catalogs reviewed, Czech and Indonesian drafts, the Japanese draft completed, zoom previews, the web clipboard, Alt-drag snapping and Cmd+D repeat, recovery copies, crash and rollback fixes, colour emoji, `.fig` import fixes; earlier changes are in the revision history below) · **Target:** Figma Design (desktop app 126.10.7) FigCraft is a clean-room, open-source, pure-Rust reimplementation of the Figma design workflow, native on macOS, Windows, Linux and FreeBSD and in the browser, fully drivable by agents through @@ -132,6 +132,8 @@ Ranked; detail and milestones in [`docs/roadmap.md`](docs/roadmap.md). ## Progress log +- **2026-10-25** · egui 0.37 capture lifecycle: screenshots with hidden or unknown visibility queue, request a hidden paint, and expire after 60 seconds if no capture arrives (headless-tested contract). Logic-only edits, saves and inspection continue while hidden. Native visible GUI and forced hidden-window paint, browser and Wayland behavior remain unqualified; parity percentages are unchanged. + - **2026-10-24** · Dev Mode tail (M6, gap 16): Measurements kept on the canvas (gap 16): `devMode.addMeasurement {from?, to?, side?}` places one between two layers, along one side of a layer or (neither) to the layer around it, stored on the layer it starts from (saved in `.figcraft`, synced, undoable; old files open without them); Dev Mode draws them as labelled redlines that follow the layers, the Inspect tab lists them (those of the selected layer, or every one on the page), places and removes them; `devMode.removeMeasurement` and `devMode.measurements` remove and list them; a copy keeps those to layers copied with it. The layers panel is read-only in Dev Mode: rows select and expand, but don't rename, reorder, hide or lock. Dev Mode 98% / 78%. - **2026-10-24** · Boards (M12): File ▸ New board makes a board, a file kind of its own saved in `.figcraft` and carried to people joining a live session. Sticky notes (8 colours, text that shrinks as the note grows, the author's name, Shift+Cmd/Ctrl+Enter for the next one), shapes with text (7 outlines), connectors that re-route when what they join moves (computed in the engine's normalize pass, so local edits, undo and others' edits agree), marker, highlighter and eraser, stamps with the placer's name on hover; a board toolbar, a contextual bar over the selection and the Design panel hidden until asked for; prototyping and Dev Mode refuse on boards. Design files and boards have their own marks (a pen nib, a note) on tabs, the home screen and the Open files list. Checked in the app, with two app instances in one live session, and through MCP; the web build compiles ([boards-parity](docs/boards-parity.md)). - **2026-10-15** · Auto-save (M1, #305): Preferences ▸ Save files automatically (`pref.autoSave`, off by default, desktop only) saves each open file that has a path 3 s after its last change, never during a gesture, a live text preview or while a version is shown; the file is encoded off the UI thread, a failed save says why and is tried again a minute later. Numbers unchanged. @@ -329,6 +331,7 @@ Ranked; detail and milestones in [`docs/roadmap.md`](docs/roadmap.md). | Date | Change | Summary | |---|---|---| +| 2026-10-25 | minor | egui 0.37 capture lifecycle: screenshots with hidden or unknown visibility queue, request a hidden paint, and expire after 60 seconds if no capture arrives (headless-tested contract). Logic-only edits, saves and inspection continue while hidden. Native visible GUI and forced hidden-window paint, browser and Wayland behavior remain unqualified; parity percentages are unchanged. | | 2026-10-24 | minor | Dev Mode tail (M6, gap 16): Measurements kept on the canvas (gap 16): `devMode.addMeasurement {from?, to?, side?}` places one between two layers, along one side of a layer or (neither) to the layer around it, stored on the layer it starts from (saved in `.figcraft`, synced, undoable; old files open without them); Dev Mode draws them as labelled redlines that follow the layers, the Inspect tab lists them (those of the selected layer, or every one on the page), places and removes them; `devMode.removeMeasurement` and `devMode.measurements` remove and list them; a copy keeps those to layers copied with it. The layers panel is read-only in Dev Mode: rows select and expand, but don't rename, reorder, hide or lock. Dev Mode 97% → 98% breadth, 76% → 78% ready, 2–4 h → 1–2 h; headline numbers unchanged at this rounding | | 2026-10-24 | minor | Boards (M12): a file kind of its own (`file.newBoard`, saved in `.figcraft`, carried to live-session joiners) with sticky notes, shapes with text, connectors that re-route when what they join moves (an engine recompute, the same for local edits, undo and others' edits), marker, highlighter and eraser, stamps with the placer's name, a board toolbar and a contextual bar; prototyping and Dev Mode refuse on boards; design files and boards have their own marks on tabs and file rows. Boards row added outside the weighted numbers; headline numbers unchanged at this rounding | | 2026-10-15 | minor | Auto-save (#305, #296): Preferences ▸ Save files automatically (`pref.autoSave`, off by default; desktop only, the browser has no files to save to) saves each open file that has a path 3 s after its last change, so steady editing doesn't save every few seconds, and never during a gesture, a live text preview or while a version is shown. The file is encoded on a thread of its own and written as of that moment (edits made meanwhile stay unsaved); a failed save says why in a toast and is tried again a minute later, and version history checkpoints keep coming with it on. Numbers unchanged | diff --git a/crates/text/build.rs b/crates/text/build.rs index f46547cd..ecca6a45 100644 --- a/crates/text/build.rs +++ b/crates/text/build.rs @@ -1,6 +1,7 @@ //! Embeds the optional craft-fonts build input (`CRAFT_FONTS_DIR`): both `fonts/manifest.txt` and the //! opt-in Latin presentation fonts in `fonts/latin-manifest.txt` (Inter, Roboto, …). Unset or missing, -//! `CRAFT_FONTS` is empty and the app uses system fonts. Recipe: craft-fonts `docs/integration.md`. +//! `CRAFT_FONTS` is empty and native apps use system fonts. Required web releases enforce Inter +//! Regular/SemiBold and Noto Sans Georgian Regular after filtering. Recipe: craft-fonts `docs/integration.md`. //! Noto Sans CJK only with `FIGCRAFT_EMBED_CJK` set (the web build's only way to show CJK UI text). use std::fmt::Write as _; use std::path::PathBuf; @@ -10,30 +11,13 @@ fn main() { println!("cargo::rerun-if-env-changed=CRAFT_FONTS_REQUIRED"); println!("cargo::rerun-if-env-changed=FIGCRAFT_EMBED_CJK"); let mut src = String::from("pub static CRAFT_FONTS: &[CraftFont] = &[\n"); - if let Some(dir) = std::env::var_os("CRAFT_FONTS_DIR").map(PathBuf::from) { - let mut ok = false; - for manifest in ["fonts/latin-manifest.txt", "fonts/manifest.txt"] { - // Presentation faces are an optional extension of craft-fonts. Required mode - // validates the core manifest and every extension that is actually supplied. - let path = dir.join(manifest); - if manifest == "fonts/latin-manifest.txt" && !path.exists() { - watch(&path); - continue; - } - match craft_fonts(&dir, manifest) { - Ok(entries) => { - ok = true; - src.push_str(&entries); - } - Err(e) if std::env::var_os("CRAFT_FONTS_REQUIRED").is_some() => { - println!("cargo::error=CRAFT_FONTS_DIR={}: {e}", dir.display()); - } - Err(e) => println!("cargo::warning=craft-fonts {manifest} skipped: CRAFT_FONTS_DIR={}: {e}", dir.display()), - } - } - if !ok { - println!("cargo::warning=building without craft-fonts (once it is there, `cargo clean -p figcraft-text` makes the next build use it)"); - } + let dir = std::env::var_os("CRAFT_FONTS_DIR").map(PathBuf::from); + let required = std::env::var_os("CRAFT_FONTS_REQUIRED").is_some(); + let wasm = std::env::var("CARGO_CFG_TARGET_ARCH").is_ok_and(|a| a == "wasm32"); + let embed_cjk = std::env::var_os("FIGCRAFT_EMBED_CJK").is_some(); + match input_fonts(dir.as_deref(), wasm, required, embed_cjk) { + Ok(entries) => src.push_str(&entries), + Err(e) => println!("cargo::error={e}"), } src.push_str("];\n"); let out = PathBuf::from(std::env::var_os("OUT_DIR").unwrap_or_default()).join("craft_fonts.rs"); @@ -42,13 +26,45 @@ fn main() { } } +/// Collect the effective catalog and enforce the required web release faces after filtering. +fn input_fonts(dir: Option<&std::path::Path>, wasm: bool, required: bool, embed_cjk: bool) -> Result { + let Some(dir) = dir else { + return if required { Err("CRAFT_FONTS_REQUIRED is set but CRAFT_FONTS_DIR is missing".into()) } else { Ok(String::new()) }; + }; + let mut out = String::new(); + let mut faces = Vec::new(); + for manifest in ["fonts/latin-manifest.txt", "fonts/manifest.txt"] { + let path = dir.join(manifest); + if manifest == "fonts/latin-manifest.txt" && !path.exists() { + watch(&path); + continue; + } + match craft_fonts(dir, manifest, wasm, embed_cjk) { + Ok(catalog) => { + out.push_str(&catalog.entries); + faces.extend(catalog.faces); + } + Err(e) if required => return Err(format!("CRAFT_FONTS_DIR={}: {e}", dir.display())), + Err(e) => println!("cargo::warning=craft-fonts {manifest} skipped: CRAFT_FONTS_DIR={}: {e}", dir.display()), + } + } + if required && wasm { + for (family, style) in [("Inter", "Regular"), ("Inter", "SemiBold"), ("Noto Sans Georgian", "Regular")] { + if !faces.iter().any(|(f, s)| f == family && s == style) { + return Err(format!("required web font missing: {family} {style}; CRAFT_FONTS_DIR must include both Latin and core release faces")); + } + } + } + Ok(out) +} + /// Rebuild when `manifest` changes or, while it is missing, when it is added to its folder. /// /// Cargo takes a watched path that doesn't exist as changed on every build, and then rebuilds this /// crate and every crate that depends on it each time. So a missing manifest is never watched /// itself: its folder is, when there is one (a craft-fonts checkout without the Latin manifest). /// With no craft-fonts at all there is nothing to watch, so the build can't notice it arriving: -/// the warning in `main` says how to pick it up. +/// rebuild this crate after adding a previously absent checkout. fn watch(manifest: &std::path::Path) { let watched = if manifest.exists() { Some(manifest) } else { manifest.parent().filter(|folder| folder.is_dir()) }; if let Some(path) = watched { @@ -56,20 +72,29 @@ fn watch(manifest: &std::path::Path) { } } -fn craft_fonts(dir: &std::path::Path, manifest_rel: &str) -> Result { +struct Catalog { + entries: String, + faces: Vec<(String, String)>, +} + +fn craft_fonts(dir: &std::path::Path, manifest_rel: &str, wasm: bool, embed_cjk: bool) -> Result { let manifest = dir.join(manifest_rel); watch(&manifest); let text = std::fs::read_to_string(&manifest).map_err(|e| format!("{}: {e}", manifest.display()))?; - let wasm = std::env::var("CARGO_CFG_TARGET_ARCH").is_ok_and(|a| a == "wasm32"); let mut out = String::new(); + let mut faces = Vec::new(); for line in text.lines().map(str::trim).filter(|l| !l.is_empty() && !l.starts_with('#')) { let f: Vec<&str> = line.split(" | ").map(str::trim).collect(); let [family, style, file, scripts, ..] = f.as_slice() else { return Err(format!("malformed manifest line: {line}")); }; + // FigCraft's asset policy excludes Adobe-authored visual assets on every target. + if matches!(*family, "Source Sans 3" | "Source Serif 4") { + continue; + } // CJK fonts are large; the desktop app finds system CJK fonts instead unless asked. let cjk = scripts.contains("Hans"); - if cjk && std::env::var_os("FIGCRAFT_EMBED_CJK").is_none() { + if cjk && !embed_cjk { continue; } // Web builds have a size budget: Inter, Noto Sans Georgian (small, for the Georgian UI), only the @@ -80,7 +105,95 @@ fn craft_fonts(dir: &std::path::Path, manifest_rel: &str) -> Result Self { + let dir = std::env::temp_dir().join(format!("fig-font-input-{}-{}", std::process::id(), NEXT.fetch_add(1, Ordering::Relaxed))); + std::fs::create_dir_all(dir.join("fonts")).unwrap(); + // The build script validates manifest/file presence; font bytes are checked centrally. + std::fs::write(dir.join("fonts/face.ttf"), b"synthetic build-input fixture").unwrap(); + let fixture = Self(dir); + fixture.manifest("manifest.txt", &[("Noto Sans Georgian", "Regular")]); + fixture + } + + fn manifest(&self, name: &str, faces: &[(&str, &str)]) { + let text = faces.iter().map(|(family, style)| format!("{family} | {style} | fonts/face.ttf | Latn\n")).collect::(); + std::fs::write(self.0.join("fonts").join(name), text).unwrap(); + } + } + + impl Drop for Fixture { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.0); + } + } + + #[test] + fn restored_latin_catalog_preserves_permitted_native_faces_and_web_budget() { + let f = Fixture::new(); + std::fs::write(f.0.join("fonts/latin-manifest.txt"), include_str!("tests/fixtures/latin-families.txt")).unwrap(); + let native = craft_fonts(&f.0, "fonts/latin-manifest.txt", false, false).unwrap(); + assert_eq!(native.faces.len(), 43, "all prior permitted presentation faces remain available"); + let web = craft_fonts(&f.0, "fonts/latin-manifest.txt", true, false).unwrap(); + assert_eq!(web.faces.len(), 4, "the web catalog keeps only the four Inter faces"); + for catalog in [&native, &web] { + assert!(!catalog.entries.contains("Source Sans 3")); + assert!(!catalog.entries.contains("Source Serif 4")); + } + assert!(native.faces.iter().any(|(family, _)| family == "Carlito")); + assert!(native.faces.iter().any(|(family, _)| family == "Liberation Serif")); + assert!(input_fonts(Some(&f.0), true, true, false).is_ok()); + } + + #[test] + fn required_web_rejects_core_only_and_partial_latin_catalogs() { + let f = Fixture::new(); + assert!(input_fonts(Some(&f.0), true, true, false).unwrap_err().contains("Inter Regular")); + f.manifest("latin-manifest.txt", &[("Inter", "Regular"), ("Unrelated", "SemiBold")]); + assert!(input_fonts(Some(&f.0), true, true, false).unwrap_err().contains("Inter SemiBold")); + } + + #[test] + fn required_web_embeds_both_catalogs_and_requires_georgian() { + let f = Fixture::new(); + f.manifest("latin-manifest.txt", &[("Inter", "Regular"), ("Inter", "SemiBold")]); + let entries = input_fonts(Some(&f.0), true, true, false).unwrap(); + assert_eq!(entries.matches("CraftFont {").count(), 3); + assert!(entries.contains("family: \"Inter\"")); + assert!(entries.contains("family: \"Noto Sans Georgian\"")); + f.manifest("manifest.txt", &[("Other", "Regular")]); + assert!(input_fonts(Some(&f.0), true, true, false).unwrap_err().contains("Noto Sans Georgian Regular")); + } + + #[test] + fn optional_and_native_inputs_keep_their_existing_policy() { + let f = Fixture::new(); + assert!(input_fonts(None, true, false, false).unwrap().is_empty()); + assert!(input_fonts(None, true, true, false).unwrap_err().contains("CRAFT_FONTS_DIR is missing")); + assert!(input_fonts(Some(&f.0), true, false, false).unwrap().contains("Noto Sans Georgian")); + assert!(input_fonts(Some(&f.0), false, true, false).unwrap().contains("Noto Sans Georgian")); + } + + #[test] + fn required_web_rejects_missing_asset_even_with_all_face_rows() { + let f = Fixture::new(); + f.manifest("latin-manifest.txt", &[("Inter", "Regular"), ("Inter", "SemiBold")]); + std::fs::remove_file(f.0.join("fonts/face.ttf")).unwrap(); + assert!(input_fonts(Some(&f.0), true, true, false).unwrap_err().contains("fonts/face.ttf")); + } } diff --git a/crates/text/tests/build_input.rs b/crates/text/tests/build_input.rs new file mode 100644 index 00000000..6f87ac1f --- /dev/null +++ b/crates/text/tests/build_input.rs @@ -0,0 +1,4 @@ +//! Exercise the actual build-script catalog policy without changing process environment. +#[allow(dead_code)] +#[path = "../build.rs"] +mod build_script; diff --git a/crates/text/tests/fixtures/latin-families.txt b/crates/text/tests/fixtures/latin-families.txt new file mode 100644 index 00000000..e9db6f41 --- /dev/null +++ b/crates/text/tests/fixtures/latin-families.txt @@ -0,0 +1,52 @@ +# Synthetic paths; family/style inventory from craft-fonts 76ba5a0496503c0e2841abd626295038cbe07cde. +Inter | Regular | fonts/face.ttf | Latn +Inter | Italic | fonts/face.ttf | Latn +Inter | SemiBold | fonts/face.ttf | Latn +Inter | Bold | fonts/face.ttf | Latn +Carlito | Regular | fonts/face.ttf | Latn +Carlito | Bold | fonts/face.ttf | Latn +Carlito | Italic | fonts/face.ttf | Latn +Carlito | Bold Italic | fonts/face.ttf | Latn +Caladea | Regular | fonts/face.ttf | Latn +Caladea | Bold | fonts/face.ttf | Latn +Caladea | Italic | fonts/face.ttf | Latn +Caladea | Bold Italic | fonts/face.ttf | Latn +Liberation Sans | Regular | fonts/face.ttf | Latn +Liberation Sans | Bold | fonts/face.ttf | Latn +Liberation Sans | Italic | fonts/face.ttf | Latn +Liberation Sans | Bold Italic | fonts/face.ttf | Latn +Liberation Serif | Regular | fonts/face.ttf | Latn +Liberation Serif | Bold | fonts/face.ttf | Latn +Liberation Serif | Italic | fonts/face.ttf | Latn +Liberation Serif | Bold Italic | fonts/face.ttf | Latn +Liberation Mono | Regular | fonts/face.ttf | Latn +Liberation Mono | Bold | fonts/face.ttf | Latn +Liberation Mono | Italic | fonts/face.ttf | Latn +Liberation Mono | Bold Italic | fonts/face.ttf | Latn +Source Sans 3 | Regular | fonts/face.ttf | Latn +Source Sans 3 | Italic | fonts/face.ttf | Latn +Source Sans 3 | Semibold | fonts/face.ttf | Latn +Source Sans 3 | Bold | fonts/face.ttf | Latn +Source Serif 4 | Regular | fonts/face.ttf | Latn +Source Serif 4 | Italic | fonts/face.ttf | Latn +Source Serif 4 | Semibold | fonts/face.ttf | Latn +Source Serif 4 | Bold | fonts/face.ttf | Latn +Montserrat | Variable | fonts/face.ttf | Latn +Montserrat | Italic Variable | fonts/face.ttf | Latn +Lato | Regular | fonts/face.ttf | Latn +Lato | Bold | fonts/face.ttf | Latn +Lato | Italic | fonts/face.ttf | Latn +Open Sans | Variable | fonts/face.ttf | Latn +Open Sans | Italic Variable | fonts/face.ttf | Latn +Roboto | Variable | fonts/face.ttf | Latn +Roboto | Italic Variable | fonts/face.ttf | Latn +Merriweather | Regular | fonts/face.ttf | Latn +Merriweather | Bold | fonts/face.ttf | Latn +Merriweather | Italic | fonts/face.ttf | Latn +Playfair Display | Variable | fonts/face.ttf | Latn +Playfair Display | Italic Variable | fonts/face.ttf | Latn +Poppins | Regular | fonts/face.ttf | Latn +Poppins | Bold | fonts/face.ttf | Latn +Poppins | Italic | fonts/face.ttf | Latn +Nunito Sans | Variable | fonts/face.ttf | Latn +Nunito Sans | Italic Variable | fonts/face.ttf | Latn diff --git a/crates/ui-egui/src/idle_tests.rs b/crates/ui-egui/src/idle_tests.rs index 4c35ae40..c5da205c 100644 --- a/crates/ui-egui/src/idle_tests.rs +++ b/crates/ui-egui/src/idle_tests.rs @@ -345,12 +345,15 @@ fn cjk_names_are_looked_for_in_edits_not_on_every_pan() { fn a_hidden_window_answers_at_once() { // #269, #720: minimised or covered, the window draws no frames, but the app's logic still runs: // it answers edits, inspection, saves and the interface's state; what needs a frame (a capture - // of the window) is an error at once instead of waiting for the window to show. + // of the window) queues for a forced hidden paint and otherwise expires at its deadline. let dir = std::env::temp_dir().join(format!("figcraft-hidden-save-{}", std::process::id())); std::fs::create_dir_all(&dir).unwrap(); let path = dir.join("hidden.figcraft"); let (mut h, _) = document(); h.settle(); + // Exercise admission well after startup, independently of settling speed. + h.time += 120.0; + h.app.clock.set_test_now(Some(h.time)); let (tx, rx) = std::sync::mpsc::channel(); let request = |id: u64, method: &str, params: Value| ControlRequest { id: json!(id), @@ -376,7 +379,7 @@ fn a_hidden_window_answers_at_once() { assert_eq!(h.app.capture.shots.len(), 1, "one admitted capture"); assert!(h.app.control_queue.is_empty(), "nothing waits for the window"); // Its deadline expires it once, with the same error the transport used to get. - h.app.clock.set_test_now(Some(crate::control::SHOT_TIMEOUT + 1.0)); + h.app.clock.set_test_now(Some(h.time + crate::control::SHOT_TIMEOUT + 1.0)); let _ = ctx.run_logic(&hidden, |ctx| crate::control::background(&mut h.app, ctx)); let shot = rx.try_recv().expect("expired"); assert_eq!(shot.id, json!(3)); diff --git a/crates/ui-egui/src/windows_tests.rs b/crates/ui-egui/src/windows_tests.rs index 1537f426..6da3a011 100644 --- a/crates/ui-egui/src/windows_tests.rs +++ b/crates/ui-egui/src/windows_tests.rs @@ -137,6 +137,8 @@ fn another_hidden_window_answers_requests_that_need_no_frame_in_its_own_file() { // A capture that needs a frame is admitted and asks the hidden window to paint, rather than // failing at once; only its deadline expires it (once). + // Model a request admitted long after startup, without waiting in real time. + app.clock.set_test_now(Some(120.0)); let shot = request(&mut app, "ui.screenshot", json!({"window": w, "path": "unused.png"})); let unknown = request(&mut app, "window.list", json!({"window": 99})); logic(&ctx, &mut app, &[ViewportId::ROOT, other]); @@ -145,7 +147,7 @@ fn another_hidden_window_answers_requests_that_need_no_frame_in_its_own_file() { assert!(unknown.try_recv().expect("answered").result.unwrap_err().contains("no window 99")); assert!(app.control_queue.is_empty()); // The whole request lifetime is over: one timeout reply, and nothing retained. - app.clock.set_test_now(Some(crate::control::SHOT_TIMEOUT + 1.0)); + app.clock.set_test_now(Some(app.clock.now() + crate::control::SHOT_TIMEOUT + 1.0)); logic(&ctx, &mut app, &[ViewportId::ROOT, other]); assert!(shot.try_recv().expect("answered").result.unwrap_err().contains("didn't deliver a screenshot")); assert!(app.capture.shots.is_empty(), "released after its deadline"); diff --git a/docs/egui-037-local-followups.md b/docs/egui-037-local-followups.md index dde4e5c1..670fc30f 100644 --- a/docs/egui-037-local-followups.md +++ b/docs/egui-037-local-followups.md @@ -1,7 +1,24 @@ # egui 0.37 local implementation — stage 1 notes and follow-ups +Current candidate font pin: `37827adc41fd165f9a9234ac40f94dbad353aa69` restores the complete prior Latin catalog +alongside the migration fallbacks. Central font tests and license checks passed; +publication is pending approval. Managed run `egui037-figcraft-latin-ci-20261025-0711` +passed with required fonts: five targeted build-input tests plus full CI, including +WASM and plugin builds (3,257 passing executions, zero failures, nine ignored across +72 summaries; repeated tests are counted). This supersedes the optional-font-only +qualification below for the restored catalog. + ## Current local qualification — 2026-10-25 +The published refresh preserves main `9f788753` and passed managed full CI +`egui037-figcraft-main-refresh-ci-20261025-0618`: 3,247 passing executions, zero +failures and nine ignored. The 3,242 counts below describe the earlier `10702311` +qualification, before five additional main-branch tests. These are execution counts, +not distinct regressions. The release font input is under review separately; a +passing optional-font host build does not qualify the required web font catalog. + +### Earlier qualification at `10702311` + The migration preserves captured main `10702311f345393ee1d8868c3257679befcfa14d` (53 commits and 114 paths beyond the first integration). The final review commit records both the migration history and that upstream target as parents. The selected egui revision is @@ -147,19 +164,19 @@ an unhandled command for hidden tabs. Hidden-browser-tab `ui.screenshot`/`ui.inp unqualified even though the native path now queues and settles them. This is a forkfix prerequisite, not a passing claim. -## Local dependency and lock prerequisites (parent) +## Dependency and lock prerequisites -- Parent config `local-integration-config.toml` patches the egui family and winit, and `craft-ui`/ - `craft-print`. It does **not** patch `craft-window`. FigCraft now disables craft-window's optional - `egui` feature (it only needs the frame probe), but Cargo still resolves a package's optional - dependencies into the lock, and that rev declares `egui = "0.36"`. The managed graph must - therefore also patch/repoint `craft-window` to the reviewed craft-libs revision whose workspace - targets 0.37 (or otherwise prove the lock has exactly one egui family); otherwise the lock will - contain a second egui 0.36. -- No `[patch]` rows or path dependencies live in this repository's manifests; the parent generates - `Cargo.lock`. Do not publish this tree's resolved paths. -- Fonts: production keeps its central `CRAFT_FONTS_DIR`/system-font policy; no font binaries are - added here. Color-emoji claims still require a separate `epaint/color_fonts` feature job. +- The committed root `[patch.crates-io]` table pins the egui family and winit to + immutable published fork revisions. `craft-window` is pinned to the reviewed + craft-libs revision targeting egui 0.37; its optional `egui` feature stays disabled + because FigCraft needs only the frame probe. +- `Cargo.lock` is committed and resolves the canonical Git sources without local + path overrides. Use `--locked`; the earlier parent integration config is not + required to reproduce this graph. +- Fonts remain an optional central `CRAFT_FONTS_DIR` input with native system-font + fallback; no font binaries are added here. Required release-font qualification + is separate from optional-font host CI. Color emoji still needs a separate + `epaint/color_fonts` feature check. ## Qualification gaps and baseline backports/perf operations @@ -182,6 +199,12 @@ operations to measure once the parent can build: `#8731` text tessellation, `#87 startup, `#8512` font discovery, `#8763`/PR `#8764` TextEdit click-away, `#8748` hidden deferred children. None of these were applied, removed or claimed as fixed. -## Optional Latin manifest compatibility +## Required web font catalog -The pinned central font catalog has a required `fonts/manifest.txt` and no optional `fonts/latin-manifest.txt`. Required-font builds now validate the core and all supplied extension assets, while an absent opt-in Latin manifest is watched but not required. This follows the existing build script documentation and keeps malformed or incomplete supplied manifests fatal in required mode. No font binary was copied into FigCraft. Both required-core and no-font configurations remain validation gates. +Native optional-font builds retain the system-font policy. A required web build must +embed Inter Regular and SemiBold plus Noto Sans Georgian Regular after filtering; +missing required face/style coverage fails the build, regardless of which manifest supplies it. Required mode +also rejects an unset `CRAFT_FONTS_DIR`. The migration's original `b076417` catalog +lacks Inter and is not a qualified required-web input. A combined central font pin restores the prior Latin catalog while preserving the new +core fallbacks. Source Sans 3 and Source Serif 4 are excluded on every target; no font binary belongs in this repository. Required-web, required-native +and optional-font configurations remain separate validation gates. diff --git a/docs/egui-037-migration-plan.md b/docs/egui-037-migration-plan.md index fc7ecbc4..27ce7c5c 100644 --- a/docs/egui-037-migration-plan.md +++ b/docs/egui-037-migration-plan.md @@ -1188,6 +1188,10 @@ validation and generates the lockfile from its local dependency config. ## Current local qualification — 2026-10-25 +Historical qualification: the following counts apply to the earlier `10702311` +integration. The current `9f788753` refresh and its 3,247 passing executions are +recorded in the status update above. + The migration preserves captured main `10702311f345393ee1d8868c3257679befcfa14d` (53 commits and 114 paths beyond the first integration). The final review commit records both the migration history and that upstream target as parents. The selected egui revision is diff --git a/docs/releasing.md b/docs/releasing.md index 07492f6c..3dbc0fbf 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -101,11 +101,14 @@ builds with `CRAFT_FONTS_DIR` and `CRAFT_FONTS_REQUIRED=1`, so releases embed it rather than ship without them. The browser has no system fonts, so a web build without craft-fonts can't draw text. `crates/text/build.rs` reads both `fonts/manifest.txt` and `fonts/latin-manifest.txt`, so the pin -must be a commit that has the Latin manifest (today `4391305`, on craft-fonts' -`pr/latin-presentation-fonts` branch; re-pin to `main` once that lands). That commit has no -Noto Sans Georgian (craft-fonts' main has it but no Latin manifest), so desktop Georgian uses an -installed font; re-pin when one commit has both (craft-fonts#42). The web build embeds only Inter, -Noto Sans Georgian and the Archivo SemiBold wordmark, when the pin has them. Packages carry each embedded font's licence as `OFL-.txt` +must combine the Latin presentation catalog and the current core UI faces. Required web builds +validate the emitted Inter Regular/SemiBold and Noto Sans Georgian Regular faces after filtering; +a missing required face, style or asset fails the required web build. Excluded Adobe rows +are skipped before resolving their asset paths. +Native builds retain the permitted Latin presentation faces. Source Sans 3 and Source Serif 4 +are filtered on every target under FigCraft's asset policy. The web build keeps its smaller +allowlist: Inter, Noto Sans Georgian and Archivo SemiBold when supplied. Packages carry each +embedded font's licence as `OFL-.txt` (`copy_font_licences` in `packaging/env.sh`; `Contents/Resources/Licenses` in the macOS app). ### macOS From d7c7986347c85d27b2fe80411dd5b04003e108c0 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Sun, 25 Oct 2026 05:32:03 +0100 Subject: [PATCH 27/50] E21: separate capture, IME and field-save regression phases --- crates/ui-egui/src/control.rs | 414 +++++++++++++++++------------- crates/ui-egui/src/field_tests.rs | 280 ++++++++++---------- crates/ui-egui/src/shortcuts.rs | 300 ++++++++++++---------- 3 files changed, 547 insertions(+), 447 deletions(-) diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index fdecaf18..b7ca225d 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -455,171 +455,18 @@ pub fn drain(app: &mut FigApp, ctx: &Context) { let viewport = ctx.viewport_id(); // This pass's geometry defines the epoch: a resize, DPI change or zoom change (back or not) // invalidates captures issued under the old one. - let spec = current_spec(ctx, viewport); - if let Some(spec) = spec { - let changed = app.capture.geometry.get(&viewport).is_none_or(|(old, _)| *old != spec); - if changed { - app.capture.epoch = app.capture.epoch.wrapping_add(1); - app.capture.geometry.insert(viewport, (spec, app.capture.epoch)); - } - } - let epoch = app.capture.geometry.get(&viewport).map_or(0, |(_, e)| *e); + let (spec, epoch) = pass_geometry(app, ctx, viewport); expire(app, ctx, now); // Drain completed captures first, so their budget is free before new requests are admitted. - let mut i = 0; - while i < app.capture.shots.len() { - // Each viewport drains its own captures: their geometry and document differ. - if app.capture.shots[i].viewport != viewport { - i += 1; - continue; - } - let Some(slot) = app.capture.shots[i].slot.clone() else { - i += 1; - continue; - }; - let Some(image) = slot.take() else { - i += 1; - continue; - }; - let mut r = app.capture.shots.remove(i); - r.release(); - let cancelled = r.cancelled.load(std::sync::atomic::Ordering::Relaxed); - let current = current_spec(ctx, viewport); - let (document, presentation) = app.windows.presentation(&app.session, r.window); - if cancelled { - // The transport stopped waiting: no reply, no file. - } else if now >= r.deadline { - reply(&mut r, Err("the window didn't deliver a screenshot in time (is it visible?)".into())); - } else if r.window != app.windows.current || r.document != document || r.presentation != presentation { - reply(&mut r, Err("the document changed while the screenshot was being captured".into())); - } else if current.is_none() { - // Fail closed: with no representable current geometry the pixels cannot be proven to - // belong to the surface that was admitted, so they are never the capture's reply. - reply(&mut r, Err("the window's current geometry is unavailable (is it minimised?)".into())); - } else if let Some(current) = current - && (r.epoch != epoch || r.spec.is_none_or(|s| s.size_px != current.size_px || s.pixels_per_point != current.pixels_per_point)) - { - // Geometry moved between issuance and arrival (even back): retry against the new pass, - // never accept the old pixels. Document changes are errors above. - if r.retries >= 2 { - reply(&mut r, Err("the window kept changing size while the screenshot was captured".into())); - } else { - r.retries += 1; - r.spec = Some(current); - r.epoch = epoch; - r.reserved = r.spec.and_then(|s| s.cost()).unwrap_or(0); - r.settle = 0; - r.settle_frame = None; - r.issued = false; - app.capture.shots.push(r); - } - } else if let (Some(current), Some(spec)) = (current, r.spec) - // The admitted surface is in whole UI points; the readback is in physical pixels. Up - // to one pixel of rounding either way is the same surface, not a scale change. The - // difference is absolute: an undersized readback is a scale mismatch too. - && (image.size[0].abs_diff(spec.size_px[0]) > 1 || image.size[1].abs_diff(spec.size_px[1]) > 1) - { - if r.retries >= 2 { - reply( - &mut r, - Err(format!( - "the screenshot is {}x{} but the window is {}x{} (a scale mismatch)", - image.size[0], image.size[1], spec.size_px[0], spec.size_px[1] - )), - ); - } else { - r.retries += 1; - r.spec = Some(current); - r.epoch = epoch; - r.reserved = r.spec.and_then(|s| s.cost()).unwrap_or(0); - r.settle = 0; - r.settle_frame = None; - r.issued = false; - app.capture.shots.push(r); - } - } else { - let result = shot_reply(&image, r.path.as_deref()); - reply(&mut r, result); - } - ctx.request_repaint(); - } + drain_completed(app, ctx, viewport, now, epoch); // Admit queued captures for the window drawing now; other windows keep waiting for their frame. - for r in std::mem::take(&mut app.control_queue) { - if r.is_cancelled() { - continue; - } - let target = r.params.get("window").and_then(Value::as_u64).unwrap_or(app.windows.focused); - if target != app.windows.current { - if app.windows.exists(target) { - ctx.request_repaint_of(crate::windows::viewport(target)); - app.control_queue.push(r); - } else { - let _ = r.reply.send(ControlReply { id: r.id, result: Err(format!("no window {target}")) }); - } - continue; - } - if r.method == "ui.screenshot" { - admit(app, r, target, now); - continue; - } - // Every control-channel gesture is fenced from the user's system clipboard (the flag is - // restored so a batch already in a frame's raw input keeps its own provenance). - let before = app.control_synthetic; - app.control_synthetic = true; - let res = handle(app, ctx, &r.method, &r.params); - app.control_synthetic = before; - if r.method == "ui.input" && std::mem::take(&mut app.control_input_queued) { - // Acknowledge once the pass that applies the batch is presented, never from a sizing - // pass whose input is thrown away. - app.input_acks.push(crate::PendingAck { viewport, tx: r.reply, reply: ControlReply { id: r.id, result: res } }); - } else { - let _ = r.reply.send(ControlReply { id: r.id, result: res }); - } - ctx.request_repaint(); - } + admit_queued(app, ctx, viewport, now); // Fill in this pass's geometry, enforce the byte budget (a post-callback check alone would // not bound peak memory), and release anything over it before issuing. - let mut i = 0; - while i < app.capture.shots.len() { - let total: usize = app.capture.shots.iter().map(|s| s.reserved).sum(); - let mut remove = false; - { - let r = &mut app.capture.shots[i]; - if r.viewport != viewport { - i += 1; - continue; - } - if !r.issued && r.spec != spec { - // A request can resize during its settling frames. Reserve and validate this - // actual surface before issuance, never the old (possibly much smaller) one. - r.spec = spec; - r.settle = 0; - r.settle_frame = None; - if spec.is_none() { - r.reserved = 0; - } - } - if let Some(spec) = r.spec { - let raw = spec.bytes().unwrap_or(usize::MAX); - let cost = spec.cost().unwrap_or(usize::MAX); - if raw > MAX_SHOT_IMAGE_BYTES || total.saturating_sub(r.reserved).saturating_add(cost) > MAX_SHOT_TOTAL_BYTES { - reply(r, Err(format!("the screenshot needs {cost} bytes, over the capture budget"))); - remove = true; - } else if r.reserved != cost { - r.reserved = cost; - } - } - } - if remove { - let mut r = app.capture.shots.remove(i); - r.release(); - } else { - i += 1; - } - } + enforce_capture_budget(app, viewport, spec); // Settle on completed UI frames only, then issue once. (The screenshot command itself forces // the paint that delivers it.) The request's document and window were fixed at admission and @@ -630,6 +477,243 @@ pub fn drain(app: &mut FigApp, ctx: &Context) { // first pass calls `request_discard` is therefore counted once, after it presents its layout, // not when its discarded sizing pass runs. Passes after the first (`current_pass_index > 0`) // belong to such a frame and never add another count. + settle_and_issue(app, ctx, viewport, now, epoch, spec); + request_paint(app, ctx); +} + +/// Establish this pass's screenshot geometry and epoch: a resize, DPI change or zoom change (even +/// back) bumps the epoch captures issued under the old one were admitted against. +fn pass_geometry(app: &mut FigApp, ctx: &Context, viewport: egui::ViewportId) -> (Option, u64) { + let spec = current_spec(ctx, viewport); + if let Some(spec) = spec { + let changed = app.capture.geometry.get(&viewport).is_none_or(|(old, _)| *old != spec); + if changed { + app.capture.epoch = app.capture.epoch.wrapping_add(1); + app.capture.geometry.insert(viewport, (spec, app.capture.epoch)); + } + } + let epoch = app.capture.geometry.get(&viewport).map_or(0, |(_, e)| *e); + (spec, epoch) +} + +/// Take the image delivery for the shot at `index`; `None` when no image has arrived yet. +fn arrived_shot(app: &mut FigApp, index: usize) -> Option<(ShotRequest, Arc)> { + let slot = app.capture.shots.get(index)?.slot.clone()?; + let image = slot.take()?; + let mut r = app.capture.shots.remove(index); + r.release(); + Some((r, image)) +} + +/// Drain images delivered for this viewport: reply, re-queue for a geometry retry, or drop a +/// cancelled capture. Each viewport drains its own captures: their geometry and document differ. +fn drain_completed(app: &mut FigApp, ctx: &Context, viewport: egui::ViewportId, now: f64, epoch: u64) { + let mut i = 0; + while i < app.capture.shots.len() { + if app.capture.shots[i].viewport != viewport { + i += 1; + continue; + } + let Some((r, image)) = arrived_shot(app, i) else { + i += 1; + continue; + }; + settle_arrival(app, ctx, viewport, now, epoch, r, &image); + ctx.request_repaint(); + } +} + +/// Whether the pass geometry differs from the one the capture was issued at (even back to an old +/// size): the pixels cannot be accepted for the admitted surface. +fn geometry_moved(r: &ShotRequest, current: CaptureSpec, epoch: u64) -> bool { + r.epoch != epoch || r.spec.is_none_or(|s| s.size_px != current.size_px || s.pixels_per_point != current.pixels_per_point) +} + +/// The admitted surface is in whole UI points; the readback is in physical pixels. Up to one +/// pixel of rounding either way is the same surface, not a scale change. The difference is +/// absolute: an undersized readback is a scale mismatch too. +fn scale_mismatch(image: &egui::ColorImage, spec: CaptureSpec) -> bool { + image.size[0].abs_diff(spec.size_px[0]) > 1 || image.size[1].abs_diff(spec.size_px[1]) > 1 +} + +/// Re-queue a capture against the new pass, or hand it back when its retries are exhausted. +fn requeue_capture(app: &mut FigApp, mut r: ShotRequest, current: CaptureSpec, epoch: u64) -> Option { + if r.retries >= 2 { + return Some(r); + } + r.retries += 1; + r.spec = Some(current); + r.epoch = epoch; + r.reserved = r.spec.and_then(|s| s.cost()).unwrap_or(0); + r.settle = 0; + r.settle_frame = None; + r.issued = false; + app.capture.shots.push(r); + None +} + +/// Settle an arrived image: reply with it, retry against the new pass on a geometry/scale change, +/// or drop it when the transport cancelled or the window/document moved on. +fn settle_arrival(app: &mut FigApp, ctx: &Context, viewport: egui::ViewportId, now: f64, epoch: u64, mut r: ShotRequest, image: &egui::ColorImage) { + let cancelled = r.cancelled.load(std::sync::atomic::Ordering::Relaxed); + let current = current_spec(ctx, viewport); + let (document, presentation) = app.windows.presentation(&app.session, r.window); + if cancelled { + // The transport stopped waiting: no reply, no file. + return; + } + if now >= r.deadline { + reply(&mut r, Err("the window didn't deliver a screenshot in time (is it visible?)".into())); + return; + } + if r.window != app.windows.current || r.document != document || r.presentation != presentation { + reply(&mut r, Err("the document changed while the screenshot was being captured".into())); + return; + } + let Some(current) = current else { + // Fail closed: with no representable current geometry the pixels cannot be proven to + // belong to the surface that was admitted, so they are never the capture's reply. + reply(&mut r, Err("the window's current geometry is unavailable (is it minimised?)".into())); + return; + }; + if geometry_moved(&r, current, epoch) { + // Geometry moved between issuance and arrival (even back): retry against the new pass, + // never accept the old pixels. Document changes are errors above. + if let Some(mut r) = requeue_capture(app, r, current, epoch) { + reply(&mut r, Err("the window kept changing size while the screenshot was captured".into())); + } + return; + } + if let Some(spec) = r.spec + && scale_mismatch(image, spec) + { + if let Some(mut r) = requeue_capture(app, r, current, epoch) { + reply( + &mut r, + Err(format!( + "the screenshot is {}x{} but the window is {}x{} (a scale mismatch)", + image.size[0], image.size[1], spec.size_px[0], spec.size_px[1] + )), + ); + } + return; + } + let result = shot_reply(image, r.path.as_deref()); + reply(&mut r, result); +} + +/// Admit queued captures for the window drawing now; other windows keep waiting for their frame. +fn admit_queued(app: &mut FigApp, ctx: &Context, viewport: egui::ViewportId, now: f64) { + for r in std::mem::take(&mut app.control_queue) { + route_queued(app, ctx, viewport, now, r); + } +} + +/// Route one queued control request: retarget another window, admit a capture, or run a +/// state-only request for the window drawing now. +fn route_queued(app: &mut FigApp, ctx: &Context, viewport: egui::ViewportId, now: f64, r: ControlRequest) { + if r.is_cancelled() { + return; + } + let target = r.params.get("window").and_then(Value::as_u64).unwrap_or(app.windows.focused); + if target != app.windows.current { + if app.windows.exists(target) { + ctx.request_repaint_of(crate::windows::viewport(target)); + app.control_queue.push(r); + } else { + let _ = r.reply.send(ControlReply { id: r.id, result: Err(format!("no window {target}")) }); + } + return; + } + if r.method == "ui.screenshot" { + admit(app, r, target, now); + return; + } + // Every control-channel gesture is fenced from the user's system clipboard (the flag is + // restored so a batch already in a frame's raw input keeps its own provenance). + let before = app.control_synthetic; + app.control_synthetic = true; + let res = handle(app, ctx, &r.method, &r.params); + app.control_synthetic = before; + if r.method == "ui.input" && std::mem::take(&mut app.control_input_queued) { + // Acknowledge once the pass that applies the batch is presented, never from a sizing + // pass whose input is thrown away. + app.input_acks.push(crate::PendingAck { viewport, tx: r.reply, reply: ControlReply { id: r.id, result: res } }); + } else { + let _ = r.reply.send(ControlReply { id: r.id, result: res }); + } + ctx.request_repaint(); +} + +/// Reserve this request's actual surface against the capture budget; `true` when it must be +/// removed for exceeding it. +fn reserve_for_spec(r: &mut ShotRequest, spec: Option, total: usize) -> bool { + if !r.issued && r.spec != spec { + // A request can resize during its settling frames. Reserve and validate this + // actual surface before issuance, never the old (possibly much smaller) one. + r.spec = spec; + r.settle = 0; + r.settle_frame = None; + if spec.is_none() { + r.reserved = 0; + } + } + let Some(spec) = r.spec else { return false }; + let raw = spec.bytes().unwrap_or(usize::MAX); + let cost = spec.cost().unwrap_or(usize::MAX); + if raw > MAX_SHOT_IMAGE_BYTES || total.saturating_sub(r.reserved).saturating_add(cost) > MAX_SHOT_TOTAL_BYTES { + reply(r, Err(format!("the screenshot needs {cost} bytes, over the capture budget"))); + return true; + } + if r.reserved != cost { + r.reserved = cost; + } + false +} + +/// Fill in this pass's geometry and enforce the byte budget (a post-callback check alone would +/// not bound peak memory), releasing anything over it before issuing. +fn enforce_capture_budget(app: &mut FigApp, viewport: egui::ViewportId, spec: Option) { + let mut i = 0; + while i < app.capture.shots.len() { + let total: usize = app.capture.shots.iter().map(|s| s.reserved).sum(); + let remove = { + let r = &mut app.capture.shots[i]; + if r.viewport != viewport { + i += 1; + continue; + } + reserve_for_spec(r, spec, total) + }; + if remove { + let mut r = app.capture.shots.remove(i); + r.release(); + } else { + i += 1; + } + } +} + +/// Count one completed frame into the capture's settling, reporting whether it may now be issued. +fn settled_for_issue(r: &mut ShotRequest, frame_nr: u64) -> bool { + match r.settle_frame { + None => { + // Anchor the count at the first pass that sees this request's geometry; this + // frame has not completed yet. + r.settle_frame = Some(frame_nr); + false + } + Some(seen) if frame_nr > seen => { + r.settle_frame = Some(frame_nr); + r.settle = r.settle.saturating_add(1); + r.settle >= SHOT_SETTLE_PASSES + } + _ => false, + } +} + +/// Settle on completed UI frames only, then issue once (against this pass's surface). +fn settle_and_issue(app: &mut FigApp, ctx: &Context, viewport: egui::ViewportId, now: f64, epoch: u64, spec: Option) { let first_pass = ctx.current_pass_index() == 0; let frame_nr = ctx.cumulative_frame_nr_for(viewport); for r in &mut app.capture.shots { @@ -639,20 +723,7 @@ pub fn drain(app: &mut FigApp, ctx: &Context) { if r.cancelled.load(std::sync::atomic::Ordering::Relaxed) || now >= r.deadline { continue; } - match r.settle_frame { - None => { - // Anchor the count at the first pass that sees this request's geometry; this - // frame has not completed yet. - r.settle_frame = Some(frame_nr); - continue; - } - Some(seen) if frame_nr > seen => { - r.settle_frame = Some(frame_nr); - r.settle = r.settle.saturating_add(1); - } - _ => continue, - } - if r.settle < SHOT_SETTLE_PASSES { + if !settled_for_issue(r, frame_nr) { continue; } let slot = CaptureSlot::new(ctx, viewport); @@ -665,7 +736,6 @@ pub fn drain(app: &mut FigApp, ctx: &Context) { r.issued = true; ctx.send_viewport_cmd_to(viewport, egui::ViewportCommand::Screenshot(CaptureSlot::callback(&slot))); } - request_paint(app, ctx); } /// A screenshot's reply: the PNG written to `path` (through the automation roots, when the app diff --git a/crates/ui-egui/src/field_tests.rs b/crates/ui-egui/src/field_tests.rs index 68a6564b..e09df06e 100644 --- a/crates/ui-egui/src/field_tests.rs +++ b/crates/ui-egui/src/field_tests.rs @@ -872,148 +872,146 @@ fn a_prepared_field_save_cannot_commit_into_a_same_pass_replacement_document() { for route in ["control", "tab"] { for save_as in [false, true] { for discard in [false, true] { - let (mut u, a, _) = setup(); - let dir = std::env::temp_dir().join(format!("figcraft-field-save-owner-{}-{route}-{save_as}-{discard}", std::process::id())); - std::fs::create_dir_all(&dir).unwrap(); - let (path, other, copy) = (dir.join("a.figcraft"), dir.join("b.figcraft"), dir.join("copy.figcraft")); - u.app.session.execute("file.saveAs", &json!({"path": path.to_string_lossy()})).unwrap(); - let owner = u.app.session.ds().unwrap().uid; - let owner_bytes = std::fs::read(&path).unwrap(); - u.app.session.execute("file.new", &json!({"name": "Same-pass B"})).unwrap(); - let b = id(u.app.session.execute("shape.rectangle", &json!({"x": 200, "y": 40, "width": 30, "height": 30})).unwrap()); - u.app.session.execute("file.saveAs", &json!({"path": other.to_string_lossy()})).unwrap(); - u.app.session.execute("shape.rectangle", &json!({"x": 300, "y": 0, "width": 10, "height": 10})).unwrap(); - u.app.session.execute("select.set", &json!({"ids": [b]})).unwrap(); - let other_index = u.app.session.active; - let other_uid = u.app.session.ds().unwrap().uid; - let other_name = u.app.session.doc().unwrap().name.clone(); - let other_model = u.app.session.ds().unwrap().doc.clone(); - let before_switch_revision = u.app.session.ds().unwrap().revision; - let other_history = u.app.session.undo_depth(); - let other_selection = u.app.session.ds().unwrap().selection.clone(); - let other_dirty = u.app.session.ds().unwrap().is_dirty(); - let other_bytes = std::fs::read(&other).unwrap(); - assert!(other_dirty, "B has independent unsaved content"); - let owner_index = u.app.session.docs.iter().position(|d| d.uid == owner).unwrap(); - u.app.session.execute("doc.switch", &json!({"index": owner_index})).unwrap(); - // Every command bumps the outgoing document's revision, even a nonediting switch. - let other_revision = u.app.session.docs.iter().find(|d| d.uid == other_uid).unwrap().revision; - assert_eq!(other_revision, before_switch_revision + 1, "the setup switch advances only B's command revision"); - let asked = std::rc::Rc::new(std::cell::Cell::new(0)); - u.app.services = Box::new(SaveAsPicker { path: Some(copy.clone()), asked: asked.clone() }); - let output = u.frame_output(vec![]); - let nodes = output.platform_output.accesskit_update.unwrap().nodes; - let tab = nodes - .iter() - .map(|(_, node)| node) - .find(|node| node.role() == Role::Tab && node.label() == Some(other_name.as_str())) - .expect("the actual B tab"); - let bounds = tab.bounds().unwrap(); - let tab_at = pos2(((bounds.x0 + bounds.x1) / 2.0) as f32, ((bounds.y0 + bounds.y1) / 2.0) as f32); - let (at, _) = field(&mut u, "X"); - click(&mut u, at); - assert_eq!(u.ctx.memory(|m| m.focused()), Some(Id::unique("pos_x").with("te"))); - assert!(u.ctx.text_edit_focused()); - u.frame(vec![Event::Text("77".into())]); - assert_eq!(u.ctx.data(|d| d.get_temp::(Id::unique("pos_x").with("editing"))), Some("77".into())); - assert_eq!(geom(&u, a).0, 10.0, "A's raw draft is not committed yet"); - assert_eq!(u.app.session.ds().unwrap().uid, owner, "the save begins with A presented"); - let reply = if route == "control" { - let (reply, rx) = std::sync::mpsc::channel(); - u.app.control_queue.push(crate::ControlRequest { - id: json!("same-pass-switch"), - method: "engine.execute".into(), - params: json!({"command": "doc.switch", "params": {"index": other_index}, "window": 0}), - reply, - cancelled: Default::default(), - }); - Some(rx) - } else { - None - }; - let mut modifiers = if cfg!(target_os = "macos") { Modifiers::COMMAND } else { Modifiers::COMMAND.plus(Modifiers::CTRL) }; - if save_as { - modifiers = modifiers.plus(Modifiers::SHIFT); - } - let mut events = vec![ - Event::Key { key: Key::S, physical_key: Some(Key::S), pressed: true, repeat: false, modifiers }, - Event::Key { key: Key::S, physical_key: Some(Key::S), pressed: false, repeat: false, modifiers }, - ]; - if route == "tab" { - events.push(Event::PointerMoved(tab_at)); - for pressed in [true, false] { - events.push(Event::PointerButton { - pos: tab_at, - button: egui::PointerButton::Primary, - pressed, - modifiers: Default::default(), - }); - } - } - if discard { - events.insert(0, Event::ModifiersChanged(modifiers)); - u.frame_raw_with_discard(egui::RawInput { events, ..Default::default() }); - } else { - u.frame_with(events, modifiers); - } - if let Some(reply) = reply { - let reply = reply.try_recv().expect("real control::drain acknowledged doc.switch in this pass"); - assert!(reply.result.is_ok(), "{:?}", reply.result); - } - let unchanged = |u: &Ui| { - assert_eq!(u.app.session.ds().unwrap().uid, other_uid, "the real same-pass route presents B"); - assert_eq!( - geom(u, b), - (200.0, 40.0, 30.0, 30.0), - "A's draft cannot enter B's field: route={route}, save_as={save_as}, discard={discard}" - ); - assert!(std::sync::Arc::ptr_eq(&u.app.session.ds().unwrap().doc, &other_model), "B's model is untouched"); - assert_eq!(u.app.session.ds().unwrap().revision, other_revision); - assert_eq!(u.app.session.undo_depth(), other_history, "B's undo/redo history is unchanged"); - assert_eq!(u.app.session.ds().unwrap().selection, other_selection); - assert_eq!(u.app.session.ds().unwrap().is_dirty(), other_dirty); - assert_eq!(std::fs::read(&other).unwrap(), other_bytes); - assert_eq!(std::fs::read(&path).unwrap(), owner_bytes); - assert_eq!(u.app.session.docs.iter().find(|d| d.uid == owner).unwrap().doc.world_bounds(a).unwrap().x0, 10.0); - assert_eq!(asked.get(), 0, "the cancelled request never asks for a path"); - assert!(!copy.exists()); - assert!(u.app.ui.after_field.is_none(), "cancel before late fallback or queueing"); - }; - unchanged(&u); - for _ in 0..3 { - u.frame(vec![]); - unchanged(&u); - } - // A cancelled draft is not a permanent veto: B accepts a later real field edit - // and saves its own value through the same focused-field shortcut path. - let (at, _) = field(&mut u, "X"); - click(&mut u, at); - assert_eq!(u.ctx.memory(|m| m.focused()), Some(Id::unique("pos_x").with("te"))); - u.frame(vec![Event::Text("88".into())]); - assert_eq!(geom(&u, b).0, 200.0, "fresh B text still waits for a normal commit"); - assert_eq!(u.ctx.data(|d| d.get_temp::(Id::unique("pos_x").with("editing"))), Some("88".into())); - u.frame_with( - vec![ - Event::Key { key: Key::S, physical_key: Some(Key::S), pressed: true, repeat: false, modifiers }, - Event::Key { key: Key::S, physical_key: Some(Key::S), pressed: false, repeat: false, modifiers }, - ], - modifiers, - ); - assert_eq!(geom(&u, b).0, 88.0, "a fresh B field commits normally"); - assert!(u.app.ui.after_field.is_some()); - for _ in 0..3 { - u.frame(vec![]); - } - assert_eq!(u.app.session.ds().unwrap().uid, other_uid); - assert_eq!(saved_x(if save_as { © } else { &other }, b), 88.0, "a later valid save belongs to B"); - if save_as { - assert_eq!(std::fs::read(&other).unwrap(), other_bytes); - } - assert_eq!(std::fs::read(&path).unwrap(), owner_bytes, "A stays unsaved"); - assert_eq!(asked.get(), usize::from(save_as)); - assert!(u.app.ui.after_field.is_none()); - std::fs::remove_dir_all(&dir).ok(); + prepared_save_cannot_enter_a_replacement(route, save_as, discard); } } } } + +/// One route/save-as/discard combination of the same-pass replacement test: a save prepared for A +/// must not commit A's cached X editor into B when routing presents B before the fields draw, +/// even though both panels use the same widget ID. +fn prepared_save_cannot_enter_a_replacement(route: &str, save_as: bool, discard: bool) { + let (mut u, a, _) = setup(); + let dir = std::env::temp_dir().join(format!("figcraft-field-save-owner-{}-{route}-{save_as}-{discard}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let (path, other, copy) = (dir.join("a.figcraft"), dir.join("b.figcraft"), dir.join("copy.figcraft")); + u.app.session.execute("file.saveAs", &json!({"path": path.to_string_lossy()})).unwrap(); + let owner = u.app.session.ds().unwrap().uid; + let owner_bytes = std::fs::read(&path).unwrap(); + u.app.session.execute("file.new", &json!({"name": "Same-pass B"})).unwrap(); + let b = id(u.app.session.execute("shape.rectangle", &json!({"x": 200, "y": 40, "width": 30, "height": 30})).unwrap()); + u.app.session.execute("file.saveAs", &json!({"path": other.to_string_lossy()})).unwrap(); + u.app.session.execute("shape.rectangle", &json!({"x": 300, "y": 0, "width": 10, "height": 10})).unwrap(); + u.app.session.execute("select.set", &json!({"ids": [b]})).unwrap(); + let other_index = u.app.session.active; + let other_uid = u.app.session.ds().unwrap().uid; + let other_name = u.app.session.doc().unwrap().name.clone(); + let other_model = u.app.session.ds().unwrap().doc.clone(); + let before_switch_revision = u.app.session.ds().unwrap().revision; + let other_history = u.app.session.undo_depth(); + let other_selection = u.app.session.ds().unwrap().selection.clone(); + let other_dirty = u.app.session.ds().unwrap().is_dirty(); + let other_bytes = std::fs::read(&other).unwrap(); + assert!(other_dirty, "B has independent unsaved content"); + let owner_index = u.app.session.docs.iter().position(|d| d.uid == owner).unwrap(); + u.app.session.execute("doc.switch", &json!({"index": owner_index})).unwrap(); + // Every command bumps the outgoing document's revision, even a nonediting switch. + let other_revision = u.app.session.docs.iter().find(|d| d.uid == other_uid).unwrap().revision; + assert_eq!(other_revision, before_switch_revision + 1, "the setup switch advances only B's command revision"); + let asked = std::rc::Rc::new(std::cell::Cell::new(0)); + u.app.services = Box::new(SaveAsPicker { path: Some(copy.clone()), asked: asked.clone() }); + let output = u.frame_output(vec![]); + let nodes = output.platform_output.accesskit_update.unwrap().nodes; + let tab = nodes + .iter() + .map(|(_, node)| node) + .find(|node| node.role() == Role::Tab && node.label() == Some(other_name.as_str())) + .expect("the actual B tab"); + let bounds = tab.bounds().unwrap(); + let tab_at = pos2(((bounds.x0 + bounds.x1) / 2.0) as f32, ((bounds.y0 + bounds.y1) / 2.0) as f32); + let (at, _) = field(&mut u, "X"); + click(&mut u, at); + assert_eq!(u.ctx.memory(|m| m.focused()), Some(Id::unique("pos_x").with("te"))); + assert!(u.ctx.text_edit_focused()); + u.frame(vec![Event::Text("77".into())]); + assert_eq!(u.ctx.data(|d| d.get_temp::(Id::unique("pos_x").with("editing"))), Some("77".into())); + assert_eq!(geom(&u, a).0, 10.0, "A's raw draft is not committed yet"); + assert_eq!(u.app.session.ds().unwrap().uid, owner, "the save begins with A presented"); + let reply = if route == "control" { + let (reply, rx) = std::sync::mpsc::channel(); + u.app.control_queue.push(crate::ControlRequest { + id: json!("same-pass-switch"), + method: "engine.execute".into(), + params: json!({"command": "doc.switch", "params": {"index": other_index}, "window": 0}), + reply, + cancelled: Default::default(), + }); + Some(rx) + } else { + None + }; + let mut modifiers = if cfg!(target_os = "macos") { Modifiers::COMMAND } else { Modifiers::COMMAND.plus(Modifiers::CTRL) }; + if save_as { + modifiers = modifiers.plus(Modifiers::SHIFT); + } + let mut events = vec![ + Event::Key { key: Key::S, physical_key: Some(Key::S), pressed: true, repeat: false, modifiers }, + Event::Key { key: Key::S, physical_key: Some(Key::S), pressed: false, repeat: false, modifiers }, + ]; + if route == "tab" { + events.push(Event::PointerMoved(tab_at)); + for pressed in [true, false] { + events.push(Event::PointerButton { pos: tab_at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }); + } + } + if discard { + events.insert(0, Event::ModifiersChanged(modifiers)); + u.frame_raw_with_discard(egui::RawInput { events, ..Default::default() }); + } else { + u.frame_with(events, modifiers); + } + if let Some(reply) = reply { + let reply = reply.try_recv().expect("real control::drain acknowledged doc.switch in this pass"); + assert!(reply.result.is_ok(), "{:?}", reply.result); + } + let unchanged = |u: &Ui| { + assert_eq!(u.app.session.ds().unwrap().uid, other_uid, "the real same-pass route presents B"); + assert_eq!(geom(u, b), (200.0, 40.0, 30.0, 30.0), "A's draft cannot enter B's field: route={route}, save_as={save_as}, discard={discard}"); + assert!(std::sync::Arc::ptr_eq(&u.app.session.ds().unwrap().doc, &other_model), "B's model is untouched"); + assert_eq!(u.app.session.ds().unwrap().revision, other_revision); + assert_eq!(u.app.session.undo_depth(), other_history, "B's undo/redo history is unchanged"); + assert_eq!(u.app.session.ds().unwrap().selection, other_selection); + assert_eq!(u.app.session.ds().unwrap().is_dirty(), other_dirty); + assert_eq!(std::fs::read(&other).unwrap(), other_bytes); + assert_eq!(std::fs::read(&path).unwrap(), owner_bytes); + assert_eq!(u.app.session.docs.iter().find(|d| d.uid == owner).unwrap().doc.world_bounds(a).unwrap().x0, 10.0); + assert_eq!(asked.get(), 0, "the cancelled request never asks for a path"); + assert!(!copy.exists()); + assert!(u.app.ui.after_field.is_none(), "cancel before late fallback or queueing"); + }; + unchanged(&u); + for _ in 0..3 { + u.frame(vec![]); + unchanged(&u); + } + // A cancelled draft is not a permanent veto: B accepts a later real field edit + // and saves its own value through the same focused-field shortcut path. + let (at, _) = field(&mut u, "X"); + click(&mut u, at); + assert_eq!(u.ctx.memory(|m| m.focused()), Some(Id::unique("pos_x").with("te"))); + u.frame(vec![Event::Text("88".into())]); + assert_eq!(geom(&u, b).0, 200.0, "fresh B text still waits for a normal commit"); + assert_eq!(u.ctx.data(|d| d.get_temp::(Id::unique("pos_x").with("editing"))), Some("88".into())); + u.frame_with( + vec![ + Event::Key { key: Key::S, physical_key: Some(Key::S), pressed: true, repeat: false, modifiers }, + Event::Key { key: Key::S, physical_key: Some(Key::S), pressed: false, repeat: false, modifiers }, + ], + modifiers, + ); + assert_eq!(geom(&u, b).0, 88.0, "a fresh B field commits normally"); + assert!(u.app.ui.after_field.is_some()); + for _ in 0..3 { + u.frame(vec![]); + } + assert_eq!(u.app.session.ds().unwrap().uid, other_uid); + assert_eq!(saved_x(if save_as { © } else { &other }, b), 88.0, "a later valid save belongs to B"); + if save_as { + assert_eq!(std::fs::read(&other).unwrap(), other_bytes); + } + assert_eq!(std::fs::read(&path).unwrap(), owner_bytes, "A stays unsaved"); + assert_eq!(asked.get(), usize::from(save_as)); + assert!(u.app.ui.after_field.is_none()); + std::fs::remove_dir_all(&dir).ok(); +} diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index 9aa72c12..2abb1cfc 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -674,153 +674,185 @@ fn text_keys(app: &mut FigApp, ctx: &Context, events: &[Event], ime_input: Optio } match ev { Event::Text(t) => { - if skip_text { - skip_text = false; - continue; - } - let before = ime_stamp(app); - if let Err(e) = figcraft_engine::textedit::insert(&mut app.session, t) { - app.toast(e.to_string()); - } - if ime_stamp(app) != before { - note_ime_application_change(app, ctx); + if !std::mem::take(&mut skip_text) { + insert_text(app, ctx, t); } } - // An accepted IME commit earns an explicit receipt only around the exact mutation. - // List AutoFormat inside the same command is an application transformation. - Event::Ime(egui::ImeEvent::Commit(t)) => { - let before = ime_stamp(app); - match figcraft_engine::textedit::insert_ime_commit(&mut app.session, t) { - Ok(ImeInsertion::Plain) => ime_receipt(app, ctx, before), - Ok(ImeInsertion::Transformed) => note_ime_application_change(app, ctx), - Ok(ImeInsertion::Nothing) => {} - Err(e) => app.toast(e.to_string()), - } - } - // The composition shows inline at the caret; the document gets it on Commit. - Event::Ime(egui::ImeEvent::Preedit { text, active_range_chars }) => { - let cursor = active_range_chars.as_ref().map(|r| r.start); - if let Err(e) = figcraft_engine::textedit::preedit(&mut app.session, text, cursor) { - app.toast(e.to_string()); - } - } - // An IME replacing text around the caret (0.37's incoming byte-counted deletion) - // deletes it before the paired Commit inserts the replacement. - Event::Ime(egui::ImeEvent::DeleteSurroundingBytes { before_bytes, after_bytes }) => { - let before = ime_stamp(app); - match figcraft_engine::textedit::delete_surrounding_bytes(&mut app.session, *before_bytes, *after_bytes) { - Ok(true) => ime_receipt(app, ctx, before), - Ok(false) => {} - Err(e) => app.toast(e.to_string()), - } - } - Event::Ime(egui::ImeEvent::DeleteSurrounding { before_chars, after_chars }) => { - let before = ime_stamp(app); - match figcraft_engine::textedit::delete_surrounding_chars(&mut app.session, *before_chars, *after_chars) { - Ok(true) => ime_receipt(app, ctx, before), - Ok(false) => {} - Err(e) => app.toast(e.to_string()), - } - } - Event::Paste(t) => { - // Plain text only: the engine normalises line endings and drops control chars. - let before = ime_stamp(app); - if let Err(e) = figcraft_engine::textedit::insert(&mut app.session, t) { - app.toast(e.to_string()); - } - if ime_stamp(app) != before { - note_ime_application_change(app, ctx); - } - } - Event::Copy | Event::Cut => { - let before = ime_stamp(app); - let selected = figcraft_engine::textedit::selected_text(&app.session).filter(|t| !t.is_empty()); - // Input injected through the control channel must never read or replace the user's - // system clipboard. It may still edit the document: a synthetic Cut deletes the - // selection exactly like a user's Cut; only the OS clipboard write is fenced. - if !app.control_synthetic - && let Some(text) = &selected - { - app.clipboard_set_text(text); - } - if matches!(ev, Event::Cut) && selected.is_some() { - let _ = figcraft_engine::textedit::key(&mut app.session, "Delete", false, false, false); - } - if ime_stamp(app) != before { - note_ime_application_change(app, ctx); - } - } - Event::Key { key, physical_key, pressed: true, modifiers: m, .. } => { - // Keys during a composition are the IME's (Enter picks a candidate, Escape cancels). - if app.session.ds().is_ok_and(|d| d.text_edit.as_ref().is_some_and(|te| te.preedit.is_some())) { - continue; - } - if m.command || m.alt || m.ctrl { - let before = ime_stamp(app); - if text_shortcut(app, *key, *physical_key, *m) { - // A text shortcut that changed the committed text/selection (a list, - // Bold, alignment) is an application edit; Save and friends are not. - if ime_stamp(app) != before { - note_ime_application_change(app, ctx); - } - skip_text = true; - continue; - } - } - let name = match key { - Key::Backspace => "Backspace", - Key::Delete => "Delete", - Key::ArrowLeft => "Left", - Key::ArrowRight => "Right", - Key::ArrowUp => "Up", - Key::ArrowDown => "Down", - Key::Home => "Home", - Key::End => "End", - Key::Enter => "Enter", - Key::Escape => "Escape", - Key::Tab => "Tab", - Key::A if m.command => "SelectAll", - Key::Z if m.command => { - note_ime_application_change(app, ctx); - let _ = figcraft_engine::textedit::end(&mut app.session); - app.run(if m.shift { "edit.redo" } else { "edit.undo" }, json!({})); - continue; - } - _ => continue, - }; - if name == "Enter" && m.command { - let _ = figcraft_engine::textedit::end(&mut app.session); - continue; - } - let before = ime_stamp(app); - let (word, line) = keymap::text_motion(platform(), name, mods(*m)); - if let Err(e) = figcraft_engine::textedit::key(&mut app.session, name, m.shift, word, line) { - app.toast(e.to_string()); - } - if ime_stamp(app) != before { - note_ime_application_change(app, ctx); - } + Event::Ime(ime) => ime_event(app, ctx, ime), + Event::Paste(t) => insert_text(app, ctx, t), + Event::Copy => copy_or_cut(app, ctx, false), + Event::Cut => copy_or_cut(app, ctx, true), + Event::Key { key, physical_key, pressed: true, modifiers: m, .. } if text_key_event(app, ctx, *key, *physical_key, *m) => { + skip_text = true; } _ => {} } } // Triple-click on the edited text selects its line (double-click is handled by the engine). - if ctx.input(|i| i.pointer.button_triple_clicked(egui::PointerButton::Primary)) - && let Some(pos) = ctx.input(|i| i.pointer.interact_pos()) - && app.canvas.rect.contains(pos) - && let Some(te) = app.session.ds().ok().and_then(|d| d.text_edit.clone()) - { - let p = app.to_page(pos); - let inside = app.session.doc().ok().and_then(|d| d.world_bounds(te.id)).is_some_and(|b| b.contains(p)); - if inside && let Ok(idx) = app.session.text_index_at(te.id, p) { + triple_click_line(app, ctx); + app.sync_preedit(); +} + +/// Insert plain text (the engine normalises line endings and drops control chars) into the edit, +/// noting the application change the mutation caused. +fn insert_text(app: &mut FigApp, ctx: &Context, t: &str) { + let before = ime_stamp(app); + if let Err(e) = figcraft_engine::textedit::insert(&mut app.session, t) { + app.toast(e.to_string()); + } + if ime_stamp(app) != before { + note_ime_application_change(app, ctx); + } +} + +/// An IME commit, preedit or surrounding-text deletion for the edit. +fn ime_event(app: &mut FigApp, ctx: &Context, ev: &egui::ImeEvent) { + match ev { + // An accepted IME commit earns an explicit receipt only around the exact mutation. + // List AutoFormat inside the same command is an application transformation. + egui::ImeEvent::Commit(t) => { let before = ime_stamp(app); - app.run("text.edit.selectLine", json!({"index": idx})); + match figcraft_engine::textedit::insert_ime_commit(&mut app.session, t) { + Ok(ImeInsertion::Plain) => ime_receipt(app, ctx, before), + Ok(ImeInsertion::Transformed) => note_ime_application_change(app, ctx), + Ok(ImeInsertion::Nothing) => {} + Err(e) => app.toast(e.to_string()), + } + } + // The composition shows inline at the caret; the document gets it on Commit. + egui::ImeEvent::Preedit { text, active_range_chars } => { + let cursor = active_range_chars.as_ref().map(|r| r.start); + if let Err(e) = figcraft_engine::textedit::preedit(&mut app.session, text, cursor) { + app.toast(e.to_string()); + } + } + // An IME replacing text around the caret (0.37's incoming byte-counted deletion) + // deletes it before the paired Commit inserts the replacement. + egui::ImeEvent::DeleteSurroundingBytes { before_bytes, after_bytes } => { + let before = ime_stamp(app); + match figcraft_engine::textedit::delete_surrounding_bytes(&mut app.session, *before_bytes, *after_bytes) { + Ok(true) => ime_receipt(app, ctx, before), + Ok(false) => {} + Err(e) => app.toast(e.to_string()), + } + } + egui::ImeEvent::DeleteSurrounding { before_chars, after_chars } => { + let before = ime_stamp(app); + match figcraft_engine::textedit::delete_surrounding_chars(&mut app.session, *before_chars, *after_chars) { + Ok(true) => ime_receipt(app, ctx, before), + Ok(false) => {} + Err(e) => app.toast(e.to_string()), + } + } + // Legacy Enabled/Disabled events were ignored by the original event dispatcher too. + _ => {} + } +} + +/// Copy or cut the edit's selection. Input injected through the control channel must never read +/// or replace the user's system clipboard; it may still edit the document: a synthetic Cut +/// deletes the selection exactly like a user's Cut; only the OS clipboard write is fenced. +fn copy_or_cut(app: &mut FigApp, ctx: &Context, cut: bool) { + let before = ime_stamp(app); + let selected = figcraft_engine::textedit::selected_text(&app.session).filter(|t| !t.is_empty()); + if !app.control_synthetic + && let Some(text) = &selected + { + app.clipboard_set_text(text); + } + if cut && selected.is_some() { + let _ = figcraft_engine::textedit::key(&mut app.session, "Delete", false, false, false); + } + if ime_stamp(app) != before { + note_ime_application_change(app, ctx); + } +} + +/// A text-editing key press. `true` when it ran a shortcut, whose following Text event is +/// swallowed (a shortcut that changed committed text/selection is also an application edit). +fn text_key_event(app: &mut FigApp, ctx: &Context, key: Key, physical: Option, m: Modifiers) -> bool { + // Keys during a composition are the IME's (Enter picks a candidate, Escape cancels). + if app.session.ds().is_ok_and(|d| d.text_edit.as_ref().is_some_and(|te| te.preedit.is_some())) { + return false; + } + if m.command || m.alt || m.ctrl { + let before = ime_stamp(app); + if text_shortcut(app, key, physical, m) { + // A text shortcut that changed the committed text/selection (a list, + // Bold, alignment) is an application edit; Save and friends are not. if ime_stamp(app) != before { note_ime_application_change(app, ctx); } + return true; } } - app.sync_preedit(); + if key == Key::Z && m.command { + note_ime_application_change(app, ctx); + let _ = figcraft_engine::textedit::end(&mut app.session); + app.run(if m.shift { "edit.redo" } else { "edit.undo" }, json!({})); + return false; + } + let Some(name) = text_key_name(key, m.command) else { return false }; + if name == "Enter" && m.command { + let _ = figcraft_engine::textedit::end(&mut app.session); + return false; + } + let before = ime_stamp(app); + let (word, line) = keymap::text_motion(platform(), name, mods(m)); + if let Err(e) = figcraft_engine::textedit::key(&mut app.session, name, m.shift, word, line) { + app.toast(e.to_string()); + } + if ime_stamp(app) != before { + note_ime_application_change(app, ctx); + } + false +} + +/// The text-edit command a named key runs, if any. +fn text_key_name(key: Key, command: bool) -> Option<&'static str> { + Some(match key { + Key::Backspace => "Backspace", + Key::Delete => "Delete", + Key::ArrowLeft => "Left", + Key::ArrowRight => "Right", + Key::ArrowUp => "Up", + Key::ArrowDown => "Down", + Key::Home => "Home", + Key::End => "End", + Key::Enter => "Enter", + Key::Escape => "Escape", + Key::Tab => "Tab", + Key::A if command => "SelectAll", + _ => return None, + }) +} + +/// Triple-click on the edited text selects its line (double-click is handled by the engine). +fn triple_click_line(app: &mut FigApp, ctx: &Context) { + if !ctx.input(|i| i.pointer.button_triple_clicked(egui::PointerButton::Primary)) { + return; + } + let Some(pos) = ctx.input(|i| i.pointer.interact_pos()).filter(|pos| app.canvas.rect.contains(*pos)) else { + return; + }; + let Some(te) = app.session.ds().ok().and_then(|d| d.text_edit.clone()) else { return }; + let p = app.to_page(pos); + if let Some(idx) = text_line_index(app, te.id, p) { + let before = ime_stamp(app); + app.run("text.edit.selectLine", json!({"index": idx})); + if ime_stamp(app) != before { + note_ime_application_change(app, ctx); + } + } +} + +/// The text index of the line under `p`, when the edit's node contains it. +fn text_line_index(app: &FigApp, id: figcraft_doc::NodeId, p: figcraft_geom::Point) -> Option { + let inside = app.session.doc().ok().and_then(|d| d.world_bounds(id)).is_some_and(|b| b.contains(p)); + if !inside { + return None; + } + app.session.text_index_at(id, p).ok() } /// Shortcuts live while editing text (Bold, lists, alignment, size/weight/spacing steps, Save…). From fc344de33c33e52baff87d348186fd468cafcdde Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Sun, 25 Oct 2026 08:10:37 +0100 Subject: [PATCH 28/50] M0: correct the migration qualification reference --- docs/egui-037-migration-plan.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/egui-037-migration-plan.md b/docs/egui-037-migration-plan.md index 6b8c5059..6cf1bb09 100644 --- a/docs/egui-037-migration-plan.md +++ b/docs/egui-037-migration-plan.md @@ -1189,8 +1189,9 @@ validation and generates the lockfile from its local dependency config. ## Historical local qualification — 2026-10-25 The following counts apply to the earlier `10702311` integration, not the later -`2a3b7d4f` qualification in the status update above. The intervening `9f788753` -refresh passed 3,247 executions; the runs listed below passed 3,242. +`2a3b7d4f` qualification documented in `docs/egui-037-local-followups.md`. The +status update above covers the subsequent `92682728` integration. The intervening +`9f788753` refresh passed 3,247 executions; the runs listed below passed 3,242. The migration preserves captured main `10702311f345393ee1d8868c3257679befcfa14d` (53 commits and 114 paths beyond the first integration). The final review commit records From a107e62bcc283d837109a20d9e40202acad97b7c Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sun, 25 Oct 2026 12:13:55 +0100 Subject: [PATCH 29/50] Fix missing end arrowhead when a closed subpath follows an open one Found while testing crates/pathops/src/points.rs:89-92 (Styled::arrowheads) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/pathops/src/lib.rs | 23 +++++++++++++++++++++++ crates/pathops/src/points.rs | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/pathops/src/lib.rs b/crates/pathops/src/lib.rs index f4b30e10..1d6dd999 100644 --- a/crates/pathops/src/lib.rs +++ b/crates/pathops/src/lib.rs @@ -693,6 +693,29 @@ mod tests { assert_ne!(explicit, layer_only); } + #[test] + fn layer_end_arrow_is_drawn_when_a_closed_run_follows_the_open_one() { + let verts = [(0.0, 0.0), (50.0, 0.0), (0.0, 100.0), (50.0, 100.0), (25.0, 150.0)]; + let net = VectorNetwork { + vertices: verts + .iter() + .enumerate() + .map(|(i, &(x, y))| figcraft_doc::Vertex { cap: (i == 0).then_some(StrokeCap::Round), ..figcraft_doc::Vertex::new(x, y) }) + .collect(), + segments: vec![ + figcraft_doc::Segment::line(0, 1), + figcraft_doc::Segment::line(2, 3), + figcraft_doc::Segment::line(3, 4), + figcraft_doc::Segment::line(4, 2), + ], + ..Default::default() + }; + let path = BezPath::new(); + let plain = StrokeProps { weight: 2.0, ..Default::default() }; + let arrow = StrokeProps { cap_end: StrokeCap::TriangleArrow, ..plain.clone() }; + assert_ne!(stroke_outline_of(&path, &arrow, false, Some(&net)), stroke_outline_of(&path, &plain, false, Some(&net))); + } + #[test] fn equal_joins_do_not_break_closed_stroke_runs() { let path = sq(0.0, 0.0, 20.0); diff --git a/crates/pathops/src/points.rs b/crates/pathops/src/points.rs index 05f58216..650f309f 100644 --- a/crates/pathops/src/points.rs +++ b/crates/pathops/src/points.rs @@ -86,8 +86,8 @@ impl Styled { /// and last end (as without point styles). pub(crate) fn arrowheads(&self, weight: f64, props: &StrokeProps) -> BezPath { let mut out = BezPath::new(); - let last = self.runs.len().saturating_sub(1); - for (k, run) in self.runs.iter().enumerate().filter(|(_, r)| !r.closed) { + let last = self.runs.iter().filter(|r| !r.closed).count().saturating_sub(1); + for (k, run) in self.runs.iter().filter(|r| !r.closed).enumerate() { let start = self.cap_at(run.start, if k == 0 { props.cap_start } else { StrokeCap::None }); let end = self.cap_at(run.end, if k == last { props.cap_end } else { StrokeCap::None }); for (at_end, cap) in [(false, start), (true, end)] { From b751271c2ac0588a13a67781e7bae8dfc1023202 Mon Sep 17 00:00:00 2001 From: skylar taylor-barrick Date: Sun, 25 Oct 2026 14:52:12 +0100 Subject: [PATCH 30/50] M-egui037: document input lifecycle and UI regression contracts --- apps/figcraft-web/src/web.rs | 3 ++ apps/figcraft/src/control_server.rs | 3 ++ apps/figcraft/src/control_server_tests.rs | 9 ++++ apps/figcraft/src/main.rs | 3 ++ crates/collab-net/src/sessions_tests.rs | 3 ++ crates/engine/src/cmd/edit.rs | 4 ++ crates/engine/src/text_behaviour_tests.rs | 5 +++ crates/engine/src/textedit.rs | 32 +++++++++++++ crates/engine/src/textfit_tests.rs | 2 + crates/engine/src/tools.rs | 4 ++ crates/text/build.rs | 21 +++++++++ crates/ui-egui/src/a11y.rs | 2 + crates/ui-egui/src/a11y_tests.rs | 2 + crates/ui-egui/src/assets_panel.rs | 13 ++++++ crates/ui-egui/src/canvas.rs | 4 ++ crates/ui-egui/src/clipboard_fence_tests.rs | 16 +++++++ crates/ui-egui/src/colorpicker.rs | 9 ++++ crates/ui-egui/src/control.rs | 13 ++++++ crates/ui-egui/src/control_capture_tests.rs | 45 +++++++++++++++++++ crates/ui-egui/src/credits_tests.rs | 2 + crates/ui-egui/src/dialogs.rs | 4 ++ crates/ui-egui/src/field_tests.rs | 9 ++++ crates/ui-egui/src/frame_labels.rs | 3 ++ crates/ui-egui/src/frame_presets.rs | 2 + crates/ui-egui/src/guides.rs | 1 + crates/ui-egui/src/handles.rs | 1 + crates/ui-egui/src/home.rs | 4 ++ crates/ui-egui/src/idle_tests.rs | 7 +++ crates/ui-egui/src/ime_tests.rs | 42 +++++++++++++++++ crates/ui-egui/src/layers.rs | 8 ++++ crates/ui-egui/src/layers_behaviour_tests.rs | 3 ++ crates/ui-egui/src/layers_rename_tests.rs | 2 + crates/ui-egui/src/layout_panel.rs | 2 + crates/ui-egui/src/lib.rs | 10 +++++ crates/ui-egui/src/live_join_tests.rs | 1 + crates/ui-egui/src/live_server_tests.rs | 1 + crates/ui-egui/src/live_share_tests.rs | 5 +++ crates/ui-egui/src/live_tests.rs | 2 + crates/ui-egui/src/menu_aim_tests.rs | 3 ++ crates/ui-egui/src/menu_input_tests.rs | 2 + crates/ui-egui/src/menus.rs | 6 +++ crates/ui-egui/src/panel_remove_tests.rs | 5 +++ crates/ui-egui/src/panel_reorder_tests.rs | 2 + crates/ui-egui/src/perf_tests.rs | 3 ++ crates/ui-egui/src/plugin_panel_tests.rs | 3 ++ crates/ui-egui/src/plugins_ui.rs | 5 +++ crates/ui-egui/src/present_tests.rs | 2 + crates/ui-egui/src/present_view_tests.rs | 3 ++ crates/ui-egui/src/proto_canvas.rs | 3 ++ crates/ui-egui/src/proto_editor.rs | 1 + crates/ui-egui/src/proto_editor_tests.rs | 5 +++ crates/ui-egui/src/proto_panel.rs | 10 +++++ crates/ui-egui/src/proto_reorder_tests.rs | 1 + crates/ui-egui/src/right.rs | 18 ++++++++ crates/ui-egui/src/rtl_names_tests.rs | 11 +++++ crates/ui-egui/src/section_panel.rs | 3 ++ crates/ui-egui/src/select_all_tests.rs | 6 +++ crates/ui-egui/src/selection_colors.rs | 10 +++++ crates/ui-egui/src/selection_spacing.rs | 6 +++ crates/ui-egui/src/selection_spacing_tests.rs | 3 ++ crates/ui-egui/src/shortcuts.rs | 11 +++++ crates/ui-egui/src/style_picker_tests.rs | 2 + crates/ui-egui/src/tabs.rs | 2 + crates/ui-egui/src/theme.rs | 2 + crates/ui-egui/src/theme_startup_tests.rs | 2 + crates/ui-egui/src/titlebar_tests.rs | 2 + crates/ui-egui/src/toolbar.rs | 3 ++ crates/ui-egui/src/type_settings_tests.rs | 2 + crates/ui-egui/src/typography.rs | 5 +++ crates/ui-egui/src/typography_scrub_tests.rs | 3 ++ crates/ui-egui/src/variable_ui.rs | 1 + crates/ui-egui/src/variables_panel.rs | 9 ++++ crates/ui-egui/src/vector_panel.rs | 2 + crates/ui-egui/src/versions.rs | 2 + crates/ui-egui/src/widgets.rs | 3 ++ crates/ui-egui/src/windows_tests.rs | 14 ++++++ 76 files changed, 478 insertions(+) diff --git a/apps/figcraft-web/src/web.rs b/apps/figcraft-web/src/web.rs index 802d229a..40451d43 100644 --- a/apps/figcraft-web/src/web.rs +++ b/apps/figcraft-web/src/web.rs @@ -71,6 +71,9 @@ struct WebShell { impl eframe::App for WebShell { // eframe runs `logic` for visible tabs and, with only `run_logic`, for hidden ones: keep // autosave/live/control deadlines moving without a paint. `FigApp::ui` does not repeat it. + /// Run the browser shell's eframe logic callback: guard `background_tick` so hidden tabs + /// still advance autosave, live and control deadlines without painting. `FigApp::ui` does + /// not repeat it. fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { figcraft_ui_egui::windows::guard(&mut self.fig, ctx, |fig| fig.background_tick(ctx)); } diff --git a/apps/figcraft/src/control_server.rs b/apps/figcraft/src/control_server.rs index 2af5610d..ada44c0f 100644 --- a/apps/figcraft/src/control_server.rs +++ b/apps/figcraft/src/control_server.rs @@ -97,6 +97,9 @@ fn spawn_connection(stream: TcpStream, queue: Queue, ctx: CtxSlot, workers: &mut } } +/// Serve one control connection: read bounded JSON lines, reject oversized frames and a +/// full queue, queue one request, wait under its gate, and write one reply. Non-JSON input +/// answers with an error and closes the connection so HTTP body lines cannot become commands. fn serve(mut out: TcpStream, queue: Queue, ctx: CtxSlot, timeout: Duration) -> std::io::Result<()> { out.set_read_timeout(Some(timeout))?; out.set_write_timeout(Some(timeout))?; diff --git a/apps/figcraft/src/control_server_tests.rs b/apps/figcraft/src/control_server_tests.rs index 6144cdf3..f29a7773 100644 --- a/apps/figcraft/src/control_server_tests.rs +++ b/apps/figcraft/src/control_server_tests.rs @@ -28,6 +28,7 @@ fn reply(reader: &mut BufReader) -> Value { serde_json::from_str(&line).unwrap() } +/// Build a `ui.inspect` control request with a throwaway reply channel. fn request() -> ControlRequest { ControlRequest { id: json!(0), method: "ui.inspect".into(), params: json!({}), reply: mpsc::channel().0, state: Default::default() } } @@ -115,6 +116,8 @@ fn full_queue_rejects_before_dispatch_and_ui_queue_stays_bounded() { worker.join().unwrap().unwrap(); } +/// Asserts a commit that writes the file and queues its reply wins the gate: the transport's +/// timeout branch consumes that reply and leaves the state `Replied`. #[test] fn a_committed_reply_wins_over_the_transport_timeout() { let dir = std::env::temp_dir().join(format!("figcraft-control-commit-{}", std::process::id())); @@ -139,6 +142,7 @@ fn a_committed_reply_wins_over_the_transport_timeout() { let _ = std::fs::remove_dir_all(&dir); } +/// Asserts a zero-duration wait reports `Timeout` and cancels the open gate. #[test] fn a_timeout_cancels_an_open_request() { let gate = RequestGate::new(); @@ -147,6 +151,8 @@ fn a_timeout_cancels_an_open_request() { assert_eq!(gate.state(), RequestState::Cancelled, "nothing may write after the timeout"); } +/// Asserts a closed reply channel reports `Disconnected` and leaves the gate `Open`, not +/// cancelled. #[test] fn a_disconnected_reply_channel_is_not_reported_as_a_timeout() { let gate = RequestGate::new(); @@ -268,6 +274,9 @@ fn a_limit_sized_frame_is_accepted_at_eof() { worker.join().unwrap().unwrap(); } +/// Asserts expired requests stop occupying the UI queue cap, a later request is admitted +/// and answered, and a window that finally draws discards its expired command before +/// dispatch. #[test] fn timed_out_requests_release_a_full_deferred_ui_queue() { use figcraft_ui_egui::{FigApp, NoServices, control, windows}; diff --git a/apps/figcraft/src/main.rs b/apps/figcraft/src/main.rs index be380c60..4a1488ad 100644 --- a/apps/figcraft/src/main.rs +++ b/apps/figcraft/src/main.rs @@ -62,6 +62,9 @@ struct App { } impl eframe::App for App { + /// Native eframe logic callback: store the first context, drain control requests, run + /// guarded background work, poll macOS open events, handle close requests and title + /// changes, and schedule recovery repaints on the app clock. fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { { let mut slot = self.ctx_slot.lock().unwrap_or_else(std::sync::PoisonError::into_inner); diff --git a/crates/collab-net/src/sessions_tests.rs b/crates/collab-net/src/sessions_tests.rs index 3c39e4d8..cf569a6d 100644 --- a/crates/collab-net/src/sessions_tests.rs +++ b/crates/collab-net/src/sessions_tests.rs @@ -89,6 +89,9 @@ fn rect(s: &mut Session) -> u64 { s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 40, "height": 30})).unwrap()["id"].as_u64().unwrap() } +/// Asserts two files are hosted and joined independently: each has its own port, session and +/// edits, presence stays in its file's session, and closing one file's session leaves the +/// other live. #[test] fn two_files_are_hosted_and_joined_independently() { let mut host = session("Hana"); diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index 044ae884..38b24ea6 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -601,6 +601,10 @@ pub fn design_clipboard_buffer(html: &str) -> Option> { figcraft_format::fig::is_fig(&bytes).then_some(bytes) } +/// Paste design layers from clipboard HTML or base64 `data`: decode and reject missing, +/// invalid or oversized data, load a temporary `.fig`, take its top-level page layers, +/// store them as a foreign-file clipboard source with a bumped layers generation, then +/// delegate to `paste` and append import warnings. fn paste_design_layers(s: &mut Session, p: &Value) -> Result { const CMD: &str = "edit.pasteDesignLayers"; let bytes = match (string(p, "html"), string(p, "data")) { diff --git a/crates/engine/src/text_behaviour_tests.rs b/crates/engine/src/text_behaviour_tests.rs index d88066cb..8cd8b145 100644 --- a/crates/engine/src/text_behaviour_tests.rs +++ b/crates/engine/src/text_behaviour_tests.rs @@ -134,6 +134,8 @@ fn ime_composition_with_cjk() { assert!(s.ds().unwrap().text_edit.as_ref().unwrap().preedit.is_none()); } +/// Asserts `delete_surrounding_bytes` removes an exact UTF-8 byte range across CJK and a +/// supplementary emoji, leaves nothing past the start, and the whole edit is one undo step. #[test] fn ime_delete_surrounding_bytes_is_exact_and_one_undo_step() { // 0.37's `DeleteSurroundingBytes` counts UTF-8 bytes around the selection, before the paired @@ -156,6 +158,9 @@ fn ime_delete_surrounding_bytes_is_exact_and_one_undo_step() { assert_eq!(chars(&s, t), "ab\u{4F60}\u{597D}c\u{1F600}d", "one undo restores the whole session"); } +/// Asserts a byte range that only partly covers a character leaves it in place, while an +/// exact range deletes it, and a selection survives for the paired commit with its +/// direction preserved. #[test] fn ime_delete_surrounding_bytes_keeps_partial_characters_and_selection() { // The fork deletes the byte range exactly and leaves a character the range only partly diff --git a/crates/engine/src/textedit.rs b/crates/engine/src/textedit.rs index 9c62c331..6551783c 100644 --- a/crates/engine/src/textedit.rs +++ b/crates/engine/src/textedit.rs @@ -69,6 +69,8 @@ pub struct ImeSurrounding { /// A mutex (rather than an atomic) also works on wasm32 targets without 64-bit atomics. static EDITING_SESSION: LazyLock> = LazyLock::new(|| Mutex::new(0)); +/// Return the next editing-session token from a mutex-protected counter (`wrapping_add`). +/// Zero is a valid token; the mutex also works on wasm32 without 64-bit atomics. fn next_editing_session() -> u64 { let mut session = match EDITING_SESSION.lock() { Ok(session) => session, @@ -143,6 +145,9 @@ fn range(te: &TextEdit) -> (usize, usize) { (te.caret.min(te.anchor), te.caret.max(te.anchor)) } +/// Apply an unconditional text-model mutation through `edit_if`, whose success clears the +/// composition, clamps caret and anchor to the character count, marks a `characters` override +/// when the node is source-backed, normalizes the document and bumps the revision. fn edit(s: &mut Session, f: impl FnOnce(&mut TextData, &mut TextEdit)) -> Result<()> { edit_if(s, |t, te| { f(t, te); @@ -230,6 +235,11 @@ pub fn insert_ime_commit(s: &mut Session, text: &str) -> Result { insert_model(s, text, true) } +/// Insert committed text, optionally as an IME commit: normalize line endings, drop control +/// characters except `\n`/`\t`, ignore a bare newline/CR IME commit, clear an active +/// composition for an empty or control-only IME commit, and turn a committed space after a +/// line-start `-`, `*` or `1.` into a bulleted/numbered list. Reports whether the insertion was +/// plain, transformed, or a no-op. fn insert_model(s: &mut Session, text: &str, ime_commit: bool) -> Result { // Stock `TextEdit` deliberately ignores these two commits (they are not a mutation); only a // real commit may do so, since typing Enter goes through `insert`. @@ -894,6 +904,9 @@ mod tests { e } + /// Asserts double-clicking a text layer selects all text, a second double-click selects the + /// word without changing the editing session, and drag and Shift+click extend the + /// selection. #[test] fn pointer_double_click_drag_and_shift_click() { let (mut s, id) = setup("Hello world"); @@ -1132,6 +1145,8 @@ mod tests { } } + /// Asserts surrounding text is logical UTF-8 text with byte offsets and keeps a reversed + /// selection reversed. #[test] fn ime_surrounding_uses_logical_utf8_bytes_and_keeps_selection_direction() { let (mut s, id) = setup("café😀e\u{301}x"); @@ -1146,6 +1161,8 @@ mod tests { assert_eq!(ime.owner.document, s.ds().unwrap().uid); } + /// Asserts an active composition is excluded from surrounding text and an empty text layer + /// reports an available, empty payload. #[test] fn ime_surrounding_excludes_the_composition_and_empty_text_is_available() { let (mut s, id) = setup("Hi"); @@ -1162,6 +1179,8 @@ mod tests { assert_eq!((ime.text.as_str(), ime.cursor, ime.anchor), ("", 0, 0), "an empty layer is available, not unavailable"); } + /// Asserts surrounding text is capped at `MAX_IME_SURROUNDING_BYTES`, an exactly budget-sized + /// selection is describable, and one byte more is `SelectionTooWide`. #[test] fn ime_surrounding_is_bounded_and_a_too_wide_selection_is_explicitly_unavailable() { let long = "a".repeat(5000); @@ -1182,6 +1201,8 @@ mod tests { assert_eq!(ime_surrounding(&s), Err(ImeSurroundingUnavailable::SelectionTooWide)); } + /// Asserts edits and caret moves keep the same IME owner, while ending and beginning a new + /// edit session changes the generation. #[test] fn ime_owner_is_stable_through_edits_and_the_session_changes_on_begin() { let (mut s, id) = setup("Hello"); @@ -1197,6 +1218,8 @@ mod tests { assert_ne!(replaced.editing_session, first.editing_session, "a new edit session is a replacement epoch"); } + /// Asserts byte deletion around a reversed selection removes whole characters on both + /// sides, keeps the selected text and direction, and a final no-op leaves the text alone. #[test] fn ime_delete_surrounding_bytes_keeps_the_reversed_selection_and_deletes_around_it() { let (mut s, id) = setup("ab你好cd"); @@ -1215,6 +1238,8 @@ mod tests { assert_eq!(data(&s, id).characters, "你好", "a no-op delete does not touch the text"); } + /// Asserts character deletion keeps and shifts the selection, and a no-op delete leaves an + /// active composition and the revision untouched. #[test] fn ime_delete_surrounding_chars_keeps_the_selection_and_ignores_a_no_op() { let (mut s, id) = setup("ab你好cd"); @@ -1235,6 +1260,7 @@ mod tests { assert_eq!(s.ds().unwrap().revision, revision); } + /// Asserts a text layer in another document has a different IME owner. #[test] fn ime_owner_identity_changes_with_the_document() { let (mut s, id) = setup("Hi"); @@ -1250,6 +1276,8 @@ mod tests { assert_eq!(second.node, other); } + /// Asserts a space committed after a line-start `-` becomes a bulleted list and reports + /// `Transformed`; a plain `"x"` commit reports `Plain`, and an empty commit reports `Nothing`. #[test] fn ime_commit_reports_list_autoformat_as_an_application_transformation() { let (mut s, id) = setup("-"); @@ -1261,6 +1289,8 @@ mod tests { assert_eq!(insert_ime_commit(&mut s, "").unwrap(), ImeInsertion::Nothing); } + /// Asserts CRLF normalization reports `Transformed`, control-only input reports `Nothing`, + /// and bare newline/CR commits are ignored while a live composition remains. #[test] fn ime_commit_normalisation_is_a_transformation_and_a_bare_newline_is_ignored() { let (mut s, id) = setup("Hi"); @@ -1283,6 +1313,8 @@ mod tests { assert_eq!(data(&s, id).characters, "Hia\nb\n"); } + /// Asserts an empty or control-only IME commit ends a live composition (bumping the revision + /// once), inserts nothing, and is a harmless no-op when no composition is active. #[test] fn an_empty_ime_commit_ends_the_composition_without_inserting_text() { let (mut s, id) = setup("Hello"); diff --git a/crates/engine/src/textfit_tests.rs b/crates/engine/src/textfit_tests.rs index f9508942..e35f810c 100644 --- a/crates/engine/src/textfit_tests.rs +++ b/crates/engine/src/textfit_tests.rs @@ -64,6 +64,8 @@ fn a_one_word_last_line_is_avoided() { assert!(l.lines.len() == 1 || words.split_whitespace().count() > 1 || words.contains('\u{a0}'), "{words:?}"); } +/// Asserts `data.fill` keeps a short copy's font size, shrinks a long copy, and leaves the +/// source text layer untouched. #[test] fn data_fill_sizes_each_copys_text() { figcraft_text::scan_system_fonts(); diff --git a/crates/engine/src/tools.rs b/crates/engine/src/tools.rs index e6776d2c..e65afe2c 100644 --- a/crates/engine/src/tools.rs +++ b/crates/engine/src/tools.rs @@ -2010,6 +2010,10 @@ impl Session { Ok(()) } + /// Handle a double-click gesture: finish a pen path, rename or click labels/widgets, + /// cancel an in-progress move/resize/draw/marquee, handle board double-clicks, enter text + /// editing (select-all on entry, word-select inside the running edit), enter vector editing + /// for selected shapes, and step groups/frames one level deeper. fn double_click(&mut self, ev: &PointerEvent) -> Result<()> { let ds = self.ds()?; let (doc, sel, page) = (ds.doc.clone(), ds.selection.clone(), ds.page); diff --git a/crates/text/build.rs b/crates/text/build.rs index ecca6a45..ba087983 100644 --- a/crates/text/build.rs +++ b/crates/text/build.rs @@ -6,6 +6,9 @@ use std::fmt::Write as _; use std::path::PathBuf; +/// Font build script: emit `craft_fonts.rs` from `input_fonts`, passing the +/// `CRAFT_FONTS_DIR`, `CRAFT_FONTS_REQUIRED`, wasm target and `FIGCRAFT_EMBED_CJK` inputs; +/// report generation and write failures with `cargo::error`. fn main() { println!("cargo::rerun-if-env-changed=CRAFT_FONTS_DIR"); println!("cargo::rerun-if-env-changed=CRAFT_FONTS_REQUIRED"); @@ -77,6 +80,10 @@ struct Catalog { faces: Vec<(String, String)>, } +/// Parse a font manifest of `family | style | file | scripts` rows into `CraftFont` +/// entries: skip Adobe-authored families, skip CJK unless requested, keep the web catalog +/// to its budgeted families, canonicalize and watch each face, and emit `include_bytes!` +/// items. fn craft_fonts(dir: &std::path::Path, manifest_rel: &str, wasm: bool, embed_cjk: bool) -> Result { let manifest = dir.join(manifest_rel); watch(&manifest); @@ -121,6 +128,8 @@ mod tests { struct Fixture(PathBuf); impl Fixture { + /// Test fixture: create a unique temporary directory, write a synthetic face file and + /// install the default Georgian manifest. fn new() -> Self { let dir = std::env::temp_dir().join(format!("fig-font-input-{}-{}", std::process::id(), NEXT.fetch_add(1, Ordering::Relaxed))); std::fs::create_dir_all(dir.join("fonts")).unwrap(); @@ -131,6 +140,7 @@ mod tests { fixture } + /// Test fixture: write manifest rows that all point at the fixture's `fonts/face.ttf` face. fn manifest(&self, name: &str, faces: &[(&str, &str)]) { let text = faces.iter().map(|(family, style)| format!("{family} | {style} | fonts/face.ttf | Latn\n")).collect::(); std::fs::write(self.0.join("fonts").join(name), text).unwrap(); @@ -138,11 +148,15 @@ mod tests { } impl Drop for Fixture { + /// Remove the fixture's temporary directory, ignoring errors. fn drop(&mut self) { let _ = std::fs::remove_dir_all(&self.0); } } + /// Asserts the native Latin catalog keeps its 43 permitted presentation faces, the web + /// catalog keeps only the four Inter faces, Adobe-authored families are absent, and + /// permitted native faces remain. #[test] fn restored_latin_catalog_preserves_permitted_native_faces_and_web_budget() { let f = Fixture::new(); @@ -160,6 +174,7 @@ mod tests { assert!(input_fonts(Some(&f.0), true, true, false).is_ok()); } + /// Asserts required web input rejects a catalog missing Inter Regular or Inter SemiBold. #[test] fn required_web_rejects_core_only_and_partial_latin_catalogs() { let f = Fixture::new(); @@ -168,6 +183,8 @@ mod tests { assert!(input_fonts(Some(&f.0), true, true, false).unwrap_err().contains("Inter SemiBold")); } + /// Asserts required web input embeds the Inter and Georgian catalogs (three entries) and + /// rejects a manifest without Noto Sans Georgian Regular. #[test] fn required_web_embeds_both_catalogs_and_requires_georgian() { let f = Fixture::new(); @@ -180,6 +197,8 @@ mod tests { assert!(input_fonts(Some(&f.0), true, true, false).unwrap_err().contains("Noto Sans Georgian Regular")); } + /// Asserts absent font input is empty when optional and an error when required, while present + /// input includes Noto Sans Georgian. #[test] fn optional_and_native_inputs_keep_their_existing_policy() { let f = Fixture::new(); @@ -189,6 +208,8 @@ mod tests { assert!(input_fonts(Some(&f.0), false, true, false).unwrap().contains("Noto Sans Georgian")); } + /// Asserts required web input rejects a manifest whose face file is missing, even when every + /// face row is listed. #[test] fn required_web_rejects_missing_asset_even_with_all_face_rows() { let f = Fixture::new(); diff --git a/crates/ui-egui/src/a11y.rs b/crates/ui-egui/src/a11y.rs index 79a28118..3c5fafb6 100644 --- a/crates/ui-egui/src/a11y.rs +++ b/crates/ui-egui/src/a11y.rs @@ -253,6 +253,8 @@ struct Shared { name: String, } +/// Run `f` on the per-context temporary `Shared` accessibility state keyed by +/// `figcraft_a11y`. fn shared(ctx: &Context, f: impl FnOnce(&mut Shared) -> R) -> R { ctx.data_mut(|d| f(d.get_temp_mut_or_default::(Id::unique("figcraft_a11y")))) } diff --git a/crates/ui-egui/src/a11y_tests.rs b/crates/ui-egui/src/a11y_tests.rs index a2c54cbe..14be637d 100644 --- a/crates/ui-egui/src/a11y_tests.rs +++ b/crates/ui-egui/src/a11y_tests.rs @@ -404,6 +404,8 @@ fn the_align_buttons_are_off_for_a_layer_alone_on_the_page() { assert!(!align_left(&tree(&mut u)), "one in a frame aligns to it"); } +/// Asserts side-panel and Pages edges are not focusable, and Tab never stops on the +/// side-panel edges. #[test] fn the_custom_panel_edges_never_enter_the_keyboard_or_focus_order() { // FigCraft's panels are fixed, so egui makes no `panel.__resize` widgets; the draggable edges diff --git a/crates/ui-egui/src/assets_panel.rs b/crates/ui-egui/src/assets_panel.rs index e9f0ffce..db0cc0f7 100644 --- a/crates/ui-egui/src/assets_panel.rs +++ b/crates/ui-egui/src/assets_panel.rs @@ -164,6 +164,7 @@ enum Act { Hide(NodeId, bool), } +/// Stable egui id for the assets drag payload. fn drag_id() -> Id { Id::unique("asset_drag") } @@ -581,6 +582,10 @@ fn render_thumbs(ui: &Ui, w: f32, thumbs: &mut Thumbs, wanted: &[(Source, NodeId } } +/// Draw the Assets panel: refresh libraries, switch to the libraries view when asked, +/// otherwise cache a listing keyed by revision, query and library state, render local and +/// enabled-library assets with reused thumbnails, and dispatch place, style, hide, toggle +/// and drag actions. pub fn show(app: &mut FigApp, ui: &mut Ui) { refresh_libraries(app, ui); if app.ui.libraries { @@ -773,6 +778,8 @@ fn drag_feedback(app: &mut FigApp, ui: &mut Ui, doc: &Document, libs: &HashMap) { let t = Tokens::get(ui.ctx()); let painter = ui.ctx().layer_painter(egui::LayerId::new(egui::Order::Tooltip, Id::unique("asset_ghost"))); @@ -831,6 +838,10 @@ fn libraries_view(app: &mut FigApp, ui: &mut Ui) { }); } +/// Draw the publish form: status, publishable components/styles/collections, description and +/// publish buttons. Run `library.publish` locally or publish to the server in the +/// background, reset the form on success, and report when the file is unsaved so other files +/// cannot yet use it. fn publish_form(app: &mut FigApp, ui: &mut Ui, w: f32, doc: &Document) { let form_id = Id::unique("asset_publish_form"); let mut form: PublishForm = ui.data(|d| d.get_temp(form_id)).unwrap_or_default(); @@ -1010,6 +1021,8 @@ fn usage(app: &mut FigApp, ui: &mut Ui, w: f32, link: &str) { ui.add_space(8.0); } +/// Draw the libraries enabled in this file with version/count/status, remove and swap +/// actions, add-file and pasted-link controls, and background fetch/cancel handling. fn enabled_libraries(app: &mut FigApp, ui: &mut Ui, w: f32, doc: &Document) { let t = Tokens::get(ui.ctx()); title(ui, w, tr("Libraries in this file")); diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 4211b3cc..a6770823 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -163,6 +163,10 @@ fn pointer_event(app: &FigApp, kind: PointerKind, pos: Pos2, m: &egui::Modifiers } } +/// Run one canvas pass: update the viewport size and first-fit zoom; handle pointer/key input +/// and accessibility; draw the drop overlay, guides, live pointer and preedit; request/poll +/// renders and upload the texture; draw the page background and last texture; then draw overlays, +/// labels, handles, comments, versions/branch/dev/live UI and the cursor. pub fn show(app: &mut FigApp, ui: &mut Ui, worker: &mut Worker) { let rect = ui.max_rect(); app.canvas.rect = rect; diff --git a/crates/ui-egui/src/clipboard_fence_tests.rs b/crates/ui-egui/src/clipboard_fence_tests.rs index 9211a4d4..76ddf81c 100644 --- a/crates/ui-egui/src/clipboard_fence_tests.rs +++ b/crates/ui-egui/src/clipboard_fence_tests.rs @@ -25,14 +25,17 @@ struct Recorded { struct Clipboard(Arc>); impl Services for Clipboard { + /// Record a system-clipboard text write in the test clipboard service. fn clipboard_set_text(&mut self, s: &str) { let mut r = self.0.lock().unwrap(); r.text.push(s.to_string()); r.last_text = Some(s.to_string()); } + /// Return the test system clipboard's last text. fn clipboard_get_text(&mut self) -> Option { self.0.lock().unwrap().last_text.clone() } + /// Count a PNG clipboard write in the test clipboard service. fn clipboard_set_png(&mut self, _w: u32, _h: u32, _rgba: &[u8]) { self.0.lock().unwrap().pngs += 1; } @@ -46,6 +49,7 @@ struct Win { } impl Win { + /// Create a test window over a session containing one selected rectangle. fn new() -> Self { let mut s = Session::new(); s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 100, "height": 50})).unwrap(); @@ -54,6 +58,7 @@ impl Win { win } + /// Build a test window around `s` with a recording clipboard service and run three frames. fn with_session(s: Session) -> Self { let recorded = Arc::new(Mutex::new(Recorded::default())); let app = FigApp::new(s, Box::new(Clipboard(recorded.clone()))); @@ -64,6 +69,7 @@ impl Win { win } + /// Run one production UI frame with `events` at the next 60 Hz test time. fn frame(&mut self, events: Vec) { self.time += 1.0 / 60.0; self.app.clock.set_test_now(Some(self.time)); @@ -74,12 +80,15 @@ impl Win { out.textures_delta.clear(); } + /// Return the recorded `(text writes, PNG writes)` count. fn writes(&self) -> (usize, usize) { let r = self.recorded.lock().unwrap(); (r.text.len(), r.pngs) } } +/// Asserts that a control-channel copy shortcut writes no system clipboard, still runs the +/// command and is acknowledged. #[test] fn a_synthetic_copy_shortcut_leaves_the_system_clipboard_alone() { let mut w = Win::new(); @@ -106,6 +115,8 @@ fn a_synthetic_copy_shortcut_leaves_the_system_clipboard_alone() { assert!(rx.try_recv().is_ok(), "the batch is acknowledged"); } +/// Asserts copy commands run under the synthetic-control fence write nothing, while the same +/// command afterwards writes once. #[test] fn a_copy_command_invoked_for_a_synthetic_click_still_keeps_the_clipboard() { let mut w = Win::new(); @@ -120,6 +131,7 @@ fn a_copy_command_invoked_for_a_synthetic_click_still_keeps_the_clipboard() { assert_eq!(w.writes(), (1, 0)); } +/// Return the characters of a text node in the test window. fn edit_text(w: &Win, id: NodeId) -> String { match &w.app.session.doc().unwrap().node(id).unwrap().kind { NodeKind::Text(t) => t.characters.clone(), @@ -127,6 +139,8 @@ fn edit_text(w: &Win, id: NodeId) -> String { } } +/// Asserts a synthetic Cut deletes the selected text, keeps the edit session active, writes +/// no system clipboard, and ends its fence with the frame. #[test] fn a_synthetic_cut_deletes_the_selection_but_leaves_the_users_clipboard_alone() { let mut s = Session::new(); @@ -147,6 +161,8 @@ fn a_synthetic_cut_deletes_the_selection_but_leaves_the_users_clipboard_alone() assert!(!w.app.control_synthetic, "the fence ends with the frame"); } +/// Asserts a programmatic copy leaves the system clipboard alone and invalidates the stale +/// mirror, so a later user paste uses the system text rather than the programmatic layers. #[test] fn a_programmatic_copy_does_not_let_a_stale_mirror_hide_the_users_paste() { let mut s = Session::new(); diff --git a/crates/ui-egui/src/colorpicker.rs b/crates/ui-egui/src/colorpicker.rs index 90d00c3f..f1cde02f 100644 --- a/crates/ui-egui/src/colorpicker.rs +++ b/crates/ui-egui/src/colorpicker.rs @@ -339,6 +339,8 @@ fn hue_color(ctx: &egui::Context, h: f32) -> Color32 { doc_c32(ctx, Hsb { h, s: 1.0, b: 1.0 }.to_color()) } +/// Draw the saturation/value square and its knob, updating `hsb.s` and `hsb.b` on click or +/// drag; returns `(changed, done)`. fn sv_square(ui: &mut Ui, rect: Rect, hsb: &mut Hsb) -> (bool, bool) { // White → hue horizontally, then transparent → black vertically. let mut m = Mesh::default(); @@ -377,6 +379,8 @@ fn sv_square(ui: &mut Ui, rect: Rect, hsb: &mut Hsb) -> (bool, bool) { (changed, resp.drag_stopped() || resp.clicked()) } +/// Draw the hue gradient and knob, updating `hsb.h` clamped below 360; returns +/// `(changed, done)`. fn hue_slider(ui: &mut Ui, rect: Rect, hsb: &mut Hsb) -> (bool, bool) { let n = 12; let mut m = Mesh::default(); @@ -417,6 +421,8 @@ fn slider_knob(ui: &mut Ui, rect: Rect, t: f32, id: Id) -> Option<(f32, bool)> { None } +/// Draw the checkerboard and transparent-to-opaque alpha gradient with a knob; returns the +/// new alpha and done state, or `None` when the slider is not interacting. fn alpha_slider(ui: &mut Ui, rect: Rect, color: Color) -> Option<(f32, bool)> { widgets::checker(&ui.painter().with_clip_rect(rect), rect, rect.height() / 2.0); let mut m = Mesh::default(); @@ -441,6 +447,9 @@ pub fn window_id() -> Id { Id::unique("color_picker") } +/// Draw the colour picker for the current target: close it when there is no target or the +/// target's selection no longer matches, otherwise apply eyedropper, paint-kind, colour and +/// gradient-stop edits live, positioned beside a plugin field when applicable. pub fn show(app: &mut FigApp, ctx: &egui::Context) { let Some(target) = app.ui.picker.clone() else { // A colour sampled for a picker that has closed has no paint to go to. diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 4c3be3de..97e62d1f 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -70,18 +70,22 @@ pub struct RequestGate { } impl RequestGate { + /// Create a request gate in its default `Open` state. pub fn new() -> Self { Self::default() } + /// Return a copy of the gate's current request state. pub fn state(&self) -> RequestState { *self.state.lock().unwrap_or_else(std::sync::PoisonError::into_inner) } + /// Whether the gate is `Cancelled`. pub fn is_cancelled(&self) -> bool { self.state() == RequestState::Cancelled } + /// Whether the gate is `Replied`. pub fn is_replied(&self) -> bool { self.state() == RequestState::Replied } @@ -121,6 +125,7 @@ pub struct ControlRequest { } impl ControlRequest { + /// Whether this request's gate is `Cancelled`. pub fn is_cancelled(&self) -> bool { self.state.is_cancelled() } @@ -147,6 +152,7 @@ struct SlotInner { } impl CaptureSlot { + /// Create an empty capture slot for `viewport`, holding a clone of the UI context. fn new(ctx: &Context, viewport: egui::ViewportId) -> Arc { Arc::new(Self { inner: Mutex::new(SlotInner::default()), ctx: ctx.clone(), viewport }) } @@ -161,6 +167,8 @@ impl CaptureSlot { }) } + /// Store the first delivered image only while the slot is open and untaken, ignoring later + /// or closed deliveries, then wake the viewport after releasing the lock. pub(crate) fn complete(&self, image: Arc) { { let mut inner = self.inner.lock().unwrap_or_else(std::sync::PoisonError::into_inner); @@ -214,6 +222,7 @@ pub struct CaptureSpec { const SHOT_PNG_OVERHEAD: usize = 64 * 1024; impl CaptureSpec { + /// Return the checked pixel byte count (`width × height × 4`), or `None` on overflow. fn bytes(&self) -> Option { self.size_px[0].checked_mul(self.size_px[1])?.checked_mul(4) } @@ -272,6 +281,7 @@ pub struct ShotRequest { } impl ShotRequest { + /// Close and drop the capture slot, if any, and zero the reserved byte count. fn release(&mut self) { if let Some(slot) = self.slot.take() { slot.close(); @@ -327,6 +337,7 @@ fn current_spec(ctx: &Context, viewport: egui::ViewportId) -> Option) { let _ = r.reply.send(ControlReply { id: r.id.clone(), result }); } @@ -819,6 +830,8 @@ enum EncodedShot { } impl EncodedShot { + /// Deliver the encoded shot: for `File`, write the PNG through `file_access` and return its + /// path and dimensions; for `Data`, return the prebuilt result. fn finish(self) -> Result { match self { Self::File { path, png, width, height } => { diff --git a/crates/ui-egui/src/control_capture_tests.rs b/crates/ui-egui/src/control_capture_tests.rs index ce4df1aa..6068ce52 100644 --- a/crates/ui-egui/src/control_capture_tests.rs +++ b/crates/ui-egui/src/control_capture_tests.rs @@ -12,6 +12,7 @@ use serde_json::json; use crate::control::{CaptureSpec, ControlReply, ControlRequest}; use crate::layers_drag_tests::Ui; +/// Queue a `ui.screenshot` request in the test app and return its reply receiver. fn push(u: &mut Ui, id: u64, params: serde_json::Value) -> std::sync::mpsc::Receiver { let (tx, rx) = std::sync::mpsc::channel(); u.app.control_queue.push(ControlRequest { id: json!(id), method: "ui.screenshot".into(), params, reply: tx, state: Default::default() }); @@ -38,10 +39,13 @@ fn resized_frame(u: &mut Ui, size: egui::Vec2) -> egui::FullOutput { out } +/// Whether any viewport in the frame output issues a `Screenshot` command. fn has_screenshot(out: &egui::FullOutput) -> bool { out.viewport_output.values().any(|v| v.commands.iter().any(|c| matches!(c, egui::ViewportCommand::Screenshot(_)))) } +/// Asserts reverse capture completion replies only to the matching request, then drains both +/// requests. #[test] fn two_captures_correlate_by_request_across_reverse_completion() { let mut u = Ui::new(Session::empty()); @@ -67,6 +71,7 @@ fn two_captures_correlate_by_request_across_reverse_completion() { assert!(u.app.capture.shots.is_empty(), "no retained requests"); } +/// Asserts a cancelled capture gets no reply and its slot is released. #[test] fn a_cancelled_capture_never_replies_or_writes() { let mut u = Ui::new(Session::empty()); @@ -89,6 +94,7 @@ fn commit_dir(tag: &str) -> std::path::PathBuf { dir } +/// Asserts cancellation after encoding still prevents the final file write and reply. #[test] fn a_cancellation_after_encoding_prevents_the_final_write() { let dir = commit_dir("cancelled"); @@ -107,6 +113,7 @@ fn a_cancellation_after_encoding_prevents_the_final_write() { let _ = std::fs::remove_dir_all(&dir); } +/// Asserts a capture that arrives past its deadline reports a timeout and writes no PNG. #[test] fn a_real_arrival_that_crosses_the_deadline_does_not_write_its_png() { let mut u = Ui::new(Session::empty()); @@ -129,6 +136,8 @@ fn a_real_arrival_that_crosses_the_deadline_does_not_write_its_png() { let _ = std::fs::remove_dir_all(&dir); } +/// Asserts an expiry during encoding reports the timeout under the gate, marks the request +/// replied and writes no file. #[test] fn an_expiry_during_encoding_prevents_the_final_write_and_reports_timeout() { let dir = commit_dir("expired"); @@ -149,6 +158,8 @@ fn an_expiry_during_encoding_prevents_the_final_write_and_reports_timeout() { let _ = std::fs::remove_dir_all(&dir); } +/// Asserts a commit before the deadline writes the file and queues one reply, and a second +/// commit is refused. #[test] fn a_commit_before_the_deadline_writes_and_queues_its_reply_once() { let dir = commit_dir("committed"); @@ -172,6 +183,8 @@ fn a_commit_before_the_deadline_writes_and_queues_its_reply_once() { let _ = std::fs::remove_dir_all(&dir); } +/// Asserts a capture past its deadline sends one timeout reply, releases its slot, and late +/// pixels are ignored. #[test] fn a_capture_after_its_deadline_replies_once_and_late_pixels_are_inert() { let mut u = Ui::new(Session::empty()); @@ -191,6 +204,8 @@ fn a_capture_after_its_deadline_replies_once_and_late_pixels_are_inert() { assert!(rx.try_recv().is_err(), "a late capture is inert"); } +/// Asserts the snapshot count budget rejects an over-budget request before issuing, and every +/// admitted capture still completes under its own id. #[test] fn a_snapshot_batch_is_capped_before_issuing_over_the_count_budget() { let mut u = Ui::new(Session::empty()); @@ -213,6 +228,7 @@ fn a_snapshot_batch_is_capped_before_issuing_over_the_count_budget() { rxs.clear(); } +/// Asserts an undersized readback is not accepted but reissued with one retry and no reply. #[test] fn an_undersized_readback_is_reissued_instead_of_accepted() { let mut u = Ui::new(Session::empty()); @@ -230,6 +246,7 @@ fn an_undersized_readback_is_reissued_instead_of_accepted() { assert!(!r.issued, "waits for the settled geometry again"); } +/// Asserts a one-pixel rounding difference is accepted as the same surface. #[test] fn a_one_pixel_rounding_difference_is_still_the_same_surface() { let mut u = Ui::new(Session::empty()); @@ -245,6 +262,7 @@ fn a_one_pixel_rounding_difference_is_still_the_same_surface() { assert!(u.app.capture.shots.is_empty(), "released"); } +/// Asserts an A→B→A tab switch invalidates the admitted capture with "document changed". #[test] fn a_document_a_to_b_to_a_switch_is_not_the_admitted_capture() { let mut s = Session::empty(); @@ -268,6 +286,8 @@ fn a_document_a_to_b_to_a_switch_is_not_the_admitted_capture() { assert!(u.app.capture.shots.is_empty(), "released"); } +/// Asserts a geometry change bumps the capture epoch and reissues instead of accepting old +/// pixels. #[test] fn a_geometry_change_reissues_instead_of_accepting_old_pixels() { let mut u = Ui::new(Session::empty()); @@ -288,6 +308,8 @@ fn a_geometry_change_reissues_instead_of_accepting_old_pixels() { assert!(!r.issued, "waits for the settled geometry again"); } +/// Asserts a translucent pixel round-trips through the PNG as straight RGBA without +/// darkening. #[test] fn a_translucent_pixel_round_trips_straight_rgba() { let img = egui::ColorImage::from_rgba_unmultiplied([1, 1], &[128, 64, 32, 128]); @@ -298,6 +320,8 @@ fn a_translucent_pixel_round_trips_straight_rgba() { assert_eq!(decoded.get_pixel(0, 0).0, [128, 64, 32, 128], "straight alpha is not darkened"); } +/// Asserts a capture is not issued before three completed real UI frames; the following +/// completed frame issues it. #[test] fn a_capture_is_not_issued_before_three_completed_real_ui_frames() { let mut u = Ui::new(Session::empty()); @@ -313,6 +337,8 @@ fn a_capture_is_not_issued_before_three_completed_real_ui_frames() { assert!(u.app.capture.shots[0].issued, "issued once three frames have presented their layout"); } +/// Asserts a discarded sizing pass does not count toward capture settling, and the next +/// completed frame issues it. #[test] fn a_discarded_sizing_pass_does_not_count_as_a_settled_capture_frame() { let mut u = Ui::new(Session::empty()); @@ -327,6 +353,8 @@ fn a_discarded_sizing_pass_does_not_count_as_a_settled_capture_frame() { assert!(u.app.capture.shots[0].issued, "the next completed frame issues the capture"); } +/// Asserts pixels delivered while hidden force a draining paint and are answered rather than +/// timed out. #[test] fn a_hidden_window_that_delivers_pixels_is_asked_to_paint_the_draining_pass() { let mut u = Ui::new(Session::empty()); @@ -354,6 +382,8 @@ fn a_hidden_window_that_delivers_pixels_is_asked_to_paint_the_draining_pass() { assert!(u.app.capture.shots.is_empty(), "released"); } +/// Asserts a capture for a window with unknown visibility is parked with its deadline and a +/// paint request, then times out once. #[test] fn a_capture_for_a_window_with_unknown_visibility_is_admitted_with_a_deadline() { let mut u = Ui::new(Session::empty()); @@ -386,6 +416,8 @@ fn a_capture_for_a_window_with_unknown_visibility_is_admitted_with_a_deadline() assert!(u.app.capture.shots.is_empty(), "released"); } +/// Asserts a completed capture is rejected when current geometry is unavailable, failing +/// closed. #[test] fn a_completed_capture_is_rejected_when_current_geometry_is_unavailable() { let mut u = Ui::new(Session::empty()); @@ -412,6 +444,7 @@ fn a_completed_capture_is_rejected_when_current_geometry_is_unavailable() { assert!(u.app.capture.shots.is_empty(), "released"); } +/// Asserts a tab switch while a capture settles invalidates it with "document changed". #[test] fn a_capture_belongs_to_the_document_admitted_not_the_one_showing_when_it_arrives() { let mut s = Session::empty(); @@ -435,6 +468,8 @@ fn a_capture_belongs_to_the_document_admitted_not_the_one_showing_when_it_arrive assert!(u.app.capture.shots.is_empty(), "released"); } +/// Asserts the capture budget covers the encoding and reply peaks, not just pixels, and an +/// over-budget resize is rejected before readback. #[test] fn the_capture_budget_counts_the_encoding_peak_not_only_the_pixels() { let fits = CaptureSpec { viewport: egui::ViewportId::ROOT, size_px: [4096, 4096], pixels_per_point: 1.0, zoom: 1.0 }; @@ -462,6 +497,8 @@ fn the_capture_budget_counts_the_encoding_peak_not_only_the_pixels() { assert!(!has_screenshot(&out), "over-budget growth is rejected before any readback command"); } +/// Asserts resizing settling captures rechecks aggregate reserved bytes, rejects the request +/// that no longer fits, and makes the survivor reserve its real cost. #[test] fn resizing_settling_captures_rechecks_the_aggregate_reserved_bytes() { let mut u = Ui::new(Session::empty()); @@ -481,6 +518,8 @@ fn resizing_settling_captures_rechecks_the_aggregate_reserved_bytes() { assert!(!has_screenshot(&out), "neither request was read back using the old small reservation"); } +/// Asserts an allowed resize restarts settling, issues only after three new-size frames, and +/// reserves the current cost. #[test] fn an_allowed_resize_restarts_settling_and_issues_with_the_current_reservation() { let mut u = Ui::new(Session::empty()); @@ -518,6 +557,8 @@ fn push_input(u: &mut Ui, id: u64) -> std::sync::mpsc::Receiver { rx } +/// Asserts injected input is queued, applied by the presenting pass, and acknowledged once +/// after that pass. #[test] fn injected_input_is_acknowledged_only_after_the_pass_that_applies_it() { let mut u = Ui::new(Session::empty()); @@ -534,6 +575,8 @@ fn injected_input_is_acknowledged_only_after_the_pass_that_applies_it() { assert!(!u.app.control_synthetic, "the fence ends with the frame"); } +/// Asserts a discarded pass neither acknowledges nor replays an injected batch; the presented +/// pass acknowledges once. #[test] fn a_discarded_pass_does_not_acknowledge_or_lose_an_injected_batch() { let mut u = Ui::new(Session::empty()); @@ -565,6 +608,8 @@ fn a_discarded_pass_does_not_acknowledge_or_lose_an_injected_batch() { assert!(app.input_acks.is_empty() && app.applied_acks.is_empty()); } +/// Asserts injected text is applied once across a discarded sizing pass and acknowledged +/// once. #[test] fn injected_text_lands_once_across_a_discarded_sizing_pass() { // egui reruns a discarded pass with the same `RawInput`. The custom editor applied the text in diff --git a/crates/ui-egui/src/credits_tests.rs b/crates/ui-egui/src/credits_tests.rs index 8b10a622..fb3993ad 100644 --- a/crates/ui-egui/src/credits_tests.rs +++ b/crates/ui-egui/src/credits_tests.rs @@ -51,10 +51,12 @@ impl Ui { u } + /// Store the About table's current view in test context data. fn set_view(&self, v: View) { self.ctx.data_mut(|d| d.insert_temp(egui::Id::unique("credits_view"), v)); } + /// Read the stored About table view, defaulting when unset. fn view(&self) -> View { self.ctx.data(|d| d.get_temp::(egui::Id::unique("credits_view"))).unwrap_or_default() } diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 3ec562a2..8d4d8fdb 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -179,6 +179,10 @@ pub fn keys(app: &mut FigApp, ctx: &Context) { } } +/// Draw the app's dialogs and cards: pending opens/imports/missing fonts, About, +/// Preferences, shortcuts, find/replace, batch rename, menu input, variables, dev compare, +/// branch, export preview, colour profile, plugin, live join/publish, online dialogs and +/// close confirmation. pub fn show(app: &mut FigApp, ctx: &Context) { // Dropped files waiting to open: their card, then (once it has shown) the files. crate::pending_open::pending_opens(app, ctx); diff --git a/crates/ui-egui/src/field_tests.rs b/crates/ui-egui/src/field_tests.rs index 4e724553..341e7cca 100644 --- a/crates/ui-egui/src/field_tests.rs +++ b/crates/ui-egui/src/field_tests.rs @@ -467,6 +467,8 @@ fn lead(u: &Ui, id: Id) -> Pos2 { u.ctx.read_response(id.with("lead")).unwrap_or_else(|| panic!("no field {id:?}")).rect.center() } +/// Asserts scrubbing the colour picker's R and alpha fields updates the colour live, each +/// scrub adding one undo step. #[test] fn scrubbing_colour_picker_fields_is_live_and_one_undo_step() { let (mut u, a, _) = setup(); @@ -490,6 +492,8 @@ fn scrubbing_colour_picker_fields_is_live_and_one_undo_step() { assert_eq!(undo_steps(&u), steps + 2, "alpha"); } +/// Asserts scrubbing a prototype delay sets the value once when released and adds one undo +/// step. #[test] fn scrubbing_a_prototype_delay_sets_it_once_when_let_go() { let mut s = Session::new(); @@ -514,6 +518,7 @@ fn scrubbing_a_prototype_delay_sets_it_once_when_let_go() { assert_eq!((ms, undo_steps(&u)), (800, steps + 1)); } +/// Asserts scrubbing the scale panel's width scales the layer live in one undo step. #[test] fn scrubbing_the_scale_panel_width_scales_live_in_one_undo_step() { let (mut u, a, _) = setup(); @@ -584,6 +589,8 @@ fn the_intensity_label_fits_whole_in_every_language() { out.textures_delta.clear(); } +/// Asserts a label too long for its number field is elided before the value, while the value +/// stays whole and both remain inside the field. #[test] fn a_label_too_long_for_its_field_ends_in_an_ellipsis_before_the_value() { let ctx = egui::Context::default(); @@ -780,6 +787,8 @@ fn a_deferred_field_save_keeps_its_document_when_the_next_input_switches_tabs() } } +/// Asserts a deferred field save does not retarget a closed, moved or foreign owner: the other +/// file stays untouched, Save as is not opened, and the stale request is consumed once. #[test] fn a_deferred_field_save_does_not_retarget_a_closed_moved_or_foreign_owner() { for change in ["closed", "moved", "foreign"] { diff --git a/crates/ui-egui/src/frame_labels.rs b/crates/ui-egui/src/frame_labels.rs index 4c4b0de1..a87fc9f4 100644 --- a/crates/ui-egui/src/frame_labels.rs +++ b/crates/ui-egui/src/frame_labels.rs @@ -58,6 +58,9 @@ pub fn turn_since(painter: &Painter, from: ShapeIdx, pivot: Pos2, angle: f32) { }); } +/// Recursively rotate shape geometry by `rot`/`angle` about `pivot`: leaves +/// no-op/callback/band shapes alone, rotates points and centers, adds the angle to +/// ellipses/rects/text, and rotates meshes. fn turn(shape: &mut Shape, rot: Rot2, angle: f32, pivot: Pos2) { let at = |p: &mut Pos2| *p = pivot + rot * (*p - pivot); match shape { diff --git a/crates/ui-egui/src/frame_presets.rs b/crates/ui-egui/src/frame_presets.rs index 0d1c4b91..9eb28162 100644 --- a/crates/ui-egui/src/frame_presets.rs +++ b/crates/ui-egui/src/frame_presets.rs @@ -10,6 +10,8 @@ use crate::icons::{self, Icon}; use crate::theme::{Tokens, regular, semibold}; use crate::widgets::{self, PAD}; +/// Draw the expandable frame-preset categories; choosing a preset runs `frame.create`, +/// switches to the Move tool and zooms to the new selection. pub fn panel(app: &mut FigApp, ui: &mut Ui) { let t = Tokens::get(ui.ctx()); widgets::section_header(ui, tr("Frame"), &[], false); diff --git a/crates/ui-egui/src/guides.rs b/crates/ui-egui/src/guides.rs index 827597ac..3200ca42 100644 --- a/crates/ui-egui/src/guides.rs +++ b/crates/ui-egui/src/guides.rs @@ -49,6 +49,7 @@ struct Placed { line: Option<[Point; 2]>, } +/// Stable egui id for guide dragging. fn drag_id() -> Id { Id::unique("guide_drag") } diff --git a/crates/ui-egui/src/handles.rs b/crates/ui-egui/src/handles.rs index b7a575fa..d29d59ee 100644 --- a/crates/ui-egui/src/handles.rs +++ b/crates/ui-egui/src/handles.rs @@ -67,6 +67,7 @@ fn crop_corners(app: &FigApp, id: NodeId, r: (f64, f64, f64, f64)) -> Option<[Po ]) } +/// Stable egui id for handle dragging. fn drag_id() -> Id { Id::unique("figcraft_handle_drag") } diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rs index ebea682e..9c809b99 100644 --- a/crates/ui-egui/src/home.rs +++ b/crates/ui-egui/src/home.rs @@ -188,6 +188,8 @@ fn dropped(app: &mut FigApp, ctx: &egui::Context) { } } +/// Draw the Home sidebar: app icon and wordmark, file/template search (Escape clears it) +/// and section tabs; choosing a section clears the file query. fn sidebar(app: &mut FigApp, ui: &mut Ui, t: &Tokens, left: Rect) { let mut y = left.min.y + 20.0; crate::theme::paint_app_icon(ui, Rect::from_min_size(pos2(left.min.x + 12.0, y - 4.0), vec2(32.0, 32.0))); @@ -475,6 +477,8 @@ fn matches(template: &Template, query: &str, kind: Option) -> bool { || has(template.size)) } +/// Draw template search and kind filter, show no-match guidance and a "Show all templates" +/// button that clears the query and kind, and lay matching templates out in a grid. fn templates(app: &mut FigApp, ui: &mut Ui, t: &Tokens) { heading(ui, t, tr("Templates")); ui.horizontal(|ui| { diff --git a/crates/ui-egui/src/idle_tests.rs b/crates/ui-egui/src/idle_tests.rs index cc19d6a9..ee25124a 100644 --- a/crates/ui-egui/src/idle_tests.rs +++ b/crates/ui-egui/src/idle_tests.rs @@ -248,6 +248,8 @@ fn a_finished_background_render_wakes_the_ui() { assert!(worker.poll().is_some(), "the woken frame finds the image"); } +/// Asserts a control request wakes an idle UI and is answered, and screenshots keep frames +/// coming until delivered before the UI rests again. #[test] fn control_requests_and_screenshots_wake_an_idle_ui() { let (mut h, _) = document(); @@ -341,6 +343,8 @@ fn cjk_names_are_looked_for_in_edits_not_on_every_pan() { assert_eq!(h.app.cjk_needed(&ctx, 0), crate::cjk::HANGUL); } +/// Asserts a hidden window answers edits and inspection at once, while a screenshot is +/// parked with a deadline and times out once instead of waiting for a frame. #[test] fn a_hidden_window_answers_at_once() { // #269, #720: minimised or covered, the window draws no frames, but the app's logic still runs: @@ -424,6 +428,8 @@ fn auto_save_writes_a_changed_file_then_rests() { let _ = std::fs::remove_dir_all(&dir); } +/// Asserts a hidden logic tick runs background work and advances the autosave deadline +/// without counting a UI frame, and is idempotent at the same time. #[test] fn a_hidden_logic_tick_runs_background_work_but_counts_no_ui_frame() { let (mut h, _) = document(); @@ -444,6 +450,7 @@ fn a_hidden_logic_tick_runs_background_work_but_counts_no_ui_frame() { assert_eq!(h.app.ui.next_autosave, deadline, "idempotent at the same monotonic time"); } +/// Asserts a discarded sizing pass counts one drawn frame, not one per pass. #[test] fn a_discarded_sizing_pass_sets_up_and_counts_one_frame_only() { let (mut h, _) = document(); diff --git a/crates/ui-egui/src/ime_tests.rs b/crates/ui-egui/src/ime_tests.rs index e699dda5..e6c2f698 100644 --- a/crates/ui-egui/src/ime_tests.rs +++ b/crates/ui-egui/src/ime_tests.rs @@ -48,6 +48,7 @@ fn ime_descriptor(u: &mut Ui, events: Vec) -> IMEOutput { u.frame_raw(RawInput { events, ..Default::default() }).platform_output.ime.expect("the IME stays on while editing") } +/// Return the available surrounding-text payload of an IME output, panicking when unavailable. fn available(ime: &IMEOutput) -> &IMESurroundingTextPayload { match &ime.surrounding_text { IMESurroundingText::Available(payload) => payload, @@ -55,6 +56,7 @@ fn available(ime: &IMEOutput) -> &IMESurroundingTextPayload { } } +/// Create a text layer with `text` and return its node id. fn text_layer(s: &mut Session, text: &str) -> NodeId { NodeId(s.execute("text.create", &json!({"text": text, "x": 40, "y": 40})).unwrap()["id"].as_u64().unwrap()) } @@ -103,6 +105,8 @@ fn pinyin_composes_inline_and_commits_once_with_the_ime_on_every_frame() { assert_eq!(text(&u, t), "Hi你好\n!"); } +/// Asserts an empty IME commit ends the composition, inserts nothing, keeps the editor +/// focused, and the next pass observes the committed text. #[test] fn an_empty_ime_commit_ends_the_composition_without_inserting_text() { // Safari's egui web integration sends `Commit("")` (not `Preedit("")`) when the last @@ -126,6 +130,8 @@ fn an_empty_ime_commit_ends_the_composition_without_inserting_text() { assert_eq!(text(&u, t), "Hello"); } +/// Asserts byte deletion before the paired commit replaces the exact UTF-8 range, and one undo +/// restores the pre-IME text. #[test] fn an_ime_replacing_text_deletes_in_bytes_before_the_paired_commit() { // 0.37 sends `DeleteSurroundingBytes` immediately before the commit that replaces it. The @@ -146,6 +152,8 @@ fn an_ime_replacing_text_deletes_in_bytes_before_the_paired_commit() { assert_eq!(text(&u, t), "ab\u{4F60}\u{597D}cd", "one undo restores the pre-IME text"); } +/// Asserts a caret click invalidates the whole stale IME batch (both byte and character +/// deletions) while a later direct commit still works. #[test] fn a_caret_click_rejects_the_stale_delete_and_commit_in_the_same_input_batch() { figcraft_text::scan_system_fonts(); @@ -185,6 +193,8 @@ fn a_caret_click_rejects_the_stale_delete_and_commit_in_the_same_input_batch() { } } +/// Asserts a control-channel document switch rejects the old composition's delete and commit +/// batch, while a direct commit to the new target remains valid. #[test] fn a_document_switch_rejects_the_old_compositions_delete_and_commit_batch() { figcraft_text::scan_system_fonts(); @@ -214,6 +224,8 @@ fn a_document_switch_rejects_the_old_compositions_delete_and_commit_batch() { assert_eq!(text(&u, b), "BravoX", "a direct commit to the new noncomposing target remains valid"); } +/// Asserts the first observation and ordinary typing are `Other`, while an accepted commit is +/// `InputMethod` with UTF-8 offsets, the same owner and generation. #[test] fn ime_cause_is_input_method_only_for_an_accepted_commit() { figcraft_text::scan_system_fonts(); @@ -240,6 +252,8 @@ fn ime_cause_is_input_method_only_for_an_accepted_commit() { assert_eq!(text(&u, t), "Hi你好x"); } +/// Asserts a frame mixing IME and application edits is `Other`, and a later pure commit is +/// `InputMethod` without lingering state. #[test] fn ime_cause_reports_mixed_application_and_ime_mutations_as_other() { figcraft_text::scan_system_fonts(); @@ -267,6 +281,7 @@ fn ime_cause_reports_mixed_application_and_ime_mutations_as_other() { assert_eq!(text(&u, t), "Hiあbうcえおdか"); } +/// Asserts a control-channel text edit is an application change (`Other`). #[test] fn a_control_channel_text_edit_is_an_application_change() { figcraft_text::scan_system_fonts(); @@ -283,6 +298,8 @@ fn a_control_channel_text_edit_is_an_application_change() { assert_eq!(available(&out).text, "Hiz"); } +/// Asserts a byte delete followed by a commit is `InputMethod` and describes the +/// post-mutation text and caret. #[test] fn ime_delete_then_commit_is_input_method_and_describes_the_post_mutation_text() { figcraft_text::scan_system_fonts(); @@ -302,6 +319,8 @@ fn ime_delete_then_commit_is_input_method_and_describes_the_post_mutation_text() assert_eq!(text(&u, t), "abXd"); } +/// Asserts preedit text is excluded from surrounding text and earns no receipt, while the +/// following commit is `InputMethod`. #[test] fn preedit_is_not_surrounding_text_but_the_commit_that_follows_is_input_method() { figcraft_text::scan_system_fonts(); @@ -322,6 +341,8 @@ fn preedit_is_not_surrounding_text_but_the_commit_that_follows_is_input_method() assert_eq!(available(&committed).cursor, 8); } +/// Asserts surrounding text is logical UTF-8 with byte offsets and keeps a reversed +/// selection. #[test] fn ime_surrounding_text_is_logical_utf8_and_keeps_a_reversed_selection() { figcraft_text::scan_system_fonts(); @@ -339,6 +360,8 @@ fn ime_surrounding_text_is_logical_utf8_and_keeps_a_reversed_selection() { assert!(payload.cursor < payload.anchor, "the reversed selection is not sorted"); } +/// Asserts empty text is available while a selection wider than the 4000-byte budget is +/// explicitly unavailable but still has a nonzero IME context generation. #[test] fn empty_text_is_available_while_a_too_wide_selection_is_explicitly_unavailable() { figcraft_text::scan_system_fonts(); @@ -361,6 +384,7 @@ fn empty_text_is_available_while_a_too_wide_selection_is_explicitly_unavailable( assert!(wide.context_generation > 0, "the owner stays known when only the text is unavailable"); } +/// Asserts replacing a too-wide selection with a commit is still an `InputMethod` receipt. #[test] fn a_commit_replacing_a_too_wide_selection_is_still_an_input_method_receipt() { figcraft_text::scan_system_fonts(); @@ -382,6 +406,8 @@ fn a_commit_replacing_a_too_wide_selection_is_still_an_input_method_receipt() { assert_eq!((available(&out).cursor, available(&out).anchor), (1, 1)); } +/// Asserts another text node is another owner, and re-entering the same node changes the +/// context generation while keeping the owner key. #[test] fn a_new_edit_session_and_another_text_node_are_new_ime_owners() { figcraft_text::scan_system_fonts(); @@ -405,6 +431,8 @@ fn a_new_edit_session_and_another_text_node_are_new_ime_owners() { assert_ne!(again.context_generation, first.context_generation, "re-entering is a replaced target"); } +/// Asserts an accepted commit survives a discarded rerun without inserting twice and keeps +/// its `InputMethod` cause, while a mixed rerun is `Other`. #[test] fn an_accepted_commit_survives_a_discarded_pass_without_reapplying_or_losing_its_cause() { figcraft_text::scan_system_fonts(); @@ -428,6 +456,9 @@ fn an_accepted_commit_survives_a_discarded_pass_without_reapplying_or_losing_its assert_eq!(mixed.change_cause, ImeChangeCause::Other); } +/// Asserts IME context state is scoped per viewport: each viewport has its own generation, +/// the root keeps its context across an aux pass, and a closed aux viewport does not inherit +/// the old generation. #[test] fn ime_context_state_is_scoped_per_viewport() { figcraft_text::scan_system_fonts(); @@ -480,6 +511,7 @@ fn ime_context_state_is_scoped_per_viewport() { assert_ne!(aux_again.context_generation, aux_ime.context_generation); } +/// Asserts the engine's IME surrounding-text byte limit equals egui's wire limit. #[test] fn the_engine_surrounding_limit_matches_the_wire_limit() { // A divergence would truncate or overrun the bounded payload silently. @@ -488,6 +520,8 @@ fn the_engine_surrounding_limit_matches_the_wire_limit() { assert_eq!(engine, wire); } +/// Asserts a frame observes the IME exactly once in both the editor pass and the Home +/// early-return pass. #[test] fn a_frame_observes_the_ime_once_even_when_it_ends_early() { figcraft_text::scan_system_fonts(); @@ -506,6 +540,8 @@ fn a_frame_observes_the_ime_once_even_when_it_ends_early() { assert_eq!(u.app.ime_observations - before, 1, "one idle observation on the home screen"); } +/// Asserts a double-click inside an existing edit selects the word without changing the IME +/// owner or generation. #[test] fn a_double_click_inside_the_edit_keeps_the_ime_generation() { figcraft_text::scan_system_fonts(); @@ -536,6 +572,8 @@ fn a_double_click_inside_the_edit_keeps_the_ime_generation() { assert_eq!(available(&after).text, "Hello world"); } +/// Asserts a `window.new` that moves the edited file leaves the root window emitting no IME +/// descriptor. #[test] fn a_window_new_that_moves_the_edited_file_leaves_the_root_ime_idle() { figcraft_text::scan_system_fonts(); @@ -560,6 +598,8 @@ fn a_window_new_that_moves_the_edited_file_leaves_the_root_ime_idle() { assert!(out.platform_output.ime.is_none(), "the root must not emit a descriptor for a file it no longer shows"); } +/// Asserts a CRLF-normalized commit is application-origin (`Other`), and bare-newline and +/// control-only commits insert nothing. #[test] fn a_transformed_commit_is_application_origin_and_a_bare_newline_does_nothing() { figcraft_text::scan_system_fonts(); @@ -582,6 +622,8 @@ fn a_transformed_commit_is_application_origin_and_a_bare_newline_does_nothing() assert!(matches!(control.surrounding_text, IMESurroundingText::Available(_))); } +/// Asserts character deletion keeps the selection for the paired commit, which replaces it +/// and reports `InputMethod`. #[test] fn ime_delete_surrounding_chars_keeps_the_selection_for_the_paired_commit() { figcraft_text::scan_system_fonts(); diff --git a/crates/ui-egui/src/layers.rs b/crates/ui-egui/src/layers.rs index 42a9569e..0ce4fa7a 100644 --- a/crates/ui-egui/src/layers.rs +++ b/crates/ui-egui/src/layers.rs @@ -134,6 +134,8 @@ pub fn rail(app: &mut FigApp, ui: &mut Ui) { } } +/// Draw the left panel: versions when open, otherwise the file/Assets header with in-place +/// file rename and collapse control, followed by Pages and Layers or the Assets panel. pub fn left_panel(app: &mut FigApp, ui: &mut Ui) { if app.ui.versions.open { crate::versions::panel(app, ui); @@ -173,6 +175,8 @@ pub fn left_panel(app: &mut FigApp, ui: &mut Ui) { } } +/// Draw the page list with open/search/add controls, filtering, selection, rename, +/// reorder/drag and layer drop-to-page; Dev Mode allows opening pages but blocks mutations. fn pages(app: &mut FigApp, ui: &mut Ui) { let t = Tokens::get(ui.ctx()); // Dev Mode only inspects: rows open pages, but don't add, rename, reorder, duplicate or delete. @@ -444,6 +448,7 @@ struct Sweep { ids: Vec, } +/// Stable egui id for the eye/padlock sweep state. fn sweep_id() -> Id { Id::unique("layer_toggle_sweep") } @@ -654,6 +659,7 @@ fn rename_layer(app: &mut FigApp, id: NodeId) { app.ui.layers_seen_sel = app.session.selection(); } +/// Stable egui id for a layer row's rename field. fn rename_id(id: NodeId) -> Id { Id::unique(("rename", id)) } @@ -722,6 +728,8 @@ fn search_field(ui: &mut Ui, t: &Tokens, w: f32, id: Id, hint: &str, text: &mut } } +/// Draw the layer tree with search, cached rows, reveal-selection expansion and scrolling, +/// rename/Tab navigation, selection and drag/drop, sweep toggles and Dev Mode restrictions. fn layers(app: &mut FigApp, ui: &mut Ui) { let t = Tokens::get(ui.ctx()); // Dev Mode only inspects: rows select and expand, but don't rename, reorder, hide or lock. diff --git a/crates/ui-egui/src/layers_behaviour_tests.rs b/crates/ui-egui/src/layers_behaviour_tests.rs index e801ad00..0f312499 100644 --- a/crates/ui-egui/src/layers_behaviour_tests.rs +++ b/crates/ui-egui/src/layers_behaviour_tests.rs @@ -312,6 +312,7 @@ fn pages_down_to(u: &mut Ui, to: f32) -> Vec { opened } +/// Asserts a 60-page list scrolls with the wheel to its last page, past its first pages. #[test] fn a_long_pages_list_scrolls_and_leaves_room_for_the_layers() { let mut s = Session::new(); @@ -383,6 +384,8 @@ fn double_click_checking_focus(u: &mut Ui, p: Pos2) { } } +/// Asserts double-clicking a page selects and renames it, with the keyboard in its name +/// field for the screen-reader tree. #[test] fn double_clicking_a_page_renames_it_with_the_focus_in_the_screen_reader_tree() { let mut s = Session::new(); diff --git a/crates/ui-egui/src/layers_rename_tests.rs b/crates/ui-egui/src/layers_rename_tests.rs index 6ffa9696..c1c229eb 100644 --- a/crates/ui-egui/src/layers_rename_tests.rs +++ b/crates/ui-egui/src/layers_rename_tests.rs @@ -144,6 +144,8 @@ fn rename_without_a_name_renames_one_row_or_opens_the_dialog() { assert!(std::sync::Arc::ptr_eq(&doc, &s.ds().unwrap().doc)); } +/// Asserts a layer rename continues after its row is scrolled out of view and commits on +/// Enter. #[test] fn a_rename_scrolled_out_of_view_goes_on() { let mut s = Session::new(); diff --git a/crates/ui-egui/src/layout_panel.rs b/crates/ui-egui/src/layout_panel.rs index eef37755..0874da2f 100644 --- a/crates/ui-egui/src/layout_panel.rs +++ b/crates/ui-egui/src/layout_panel.rs @@ -283,6 +283,8 @@ fn add_slot(ui: &mut Ui, label: &str, tip: &str, width: f32) -> egui::Response { resp } +/// Draw the 3×3 main/cross alignment grid, auto-gap modes, grid column/row gaps and the +/// horizontal baseline checkbox. fn alignment(app: &mut FigApp, ui: &mut Ui, ids: &[NodeId], l: &AutoLayout) { let t = Tokens::get(ui.ctx()); let grid_mode = l.mode == LayoutMode::Grid; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index d3c17453..6f0effd8 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -488,6 +488,7 @@ pub struct FrameClock { } impl Default for FrameClock { + /// Start the frame clock at the current web time with no injected test time. fn default() -> Self { Self { origin: web_time::Instant::now(), test_now: None } } @@ -722,6 +723,9 @@ pub struct UiState { } impl Default for UiState { + /// Seed the default UI state (panel widths, tabs, pages, Home, presenters, pickers and + /// dialogs off, and the rest of the transient UI fields); `FigApp::new` overrides panel + /// widths and the pages height from preferences. fn default() -> Self { Self { left_width: PANEL_DEFAULT, @@ -915,6 +919,9 @@ pub struct FigApp { pub type Done = Box; impl FigApp { + /// Construct `FigApp` from a session and services, taking panel widths and pages height + /// from preferences and initializing UI, canvas, clocks, capture/IME and transient channel + /// state. pub fn new(session: Session, services: Box) -> Self { // The main window's panels open as wide as they were left. let (left_width, right_width) = session.prefs.panel_widths; @@ -2044,6 +2051,9 @@ impl FigApp { } } + /// Draw the toast: start its lifetime on the frame **after** the first drawn frame, request + /// that frame and the frame that hides it, expire and remove it at the deadline, and place it + /// at the bottom centre. fn toast_ui(&mut self, ctx: &egui::Context) { let Some((msg, clock)) = &mut self.ui.toast else { return }; let now = ctx.input(|i| i.time); diff --git a/crates/ui-egui/src/live_join_tests.rs b/crates/ui-egui/src/live_join_tests.rs index 81eddc76..bc1db8ad 100644 --- a/crates/ui-egui/src/live_join_tests.rs +++ b/crates/ui-egui/src/live_join_tests.rs @@ -14,6 +14,7 @@ fn escape(h: &mut Harness) { } } +/// Whether the Join link field currently has focus. fn link_focused(h: &Harness) -> bool { h.ctx.memory(|m| m.has_focus(egui::Id::unique("live_join_link"))) } diff --git a/crates/ui-egui/src/live_server_tests.rs b/crates/ui-egui/src/live_server_tests.rs index 0bf1e631..014be152 100644 --- a/crates/ui-egui/src/live_server_tests.rs +++ b/crates/ui-egui/src/live_server_tests.rs @@ -20,6 +20,7 @@ fn key(h: &mut Harness, key: Key) { } } +/// Whether the widget with the given id currently has focus. fn focused(h: &Harness, id: &str) -> bool { h.ctx.memory(|m| m.has_focus(egui::Id::unique(id))) } diff --git a/crates/ui-egui/src/live_share_tests.rs b/crates/ui-egui/src/live_share_tests.rs index 06d902bd..d7fc61c8 100644 --- a/crates/ui-egui/src/live_share_tests.rs +++ b/crates/ui-egui/src/live_share_tests.rs @@ -385,6 +385,9 @@ fn without_a_code_the_link_is_shared_instead() { assert_eq!(script.lock().unwrap().copied.last().map(String::as_str), Some(PLAIN)); } +/// Asserts the join field accepts a typed code or invite link, joins on Enter, clears after +/// joining, shows failure/retry, rejects an invalid code with an error, and accepts local +/// codes and links. #[test] fn the_join_field_takes_a_code_or_a_link_and_enter_joins() { let (mut h, script) = harness(); @@ -450,6 +453,8 @@ fn the_home_screen_joins_with_a_code_and_opens_the_file() { assert_eq!(h.app.session.docs.len(), 2); } +/// Asserts the join dialog uses the same shared join field, focuses it, and closes once the +/// join starts. #[test] fn the_join_dialog_is_the_same_field() { let (mut h, script) = harness(); diff --git a/crates/ui-egui/src/live_tests.rs b/crates/ui-egui/src/live_tests.rs index eaff7354..63c3c42a 100644 --- a/crates/ui-egui/src/live_tests.rs +++ b/crates/ui-egui/src/live_tests.rs @@ -290,6 +290,8 @@ fn cursors_follow_pages_in_a_shared_document() { assert_eq!(h.app.ui.toast.as_ref().map(|t| t.0.as_str()), Some("Hana left")); } +/// Asserts clicking a peer's avatar follows that peer, and Escape or scrolling the canvas +/// stops following. #[test] fn clicking_an_avatar_follows_and_escape_stops() { let (mut h, _) = Harness::new(); diff --git a/crates/ui-egui/src/menu_aim_tests.rs b/crates/ui-egui/src/menu_aim_tests.rs index ed167e12..6f7c4b8a 100644 --- a/crates/ui-egui/src/menu_aim_tests.rs +++ b/crates/ui-egui/src/menu_aim_tests.rs @@ -87,6 +87,7 @@ impl Ui { const TOPS: [&str; 6] = ["File", "Edit", "View", "Object", "Text", "Arrange"]; +/// Stable id for a top-level menu in the menu-aim test harness. fn top(name: &str) -> Id { Id::unique(("menu", name)) } @@ -145,6 +146,8 @@ fn a_reopened_main_menu_shows_no_stale_submenu() { assert!(u.tops_shown().is_empty(), "reopened with {:?} open", u.tops_shown()); } +/// Asserts leaving a top menu and returning to it does not restore the submenu that was open +/// before. #[test] fn a_submenu_one_level_down_reopens_closed() { let mut u = Ui::new(); diff --git a/crates/ui-egui/src/menu_input_tests.rs b/crates/ui-egui/src/menu_input_tests.rs index a50173bc..6fc65533 100644 --- a/crates/ui-egui/src/menu_input_tests.rs +++ b/crates/ui-egui/src/menu_input_tests.rs @@ -69,6 +69,8 @@ fn batch_rename_opens_its_existing_dialog() { assert!(ui.app.ui.last_error.is_none()); } +/// Asserts `file.rename` opens the left panel's inline file-name editor (not a dialog), +/// focuses it, and commits the typed name on Enter. #[test] fn rename_file_edits_the_file_name_in_place() { let mut ui = Ui::new(Session::new()); diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index e73d242d..e5ddb899 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -478,10 +478,12 @@ struct At { path: String, } +/// Scoped egui id for the current menu level. fn at_key(ui: &Ui) -> Id { ui.scope_id().with("menu_level") } +/// Return the current menu root/path, defaulting to the main menu root. fn level_at(ui: &Ui) -> At { ui.data(|d| d.get_temp::(at_key(ui))).unwrap_or(At { root: Id::unique("menus"), path: String::new() }) } @@ -817,6 +819,9 @@ const TOP_MENUS: &[&str] = &[ tr_noop("Help"), ]; +/// Draw the main and context menu trees: forget closed/stale submenu state, apply +/// control-channel Select-layer open/close, close on outside click or Escape, then draw the +/// colour picker and palette popups. pub fn popups(app: &mut FigApp, ctx: &egui::Context) { let t = Tokens::get(ctx); // A closed menu forgets its open submenus (and a context menu opened somewhere else starts @@ -1020,6 +1025,7 @@ pub fn popups(app: &mut FigApp, ctx: &egui::Context) { /// The context menu's Select layer submenu (its key in the context menu's tree). const SELECT_LAYER: &str = "Select layer"; +/// Stable egui id for the context menu's pending Select-layer open request. fn select_layer_ask_id() -> Id { Id::unique("ctx_select_layer_ask") } diff --git a/crates/ui-egui/src/panel_remove_tests.rs b/crates/ui-egui/src/panel_remove_tests.rs index a2e8d3ee..1608902d 100644 --- a/crates/ui-egui/src/panel_remove_tests.rs +++ b/crates/ui-egui/src/panel_remove_tests.rs @@ -64,10 +64,13 @@ fn remove_button(u: &mut Ui, list: &str, index: usize) -> Pos2 { .unwrap_or_else(|| panic!("no Remove button in {list} row {index} {row:?} {all:?}")) } +/// Read a temporary boolean open-settings flag keyed by `salt` and row index. fn flag(u: &Ui, salt: &'static str, i: usize) -> bool { u.ctx.data(|d| d.get_temp::(Id::unique((salt, i)))).unwrap_or(false) } +/// Asserts removing a fill keeps the open picker on the surviving paint (with its index +/// shifted), and removing the paint being edited closes the picker. #[test] fn removing_a_fill_keeps_the_picker_on_its_paint() { let mut s = Session::new(); @@ -93,6 +96,8 @@ fn removing_a_fill_keeps_the_picker_on_its_paint() { assert_eq!(u.app.ui.picker, None); } +/// Asserts removing effects or grids moves open settings and an open colour picker to the +/// surviving row, or closes them when their own row is removed. #[test] fn removing_effects_and_grids_keeps_open_settings_with_their_rows() { let mut s = Session::new(); diff --git a/crates/ui-egui/src/panel_reorder_tests.rs b/crates/ui-egui/src/panel_reorder_tests.rs index 54caa687..ffeb948e 100644 --- a/crates/ui-egui/src/panel_reorder_tests.rs +++ b/crates/ui-egui/src/panel_reorder_tests.rs @@ -73,6 +73,8 @@ fn escape_cancels_a_row_drag() { assert_eq!(u.app.session.ds().unwrap().selection, [r], "the Escape only cancels the drag"); } +/// Asserts effect and layout-grid rows reorder by drag, while a mixed fill list exposes no +/// drag handle. #[test] fn effects_and_grids_drag_too_and_mixed_lists_dont() { let (mut u, r) = setup(); diff --git a/crates/ui-egui/src/perf_tests.rs b/crates/ui-egui/src/perf_tests.rs index 7b5d1212..eba5e68c 100644 --- a/crates/ui-egui/src/perf_tests.rs +++ b/crates/ui-egui/src/perf_tests.rs @@ -68,6 +68,8 @@ impl Bench { } } +/// Build and print a synthetic UI benchmark report for the given layer count; it makes no +/// assertions. fn report(layers: usize) { let mut b = Bench::new(layers); let mut rows: Vec<(&str, f64)> = Vec::new(); @@ -180,6 +182,7 @@ fn design_system(icons: usize, instances: usize) -> (Document, figcraft_engine:: figcraft_engine::synthetic_ds::design_system_with_instances(&spec, instances).unwrap() } +/// Build a test mouse-wheel event for the given vertical delta. fn wheel(d: f32) -> Event { Event::MouseWheel { unit: egui::MouseWheelUnit::Point, diff --git a/crates/ui-egui/src/plugin_panel_tests.rs b/crates/ui-egui/src/plugin_panel_tests.rs index 3b0f2746..53b1ba56 100644 --- a/crates/ui-egui/src/plugin_panel_tests.rs +++ b/crates/ui-egui/src/plugin_panel_tests.rs @@ -89,6 +89,9 @@ fn an_open_plugin_panel_draws_no_frames_while_idle() { Harness::new(session()).assert_idle("a plugin panel"); } +/// Asserts a plugin colour field's swatch opens the picker on that field, a picked colour +/// reaches the plugin, and a second plugin's panel opens while the first remains (two panels +/// present). #[test] fn a_colour_field_opens_the_colour_picker_and_two_panels_show_side_by_side() { let mut u = Ui::new(session()); diff --git a/crates/ui-egui/src/plugins_ui.rs b/crates/ui-egui/src/plugins_ui.rs index 83295359..26479c4d 100644 --- a/crates/ui-egui/src/plugins_ui.rs +++ b/crates/ui-egui/src/plugins_ui.rs @@ -245,6 +245,9 @@ const INSTALL: &str = "plugin.directory.install"; const MANAGE_W: f32 = 400.0; const ROW_TEXT_W: f32 = 300.0; +/// Draw the Plugins window with installed and browse tabs, dispatching remove, import, +/// browse, confirm and stop actions; closing the window cancels its directory requests and +/// clears confirmation. fn manage_window(app: &mut FigApp, ctx: &Context) { let t = Tokens::get(ctx); let mut open = true; @@ -509,6 +512,8 @@ fn summary(p: &InstalledPlugin) -> String { parts.join(" · ") } +/// Draw a plugin command's parameter form: close it when the plugin or command disappeared, +/// edit values and colour picks, run `plugin.run` on Run, and close on Cancel. fn form_window(app: &mut FigApp, ctx: &Context) { let Some(mut form) = app.ui.plugin_form.clone() else { return }; let Some((name, command)) = app diff --git a/crates/ui-egui/src/present_tests.rs b/crates/ui-egui/src/present_tests.rs index 4679c15d..93729922 100644 --- a/crates/ui-egui/src/present_tests.rs +++ b/crates/ui-egui/src/present_tests.rs @@ -137,6 +137,8 @@ fn preview_pane_opens_follows_edits_and_the_selection() { assert!(u.app.ui.preview.is_none()); } +/// Asserts the preview's device viewport and scroll range, wheel and drag scrolling, the +/// end clamp with spring-back, and that navigation resets scroll to the top. #[test] fn the_frame_scrolls_on_the_device_screen_by_wheel_and_drag() { let (mut u, a, b, _) = setup(); diff --git a/crates/ui-egui/src/present_view_tests.rs b/crates/ui-egui/src/present_view_tests.rs index 97fbba03..361a4caf 100644 --- a/crates/ui-egui/src/present_view_tests.rs +++ b/crates/ui-egui/src/present_view_tests.rs @@ -135,6 +135,8 @@ fn num(v: &Value) -> f64 { v.as_f64().unwrap() } +/// Asserts presenter fit/fit-width/fill/actual scaling, pan ranges, wheel and drag panning, +/// option carry-over to the next presentation, and R restarting the flow. #[test] fn presenter_scales_by_its_options_and_pans_what_overflows() { let (mut u, big) = big(); @@ -272,6 +274,7 @@ fn scrolling_keeps_its_momentum_and_springs_back_from_the_ends() { assert_eq!(u.preview()["flinging"], json!(false)); } +/// Asserts wheel momentum continues after input stops and then comes to rest. #[test] fn the_wheel_coasts_after_it_stops() { let (mut u, a, ..) = setup(); diff --git a/crates/ui-egui/src/proto_canvas.rs b/crates/ui-egui/src/proto_canvas.rs index 1faba513..b5d402b4 100644 --- a/crates/ui-egui/src/proto_canvas.rs +++ b/crates/ui-egui/src/proto_canvas.rs @@ -20,6 +20,7 @@ struct Drag { pos: Pos2, } +/// Stable egui id for prototype connection dragging. fn drag_id() -> Id { Id::unique("proto_canvas_drag") } @@ -59,6 +60,8 @@ struct Sources { ids: Arc>, } +/// Return the cached subtree nodes with interactions for `page`, recomputing only when the +/// document pointer or page changes. pub(crate) fn sources(ctx: &egui::Context, doc: &Arc, page: NodeId) -> Arc> { ctx.data_mut(|d| { let c = d.get_temp_mut_or_default::(Id::unique("proto_canvas_sources")); diff --git a/crates/ui-egui/src/proto_editor.rs b/crates/ui-egui/src/proto_editor.rs index cc3c352b..7163807e 100644 --- a/crates/ui-egui/src/proto_editor.rs +++ b/crates/ui-egui/src/proto_editor.rs @@ -129,6 +129,7 @@ fn unavailable(label: &str) -> &'static str { } } +/// Stable egui id for a node interaction's open action path. fn open_id(cx: &Cx) -> Id { Id::unique(("proto_open_action", cx.node, cx.k)) } diff --git a/crates/ui-egui/src/proto_editor_tests.rs b/crates/ui-egui/src/proto_editor_tests.rs index e6838a0a..63c152e1 100644 --- a/crates/ui-egui/src/proto_editor_tests.rs +++ b/crates/ui-egui/src/proto_editor_tests.rs @@ -78,6 +78,9 @@ fn condition(u: &Ui, btn: NodeId, block: usize) -> String { blocks[block].condition.as_ref().map(|c| c.display(&doc.variables)).unwrap_or_default() } +/// Asserts the interaction editor shows conditional blocks and nested actions, restarts a +/// condition when a variable of another type is picked, ignores a right-hand-side variable pick +/// for a complex condition, and one undo restores the previous condition. #[test] fn the_interaction_editor_shows_conditionals_and_picks_their_variables() { let (mut s, _, b, btn) = setup(); @@ -154,6 +157,8 @@ fn the_builder_takes_variable_operator_value_conditions() { } } +/// Asserts invalid typed conditions keep their draft and show errors without saving, a valid +/// one clears the error and saves, and Enter does not leak to shortcuts. #[test] fn typed_conditions_are_checked_and_errors_show_until_fixed() { let (mut s, _, b, btn) = setup(); diff --git a/crates/ui-egui/src/proto_panel.rs b/crates/ui-egui/src/proto_panel.rs index 972f068b..1b2e2df9 100644 --- a/crates/ui-egui/src/proto_panel.rs +++ b/crates/ui-egui/src/proto_panel.rs @@ -426,6 +426,8 @@ fn flows_overview(app: &mut FigApp, ui: &mut Ui, doc: &Document, page: NodeId) { } } +/// Draw prototype settings: device and rotation, device colour, custom size, responsive +/// toggle and page background, running `proto.settings`. fn settings(app: &mut FigApp, ui: &mut Ui, doc: &Document, page: NodeId) { if widgets::section_header(ui, tr("Prototype settings"), &[(Icon::Preview, tr("Open prototype preview"))], false).is_some() { app.run("proto.preview", json!({})); @@ -552,6 +554,7 @@ fn custom_size(app: &mut FigApp, ui: &mut Ui, model: Option) { }); } +/// Show, create or preview the flow starting at `frame` and edit its description. fn flow_section(app: &mut FigApp, ui: &mut Ui, doc: &Document, page: NodeId, frame: NodeId) { let flows = flows_of(doc, page); let mine = flows.iter().find(|f| f.start == frame).cloned(); @@ -579,6 +582,8 @@ fn flow_section(app: &mut FigApp, ui: &mut Ui, doc: &Document, page: NodeId, fra } } +/// List a node's interactions, add a default click navigation (or Back), open the editor +/// popover and remove interactions. fn interactions(app: &mut FigApp, ui: &mut Ui, doc: &Document, page: NodeId, node: &Node) { let t = Tokens::get(ui.ctx()); let id = node.id; @@ -696,6 +701,7 @@ fn animates(a: &Action) -> bool { ) } +/// Stable egui id for the prototype key-capture flag. fn capture_id() -> Id { Id::unique("proto_key_capture") } @@ -704,6 +710,8 @@ fn capturing(ctx: &egui::Context) -> bool { ctx.data(|d| d.get_temp::(capture_id())).unwrap_or(false) } +/// Draw an interaction's trigger controls: trigger picker, mouse/delay fields, key capture +/// and controller-button selection, patching the interaction. fn trigger_rows(app: &mut FigApp, ui: &mut Ui, node: NodeId, k: usize, it: &Interaction) { let t = Tokens::get(ui.ctx()); widgets::sublabels(ui, tr("Trigger"), None); @@ -1021,6 +1029,8 @@ pub(crate) fn action_fields(app: &mut FigApp, ui: &mut Ui, doc: &Document, page: } } +/// Draw an interaction's animation controls: transition, direction, easing, duration and +/// custom easing fields, plus an animated curve preview. fn animation_rows(app: &mut FigApp, ui: &mut Ui, node: NodeId, k: usize, it: &Interaction) { let t = Tokens::get(ui.ctx()); widgets::sublabels(ui, tr("Animation"), None); diff --git a/crates/ui-egui/src/proto_reorder_tests.rs b/crates/ui-egui/src/proto_reorder_tests.rs index 1f70f48d..d69be4f6 100644 --- a/crates/ui-egui/src/proto_reorder_tests.rs +++ b/crates/ui-egui/src/proto_reorder_tests.rs @@ -44,6 +44,7 @@ fn setup() -> (Ui, NodeId) { (u, btn) } +/// Stable id for a prototype node's open action path in the reorder tests. fn open_id(btn: NodeId) -> egui::Id { egui::Id::unique(("proto_open_action", btn, 0usize)) } diff --git a/crates/ui-egui/src/right.rs b/crates/ui-egui/src/right.rs index e2dca4a6..a084b9d0 100644 --- a/crates/ui-egui/src/right.rs +++ b/crates/ui-egui/src/right.rs @@ -78,6 +78,8 @@ impl FigApp { } } +/// Draw the right panel: people, present and share controls, Design/Prototype tabs and zoom +/// menu, then route the scroll area to comments, frame presets, design, prototype or inspect. pub fn right_panel(app: &mut FigApp, ui: &mut Ui) { let t = Tokens::get(ui.ctx()); let w = ui.available_width(); @@ -393,6 +395,8 @@ fn design(app: &mut FigApp, ui: &mut Ui) { crate::export_panel::section(app, ui, &doc, &sel); } +/// Draw the page section: background and colour profile, local variables/styles, and the +/// page export section. fn page_section(app: &mut FigApp, ui: &mut Ui, doc: &Document) { let t = Tokens::get(ui.ctx()); let Ok(page) = app.session.page() else { return }; @@ -455,6 +459,8 @@ fn page_section(app: &mut FigApp, ui: &mut Ui, doc: &Document) { crate::export_panel::page_section(app, ui, doc, page); } +/// Draw the selection header: type name (or Mixed), frame/group conversion, orientation +/// swap and frame presets, component/mask/boolean quick actions, and instance details. fn header(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId]) { let t = Tokens::get(ui.ctx()); let label = match common(doc, sel, |n| n.kind.label()) { @@ -589,6 +595,8 @@ fn position(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId]) { ui.add_space(8.0); } +/// Draw alignment and distribution, X/Y and rotation with flip/rotate controls, the +/// absolute-position toggle and frame constraints. fn position_fields(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId]) { let ids = sel.to_vec(); let col = widgets::col_width(ui.available_width()); @@ -807,6 +815,8 @@ fn pretty(s: &str) -> String { } } +/// Draw visibility/blend/mask, opacity, uniform or per-corner radius, corner smoothing and +/// the blend-mode row. fn appearance(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId]) { let ids = sel.to_vec(); let visible = common(doc, sel, |n| n.visible).unwrap_or(true); @@ -1080,6 +1090,8 @@ fn range_fill(app: &mut FigApp, ui: &mut Ui, doc: &Document, id: NodeId, start: }); } +/// Draw a selected-text range fill, or the fill/stroke paint rows with add, style, reorder, +/// stroke align/weight, per-side weights and advanced stroke settings. fn paints(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId], fills: bool) { if fills && let Some((id, a, b)) = figcraft_engine::textedit::selected_range(&app.session) @@ -1641,6 +1653,8 @@ fn paint_label(p: &Paint) -> String { } } +/// Draw the effect list with add/style/type/toggle/remove/reorder, open settings, and keep an +/// open picker and settings flags aligned when rows move or are removed. fn effects(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId]) { let ids = sel.to_vec(); let list = common(doc, sel, |n| n.effects.clone()); @@ -1723,6 +1737,8 @@ fn fx_field(app: &mut FigApp, ui: &mut Ui, ids: &[NodeId], i: usize, prop: &str, crate::variable_ui::number_field(app, ui, ids, &format!("effects/{i}/{prop}"), Id::unique(("fx", prop, i)), lead, Some(value), "", width) } +/// Draw type-specific effect fields for shadows, blurs, noise, texture and glass, using live +/// scrub edits that stay one undo step and bindable colour fields. fn effect_settings(app: &mut FigApp, ui: &mut Ui, ids: &[NodeId], i: usize, e: &Effect) { let half = (ui.available_width() - PAD * 2.0 - 8.0) / 2.0; let set = |app: &mut FigApp, e2: Effect, scrub: Option| { @@ -1959,6 +1975,8 @@ fn fx_color(app: &mut FigApp, ui: &mut Ui, ids: &[NodeId], i: usize, e: &Effect, } } +/// Draw the layout-grid list with add/style/type/toggle/remove/reorder, per-grid settings, +/// and keep open-settings flags aligned when rows move or are removed. fn grids(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId]) { let ids = sel.to_vec(); let list = common(doc, sel, |n| n.grids.clone()); diff --git a/crates/ui-egui/src/rtl_names_tests.rs b/crates/ui-egui/src/rtl_names_tests.rs index c88ab267..22f59817 100644 --- a/crates/ui-egui/src/rtl_names_tests.rs +++ b/crates/ui-egui/src/rtl_names_tests.rs @@ -34,6 +34,7 @@ fn caret_x(ctx: &egui::Context, text: &str, cursor: CCursor) -> f32 { ctx.fonts_mut(|f| f.layout_no_wrap(text.to_string(), regular(11.0), Color32::WHITE).pos_from_cursor(cursor).min.x) } +/// Read the primary character cursor of a test text field. fn cursor(ctx: &egui::Context, id: Id) -> CCursor { egui::TextEdit::load_state(ctx, id).unwrap().cursor.char_range().unwrap().primary } @@ -75,6 +76,8 @@ fn fonts() -> Option { Some(ctx) } +/// Asserts names keep their logical text while glyphs paint in visual order, including +/// ellipsis placement at the overflow end and mixed-direction rows. #[test] fn names_keep_logical_text_and_paint_in_visual_order() { let Some(ctx) = fonts() else { return }; @@ -137,6 +140,8 @@ fn names_keep_logical_text_and_paint_in_visual_order() { }); } +/// Asserts Arabic letters take joined contextual forms and truncation puts the ellipsis at +/// the visual end of a right-to-left row. #[test] fn arabic_joining_and_truncation_use_the_visual_end() { let Some(ctx) = fonts() else { return }; @@ -177,6 +182,8 @@ fn arabic_joining_and_truncation_use_the_visual_end() { }); } +/// Asserts the shaper mirrors right-to-left parentheses in both glyph order and the atlas +/// shapes chosen for them. #[test] fn rtl_brackets_are_mirrored_by_the_shaper() { let Some(ctx) = fonts() else { return }; @@ -211,6 +218,8 @@ fn rtl_brackets_are_mirrored_by_the_shaper() { }); } +/// Asserts Right/Left move the caret visually while logical offsets jump, Shift extends +/// visually, and typing inserts at the logical caret; Latin text keeps egui's own caret. #[test] fn rename_caret_moves_visually_with_logical_offsets() { let Some(ctx) = fonts() else { return }; @@ -266,6 +275,8 @@ fn rename_caret_moves_visually_with_logical_offsets() { assert_eq!(caret(&ctx, lid).0, 2); } +/// Asserts clicks map right-to-left visual positions to logical carets, so a click at the +/// visual left end leaves the caret at the logical end and typing appends there. #[test] fn clicks_place_the_logical_caret_by_what_is_shown() { let Some(ctx) = fonts() else { return }; diff --git a/crates/ui-egui/src/section_panel.rs b/crates/ui-egui/src/section_panel.rs index 586a5597..f3240d57 100644 --- a/crates/ui-egui/src/section_panel.rs +++ b/crates/ui-egui/src/section_panel.rs @@ -48,6 +48,9 @@ pub fn status_dropdown(app: &mut FigApp, ui: &mut Ui, doc: &Document, ids: &[Nod }); } +/// Draw section colour and hide-contents controls, Dev status, changed-reason Resolve, the +/// last-change note and Resize to fit; returns for an empty selection or one without a Dev +/// status. pub fn section(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId]) { let sections = !sel.is_empty() && sel.iter().all(|i| is_section(doc, *i)); if sel.is_empty() || !sel.iter().all(|i| has_status(doc, *i)) { diff --git a/crates/ui-egui/src/select_all_tests.rs b/crates/ui-egui/src/select_all_tests.rs index a68a6854..d86de12d 100644 --- a/crates/ui-egui/src/select_all_tests.rs +++ b/crates/ui-egui/src/select_all_tests.rs @@ -45,6 +45,7 @@ fn selection(ctx: &egui::Context, te: Id) -> Option<(usize, usize)> { Some((a.min(b), a.max(b))) } +/// Asserts clicking a hex field focuses it and selects all six characters. #[test] fn a_click_into_a_hex_field_selects_it_all() { let ctx = egui::Context::default(); @@ -57,6 +58,7 @@ fn a_click_into_a_hex_field_selects_it_all() { assert_eq!(selection(&ctx, id.with("te")), Some((0, 6))); } +/// Asserts clicking an inline field selects it all and typing replaces the selection. #[test] fn a_click_into_an_inline_field_selects_it_all() { // A fill's hex in the Design panel, a variable's value, a rename. @@ -75,6 +77,7 @@ fn a_click_into_an_inline_field_selects_it_all() { assert_eq!(out.as_deref(), Some("red")); } +/// Asserts clicking a search box selects its whole query. #[test] fn a_click_into_a_search_box_selects_its_query() { let ctx = egui::Context::default(); @@ -87,6 +90,7 @@ fn a_click_into_a_search_box_selects_its_query() { assert_eq!(selection(&ctx, id), Some((0, 6))); } +/// Asserts Tab focus selects a field's whole value. #[test] fn tab_into_a_field_selects_it_all() { let ctx = egui::Context::default(); @@ -106,6 +110,7 @@ fn tab_into_a_field_selects_it_all() { assert_eq!(selection(&ctx, id), Some((0, 7))); } +/// Asserts a drag selects a non-empty proper subrange rather than the whole value. #[test] fn a_drag_selects_only_what_it_covers() { let ctx = egui::Context::default(); @@ -120,6 +125,7 @@ fn a_drag_selects_only_what_it_covers() { assert!(!(a == 0 && b == q.chars().count()), "not all of it: {a}..{b}"); } +/// Asserts re-clicking a field after focus was lost mid-edit selects all. #[test] fn a_field_left_mid_edit_selects_all_on_the_next_click() { let ctx = egui::Context::default(); diff --git a/crates/ui-egui/src/selection_colors.rs b/crates/ui-egui/src/selection_colors.rs index c699788b..682b37fe 100644 --- a/crates/ui-egui/src/selection_colors.rs +++ b/crates/ui-egui/src/selection_colors.rs @@ -24,6 +24,9 @@ struct Cache { colors: Arc>, } +/// Return the cached selection colours when the document and selection match. During an +/// interaction reuse an existing matching cache, or return an empty list without discovering +/// colours; otherwise discover and cache them. fn colors(ui: &Ui, document: u64, doc: &Arc, ids: &[NodeId], interacting: bool) -> Arc> { let key = Id::unique("selection_colors_cache"); if let Some(cache) = ui.data(|d| d.get_temp::(key)) @@ -49,6 +52,9 @@ pub(crate) fn open_picker(app: &mut FigApp, targets: Vec) { app.ui.picker = Some(PickerTarget::SelectionColor { targets, selection: ds.selection.clone(), document: ds.uid }); } +/// Draw the selection-colour groups (at least two): swatch opens the picker, hex and opacity +/// edits, style/variable detach/apply/bind, and “select layers with this color”; disabled +/// during an interaction. pub fn section(app: &mut FigApp, ui: &mut Ui, doc: &Arc, ids: &[NodeId]) { let Ok(ds) = app.session.ds() else { return }; let interacting = ds.interaction.is_some(); @@ -249,6 +255,8 @@ mod tests { assert!(!p.frame(vec![]).iter().any(|(s, _)| s == "Selection colors")); } + /// Asserts the panel reuses cached colours through a live interaction and refreshes the cache + /// after the commit. #[test] fn panel_keeps_cached_colors_during_interaction_and_refreshes_after_commit() { let (mut p, a, _) = Panel::new(); @@ -268,6 +276,8 @@ mod tests { assert!(!Arc::ptr_eq(&before.colors, &after.colors)); } + /// Asserts no cached colours are discovered during an interaction, and cancelling restores + /// the panel with the original colours. #[test] fn panel_defers_discovery_without_a_matching_cache_during_interaction() { let (mut p, a, _) = Panel::new(); diff --git a/crates/ui-egui/src/selection_spacing.rs b/crates/ui-egui/src/selection_spacing.rs index 7d1d27b4..414348bb 100644 --- a/crates/ui-egui/src/selection_spacing.rs +++ b/crates/ui-egui/src/selection_spacing.rs @@ -24,6 +24,8 @@ struct LayoutCache { reorder: Option>, } +/// Return one cached spacing/reorder calculation per document, page, selection and frame, +/// refreshing next frame after an edit and reusing an unchanged document snapshot. fn layout(app: &FigApp, ctx: &egui::Context, ids: &[NodeId]) -> Arc { let Ok(ds) = app.session.ds() else { return Arc::new(SelectionSpacing::default()) }; let key = Id::unique("selection_spacing_layout"); @@ -52,11 +54,13 @@ fn layout(app: &FigApp, ctx: &egui::Context, ids: &[NodeId]) -> Arc Option> { layout(app, ctx, ids); ctx.data(|d| d.get_temp::(Id::unique("selection_spacing_layout"))).and_then(|c| c.reorder) } +/// Stable egui id for spacing/reorder drag state. fn drag_id() -> Id { Id::unique("selection_spacing_drag") } @@ -107,6 +111,8 @@ fn start_drag(app: &mut FigApp, ctx: &egui::Context, ids: Vec, p: Pos2, } } +/// Draw horizontal and vertical spacing fields, running `arrange.spacing` with +/// `fromGesture`. pub fn panel(app: &mut FigApp, ui: &mut Ui, ids: &[NodeId]) { let layout = layout(app, ui.ctx(), ids); if layout.horizontal.is_none() && layout.vertical.is_none() { diff --git a/crates/ui-egui/src/selection_spacing_tests.rs b/crates/ui-egui/src/selection_spacing_tests.rs index aaeaabc3..b4b384d0 100644 --- a/crates/ui-egui/src/selection_spacing_tests.rs +++ b/crates/ui-egui/src/selection_spacing_tests.rs @@ -43,6 +43,7 @@ fn drag(u: &mut Ui, p: Pos2, by: egui::Vec2, release: bool) { } } +/// Asserts typed and scrubbed spacing changes take effect with exactly one undo step. #[test] fn spacing_fields_type_scrub_and_keep_one_undo_step() { let (mut u, ids) = scene(true); @@ -88,6 +89,8 @@ fn canvas_gap_drag_keeps_selection_and_undo_redo_for_both_grid_axes() { } } +/// Asserts Escape rolls a spacing drag back, and releasing outside the window commits once +/// while keeping the selection. #[test] fn escape_rolls_back_and_an_outside_release_finishes_the_gesture() { let (mut u, ids) = scene(false); diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index 2abb1cfc..d47d9607 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -205,6 +205,9 @@ pub struct AfterFieldSave { } impl AfterFieldSave { + /// Run a deferred field-save binding only if the originating window still exists and owns + /// the document; temporarily activate that document, run the binding, then restore the + /// previously front tab. fn run(self, app: &mut FigApp) { // A closed file or one moved to another window cannot turn this into a save of the // current tab. The UiState normally stays in its window's pane; validate that too. @@ -299,6 +302,7 @@ pub(crate) fn revalidate_field_save(app: &FigApp, ctx: &Context, save: Option egui::Id { egui::Id::unique(("field_save_cancelled", ctx.viewport_id(), editor)) } @@ -644,12 +648,16 @@ pub(crate) struct ImeInputBaseline { } impl ImeInputBaseline { + /// Capture an IME baseline only while a text edit and an active preedit exist, recording + /// the IME target and the caret/anchor. pub(crate) fn capture(app: &FigApp) -> Option { let te = app.session.ds().ok()?.text_edit.as_ref()?; te.preedit.as_ref()?; Some(Self { target: ime_target(app)?, caret: te.caret, anchor: te.anchor }) } + /// Whether the IME target changed, editing or the preedit ended, or the caret/anchor moved + /// since the baseline was captured. fn interrupted(&self, app: &FigApp) -> bool { ime_target(app) != Some(self.target) || app @@ -661,6 +669,9 @@ impl ImeInputBaseline { } } +/// Apply a batch of text, IME, paste, copy, cut and key events: reject all IME events for an +/// interrupted composition, swallow text produced by a key that ran a shortcut, then finish +/// with triple-click line selection and preedit sync. fn text_keys(app: &mut FigApp, ctx: &Context, events: &[Event], ime_input: Option) { // Validate once before the batch: an accepted DeleteSurrounding deliberately clears preedit, // but its following Commit still belongs to the same valid transaction. An interrupted diff --git a/crates/ui-egui/src/style_picker_tests.rs b/crates/ui-egui/src/style_picker_tests.rs index f86ddd73..b732c11d 100644 --- a/crates/ui-egui/src/style_picker_tests.rs +++ b/crates/ui-egui/src/style_picker_tests.rs @@ -95,6 +95,8 @@ fn text_session() -> (Session, figcraft_doc::NodeId) { (s, t) } +/// Asserts hovering a text style previews it without an edit, leaving the popover restores +/// the value, and clicking applies one undo step and closes the picker. #[test] fn text_styles_preview_on_hover_and_apply_on_click() { let (s, t) = text_session(); diff --git a/crates/ui-egui/src/tabs.rs b/crates/ui-egui/src/tabs.rs index 92ff9f63..6f17910a 100644 --- a/crates/ui-egui/src/tabs.rs +++ b/crates/ui-egui/src/tabs.rs @@ -97,6 +97,8 @@ fn tab_drop_position(visible: &[(usize, Rect)], from: usize, pointer_x: f32) -> } } +/// Draw the top tab bar: Home, document and presenter tabs, new-tab and window controls, +/// open/close/reorder animation and tab closing, pausing the presenter when going Home. pub fn tab_bar(app: &mut FigApp, ui: &mut Ui) { let t = Tokens::get(ui.ctx()); egui::Panel::top("tab_bar").exact_size(HEIGHT).frame(egui::Frame::NONE.fill(t.tab_bar)).show(ui, |ui| { diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs index 80d1399c..9a384294 100644 --- a/crates/ui-egui/src/theme.rs +++ b/crates/ui-egui/src/theme.rs @@ -173,6 +173,7 @@ impl Tokens { } } +/// Stable id for temporary theme tokens. fn tokens_id() -> egui::Id { egui::Id::unique("figcraft_tokens") } @@ -436,6 +437,7 @@ pub fn c32(c: figcraft_color::Color) -> Color32 { Color32::from_rgba_unmultiplied(r, g, b, a) } +/// Stable id for the current document-to-screen colour conversion. fn screen_conversion_id() -> egui::Id { egui::Id::unique("figcraft_screen_conversion") } diff --git a/crates/ui-egui/src/theme_startup_tests.rs b/crates/ui-egui/src/theme_startup_tests.rs index 1ae40f58..c128a597 100644 --- a/crates/ui-egui/src/theme_startup_tests.rs +++ b/crates/ui-egui/src/theme_startup_tests.rs @@ -84,6 +84,8 @@ fn unavailable_system_theme_uses_the_existing_light_fallback() { assert_eq!(Tokens::get(&ctx), Tokens::light()); } +/// Checks that the test graph enables egui's `default_fonts` and `monochrome_emoji_fonts` +/// features by asserting both a Latin and an emoji glyph are available. #[test] fn tests_have_the_explicit_default_and_monochrome_emoji_font_features() { // 0.37 egui has no default features, and kittest's own dev-features do not propagate to this diff --git a/crates/ui-egui/src/titlebar_tests.rs b/crates/ui-egui/src/titlebar_tests.rs index 8fa4ad47..fff303ef 100644 --- a/crates/ui-egui/src/titlebar_tests.rs +++ b/crates/ui-egui/src/titlebar_tests.rs @@ -81,6 +81,8 @@ fn window_buttons_minimise_maximise_and_close() { assert!(u.frame(vec![]).contains(&ViewportCommand::Close)); } +/// Asserts closing the custom titlebar over a presenter with unsaved changes asks with the +/// unsaved-changes dialog instead of emitting `Close`. #[test] fn titlebar_close_asks_over_the_presenter_when_a_file_is_unsaved() { let mut u = Ui::new(TitleBar::Custom); diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index 7af3356a..8f8f6cc1 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -91,6 +91,7 @@ const BOARD_GROUPS: &[Group] = &[ Group::tools("comment", tr_noop("Comment"), &[(ToolId::Comment, Icon::Comment)]), ]; +/// Return the last tool index remembered for a toolbar group, falling back to `default`. fn remembered(ui: &Ui, key: &str, default: ToolId) -> ToolId { ui.data(|d| d.get_temp::(egui::Id::unique(("tb_last", key)))).and_then(|i| ToolId::ALL.get(i as usize).copied()).unwrap_or(default) } @@ -535,6 +536,8 @@ fn options_flyout(app: &mut FigApp, ui: &mut Ui, g: &Group, bottom_left: egui::P } } +/// Draw a tool group's flyout above its button, with keyboard/hover highlighting, remembered +/// selection when a tool is clicked, and Escape to close. fn flyout(app: &mut FigApp, ui: &mut Ui, g: &Group, bottom_left: egui::Pos2) { let t = Tokens::get(ui.ctx()); let item_h = 32.0; diff --git a/crates/ui-egui/src/type_settings_tests.rs b/crates/ui-egui/src/type_settings_tests.rs index cbde6cc1..421c1ce2 100644 --- a/crates/ui-egui/src/type_settings_tests.rs +++ b/crates/ui-egui/src/type_settings_tests.rs @@ -2,6 +2,8 @@ //! de paragraphe") stays inside the popover, which otherwise widened a little every frame. use egui::{Area, Id, Pos2, RawInput, Rect, vec2}; +/// Asserts a long type-settings row label does not widen the popover beyond 264 pt across +/// frames. #[test] fn a_long_label_does_not_widen_the_type_settings_popover() { let ctx = egui::Context::default(); diff --git a/crates/ui-egui/src/typography.rs b/crates/ui-egui/src/typography.rs index 33c0d5a0..f61aa183 100644 --- a/crates/ui-egui/src/typography.rs +++ b/crates/ui-egui/src/typography.rs @@ -1167,10 +1167,13 @@ const ROW: f32 = 26.0; /// The font list's tallest (it scrolls past that). const LIST_HEIGHT: f32 = 380.0; +/// Return the persisted list of recently used font families. fn recent_families(ctx: &egui::Context) -> Vec { ctx.data_mut(|d| d.get_persisted::>(Id::unique(RECENT_KEY))).unwrap_or_default() } +/// Remember a font family at the front of the recent list, removing an earlier +/// case-insensitive match and keeping at most eight entries. fn remember_family(ctx: &egui::Context, family: &str) { ctx.data_mut(|d| { let v = d.get_persisted_mut_or_default::>(Id::unique(RECENT_KEY)); @@ -1568,6 +1571,8 @@ mod variable_tests { assert!(p.app.ui.last_error.is_none(), "{:?}", p.app.ui.last_error); } + /// Asserts bound font family and style chips replace the dropdowns, a selected text range + /// offers no variable binding, and detaching restores the last values. #[test] fn bound_font_family_and_style_show_their_variables_and_detach() { let mut p = Panel::new(); diff --git a/crates/ui-egui/src/typography_scrub_tests.rs b/crates/ui-egui/src/typography_scrub_tests.rs index 1e629acf..9b95b8e5 100644 --- a/crates/ui-egui/src/typography_scrub_tests.rs +++ b/crates/ui-egui/src/typography_scrub_tests.rs @@ -44,6 +44,7 @@ impl Fields { out.textures_delta.clear(); out.platform_output.cursor_icon } + /// Screen position of a typography field's label/lead, used to start a scrub. fn lead(&self, key: &str) -> Pos2 { let rect = self.ctx.read_response(Id::unique(key).with("click")).unwrap().rect; Pos2::new(rect.min.x + 12.0, rect.center().y) @@ -157,6 +158,8 @@ fn typography_icon_scrub_changes_only_the_selected_characters_without_ending_tex assert_eq!(f.value("ty_ls"), 0.0); } +/// Asserts typography spacing fields accept typed percent units, commit on Enter, and +/// Escape restores the previous value without adding an undo step. #[test] fn typography_spacing_fields_still_accept_typed_units_and_escape_cancels() { let mut f = Fields::new(); diff --git a/crates/ui-egui/src/variable_ui.rs b/crates/ui-egui/src/variable_ui.rs index 776d8aae..fe822a1f 100644 --- a/crates/ui-egui/src/variable_ui.rs +++ b/crates/ui-egui/src/variable_ui.rs @@ -40,6 +40,7 @@ struct Picker { at: Pos2, } +/// Stable egui id for the variable picker. fn picker_id() -> Id { Id::unique("variable_picker") } diff --git a/crates/ui-egui/src/variables_panel.rs b/crates/ui-egui/src/variables_panel.rs index 2a9e3c04..372e3f04 100644 --- a/crates/ui-egui/src/variables_panel.rs +++ b/crates/ui-egui/src/variables_panel.rs @@ -173,6 +173,8 @@ pub fn show(app: &mut FigApp, ctx: &Context) { app.ui.variables = open.then_some(st); } +/// Draw the variables header: the title at the left, and the import/export/Close controls at the +/// right. fn header(app: &mut FigApp, ui: &mut Ui, open: &mut bool) { let t = Tokens::get(ui.ctx()); let (r, _) = ui.allocate_exact_size(vec2(ui.available_width(), 44.0), Sense::hover()); @@ -253,6 +255,7 @@ fn extend(app: &mut FigApp, lib: &str, c: &str, st: &mut Editor) { } } +/// Stable egui id for the rename field of a `Rename` target. fn rename_id(target: &Rename) -> Id { Id::unique(("var_rename", target)) } @@ -281,6 +284,8 @@ fn unique(base: &str, taken: impl Fn(&str) -> bool) -> String { (1..10_000).map(|k| if k == 1 { base.to_string() } else { format!("{base} {k}") }).find(|n| !taken(n)).unwrap_or_else(|| base.to_string()) } +/// Draw the collections sidebar with library headings, collection rows and a create-collection +/// button. fn sidebar(app: &mut FigApp, ui: &mut Ui, views: &[View], local: &Variables, st: &mut Editor) { let t = Tokens::get(ui.ctx()); let (hr, _) = ui.allocate_exact_size(vec2(SIDEBAR_W, 40.0), Sense::hover()); @@ -505,6 +510,8 @@ fn group_of(name: &str) -> &str { name.rsplit_once('/').map(|(g, _)| g).unwrap_or("") } +/// Draw the variables table for the selected collection: search, library/extended notes, +/// grouped rows, mode columns and the create-variable row when editable. fn table(app: &mut FigApp, ui: &mut Ui, view: &View, st: &mut Editor) { let t = Tokens::get(ui.ctx()); // A sidebar click this frame picked another source: shown next frame. @@ -594,6 +601,8 @@ fn table(app: &mut FigApp, ui: &mut Ui, view: &View, st: &mut Editor) { }); } +/// Draw a collection's mode header row with rename, duplicate, reorder and delete actions +/// and an add-mode button when the collection is editable and not extended. fn header_row(app: &mut FigApp, ui: &mut Ui, view: &View, coll: &Collection, st: &mut Editor, width: f32) { let t = Tokens::get(ui.ctx()); // An extended collection has the modes of the one it extends. diff --git a/crates/ui-egui/src/vector_panel.rs b/crates/ui-egui/src/vector_panel.rs index 29ae8726..07dda3ff 100644 --- a/crates/ui-egui/src/vector_panel.rs +++ b/crates/ui-egui/src/vector_panel.rs @@ -72,6 +72,8 @@ fn width_point(app: &mut FigApp, ui: &mut Ui, doc: &Document, ve: &VectorEdit) { ui.add_space(8.0); } +/// Draw the selected points' position, dimensions, corner radius, mirroring and per-point +/// stroke cap/join controls; the width tool delegates to its own panel. pub fn points(app: &mut FigApp, ui: &mut Ui, doc: &Document, ve: &VectorEdit) { if ve.tool == vectoredit::VTool::Width { width_point(app, ui, doc, ve); diff --git a/crates/ui-egui/src/versions.rs b/crates/ui-egui/src/versions.rs index 3519b610..19eb6a04 100644 --- a/crates/ui-egui/src/versions.rs +++ b/crates/ui-egui/src/versions.rs @@ -403,6 +403,8 @@ fn current_row(ui: &mut Ui, more: bool, active: bool) -> bool { !active && resp.on_hover_text(tr("Back to the current version")).clicked() } +/// Draw one version row with timeline, name, time, up to three description lines and a +/// more/context menu; returns the chosen preview, restore, edit, duplicate or delete action. fn version_row(ui: &mut Ui, row: &Row, last: bool, previewing: bool) -> Option { let t = Tokens::get(ui.ctx()); let w = ui.available_width(); diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index f356b797..a5dd2c7b 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -223,6 +223,9 @@ fn cancel_retargeted_field_save(ui: &mut Ui, id: Id) { ui.memory_mut(|m| m.surrender_focus(editor)); } +/// Implement the shared number field: label/icon lead, scrubbing, keyboard stepping and +/// typing, select-all when a click starts editing, bindable values and deferred-save +/// cancellation; returns an edit and/or bind event. fn number_field_impl( ui: &mut Ui, id: Id, diff --git a/crates/ui-egui/src/windows_tests.rs b/crates/ui-egui/src/windows_tests.rs index 55a7babd..0f5884dd 100644 --- a/crates/ui-egui/src/windows_tests.rs +++ b/crates/ui-egui/src/windows_tests.rs @@ -45,6 +45,8 @@ fn names(app: &FigApp) -> Vec { app.session.docs.iter().map(|d| d.doc.name.clone()).collect() } +/// Asserts closing a window in the presenter shows the unsaved-changes dialog and does not +/// dismiss the preview. #[test] fn closing_a_window_in_the_presenter_shows_the_unsaved_changes_dialog() { let mut session = Session::new(); @@ -104,6 +106,8 @@ fn windows_hold_tabs_and_close_with_their_files() { assert_eq!(app.session.ds().unwrap().doc.name, "A"); } +/// Asserts a hidden other window answers edits and inspection in its own file while the main +/// window keeps its file, and a capture parks with a deadline and times out once. #[test] fn another_hidden_window_answers_requests_that_need_no_frame_in_its_own_file() { let mut s = Session::empty(); @@ -180,6 +184,8 @@ fn a_request_for_a_window_on_screen_wakes_it_while_the_main_window_is_hidden() { assert!(woken.lock().unwrap().contains(&other), "the other window is asked to draw: {:?}", woken.lock().unwrap()); } +/// Asserts every direct UI frame clears the logic-tick marker so background work runs each +/// frame. #[test] fn every_direct_ui_frame_runs_background_work() { // Direct `App::ui` harnesses never call `App::logic`: the tick marker the UI pass consumes @@ -192,6 +198,8 @@ fn every_direct_ui_frame_runs_background_work() { } } +/// Asserts synthetic input for a child window reaches the pane that draws it, leaving the +/// main window's pane untouched. #[test] fn synthetic_input_for_a_child_window_reaches_the_pane_that_draws_it() { let mut s = Session::empty(); @@ -214,6 +222,8 @@ fn synthetic_input_for_a_child_window_reaches_the_pane_that_draws_it() { assert_eq!(crate::windows::take_input(&mut app, other), events, "the child's next frame takes its batch"); } +/// Asserts a child raw-input hook with no batch does not error or drain the root window's +/// pending acknowledgement. #[test] fn a_frame_without_a_batch_does_not_error_another_windows_acknowledgement() { let mut s = Session::empty(); @@ -238,6 +248,8 @@ fn a_frame_without_a_batch_does_not_error_another_windows_acknowledgement() { assert_eq!(app.input_acks[0].reply.id, json!(5)); } +/// Asserts a child window runs `viewport_setup` and its pane keeps the dark theme after the +/// swap back. #[test] fn a_child_window_runs_the_ui_setup_the_main_window_does() { // eframe calls `App::ui` only for the root window, so a child that draws while the root does @@ -263,6 +275,8 @@ fn a_child_window_runs_the_ui_setup_the_main_window_does() { assert_eq!(again, Some(json!(true))); } +/// Asserts a closed and later reused viewport does not inherit its old IME context +/// generation. #[test] fn an_emptied_window_forgets_its_ime_context() { // `windows::begin` ends the viewport when a window loses its last file; a later window that From 000c0e3d4e8f33c0e5e9c0b96aff73336b9a03c5 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sun, 25 Oct 2026 14:22:29 +0000 Subject: [PATCH 31/50] Scale per-point corner radius of vector layers in transform.scale Found while testing crates/engine/src/cmd/arrange.rs:~560 (scale_node, the Vector branch calling VectorNetwork::scale); crates/doc/src/vector.rs:631 (VectorNetwork::scale) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/engine/src/cmd/arrange.rs | 3 +++ crates/engine/src/scale_tool_tests.rs | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/crates/engine/src/cmd/arrange.rs b/crates/engine/src/cmd/arrange.rs index 10ad13e5..7ee1f2c1 100644 --- a/crates/engine/src/cmd/arrange.rs +++ b/crates/engine/src/cmd/arrange.rs @@ -497,6 +497,9 @@ pub fn scale_node(doc: &mut Document, id: NodeId, k: f64) -> Result<()> { } if let NodeKind::Vector { network } = &mut n.kind { network.scale(k, k); + for v in &mut network.vertices { + v.radius *= k; + } } n.width *= k; n.height *= k; diff --git a/crates/engine/src/scale_tool_tests.rs b/crates/engine/src/scale_tool_tests.rs index 647a7ce1..f61eba93 100644 --- a/crates/engine/src/scale_tool_tests.rs +++ b/crates/engine/src/scale_tool_tests.rs @@ -240,3 +240,17 @@ fn the_scale_tool_only_acts_on_handles() { assert_rect(bounds(&s, r), [10.0, 10.0, 110.0, 60.0]); assert!(near(s.doc().unwrap().node(r).unwrap().width, 100.0)); } + +#[test] +fn scale_node_scales_vector_point_corner_radius() { + let mut s = Session::new(); + let v = id_of(&ex(&mut s, "vector.create", json!({"points": [[0, 0], [100, 0], [100, 100], [0, 100]], "closed": true}))["id"]).unwrap(); + ex(&mut s, "node.set", json!({"id": v, "props": {"cornerRadius": 10}})); + ex(&mut s, "transform.scale", json!({"ids": [v], "factor": 2})); + let d = s.doc().unwrap(); + let NodeKind::Vector { network } = &d.node(v).unwrap().kind else { panic!("not a vector") }; + assert!(!network.vertices.is_empty()); + for vx in &network.vertices { + assert_eq!(vx.radius, 20.0, "corner radius scaled with the layer"); + } +} From 4eb5224f023a7baf70df5f3df9b785480324f6f8 Mon Sep 17 00:00:00 2001 From: skylar taylor-barrick Date: Sun, 25 Oct 2026 17:13:00 +0100 Subject: [PATCH 32/50] M0: correct egui 0.37 status docs and stabilize join-code regression --- crates/collab-net/src/code_tests.rs | 5 ++++- crates/ui-egui/src/windows.rs | 2 +- docs/egui-037-migration-plan.md | 8 ++++---- docs/gaps.md | 8 +++++--- docs/hardware-parity.md | 7 ++++--- docs/ui-parity.md | 5 +++-- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/crates/collab-net/src/code_tests.rs b/crates/collab-net/src/code_tests.rs index 7fe766ec..182f3782 100644 --- a/crates/collab-net/src/code_tests.rs +++ b/crates/collab-net/src/code_tests.rs @@ -103,7 +103,10 @@ fn a_local_code_with_the_wrong_secret_or_a_typo_doesnt_join() { assert!(host.live().peers.is_empty()); // A typing mistake is caught before anything connects. let mut typo: Vec = local.code().chars().collect(); - typo[7] = if typo[7] == 'A' { 'B' } else { 'A' }; + // The last symbol contains only checksum bits. Changing payload bits can collide with + // the eight-bit checksum, so it does not guarantee a malformed code. + let last = typo.last_mut().unwrap(); + *last = if *last == 'A' { 'B' } else { 'A' }; let e = guest.execute("collab.join", &json!({"code": typo.iter().collect::()})).unwrap_err().to_string(); assert!(e.contains("typing mistake"), "{e}"); // A view-only code doesn't exist here, and says where it does. diff --git a/crates/ui-egui/src/windows.rs b/crates/ui-egui/src/windows.rs index c9c9fdce..95ec721d 100644 --- a/crates/ui-egui/src/windows.rs +++ b/crates/ui-egui/src/windows.rs @@ -248,7 +248,7 @@ fn exchange(app: &mut FigApp, p: &mut Pane) { /// file, at screen point `at` (else beside this window). Returns its id. With one window (the /// browser) or a screen reader running, a file opens as a tab here instead (and the error says so). pub fn open(app: &mut FigApp, ctx: &Context, index: Option, path: Option<&str>, at: Option) -> Result { - // shortcut: eframe 0.36 gives only the main window an AccessKit adapter, so other windows have + // shortcut: eframe 0.37 gives only the main window an AccessKit adapter, so other windows have // no screen-reader tree; while a screen reader runs files stay tabs here. Upgrade when eframe // adapts every viewport. let one = if ctx.embed_viewports() { diff --git a/docs/egui-037-migration-plan.md b/docs/egui-037-migration-plan.md index 6cf1bb09..93fd815b 100644 --- a/docs/egui-037-migration-plan.md +++ b/docs/egui-037-migration-plan.md @@ -1088,10 +1088,10 @@ agent/model/tool signature; contributor credit remains username-only (`@skylarta real evidence exists. 12. **Lockfile resolution:** one egui family, one winit, one wgpu, one craft-window. If Cargo chooses two versions, stop and fix the pins rather than accepting a duplicate. -13. **AccessKit per-viewport:** 0.37's eframe integrations initialize adapters per created viewport - in the inspected source; this may remove the 0.36 “main window only” limitation, but it has not - been exercised with a screen reader here. Keep the tab fallback until a real test says - otherwise. +13. **AccessKit per-viewport:** the pinned 0.37 fork initializes the native AccessKit adapter only + for the root viewport; creating a secondary viewport does not initialize an adapter. The + “main window only” limitation remains, and no real screen-reader qualification is claimed. + Keep the tab fallback until secondary-window accessibility is implemented and tested. 14. **Automation screenshot thread:** the callback must not write files outside `file_access` confinement. The shared completion-slot design in 6.3 is required, not optional. diff --git a/docs/gaps.md b/docs/gaps.md index e76731e7..280b04c5 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -1,6 +1,6 @@ # Where FigCraft falls short of Figma -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (known gaps from the #1311 review in gaps 4, 14, 15 and 16; gap 16: measurements kept on the canvas, a read-only layers panel in Dev Mode; gap 24: boards and their tail; Dev Mode tail: import lines in layer trees, compare with versions, an inspect-only canvas; gap 5: reviewed Turkish, Czech and Indonesian drafts, the Japanese draft completed; reviewed Russian catalog and integer plurals; `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; sharing with a join code; text box sizes measured against documents re-saved by other software; live sessions per document; .fig export checked by opening written files in other software; experimental .fig export; keyboard shortcut parity suite and bindings; Simplified Chinese draft catalog; Latin American Spanish overlay; prototyping tail: gamepad triggers, widgets in prototypes, mode lookups; plugin directory on figcraft-server; Japanese and Korean draft catalogs and CJK UI fonts; plugin widgets and the plugin panel tail; French, German and Brazilian Portuguese draft catalogs; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and edit tail; dev resources links; extended collections tail; branch version history and finer list merges; comments and version history behaviour suite and fixes; canvas navigation, guides and grids behaviour suite and fixes; `.fig` import: editable vector networks, more layer kinds, variable prototype actions; `.fig` import, best effort: gap 1 down to its tail; Windows QA pass: everyday workflows on Windows 11, eight fixes incl. unsaved work kept after a crash or a forced quit; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; localization layer with a draft Spanish catalog; hosting figcraft-server: wss in the desktop app, server releases, deployment guide; plugin panels and settings; canvas fixes: boolean hit testing on the result, group drags, frame outlines and slices; code connect; stretch and scatter brushes, pen pressure; text on a path and pattern fills; team libraries on the server and swap library; branches: create, update from main, review and merge; animated GIF fills and TIFF images; Open recent, outlines for the selection and mask outlines: menu breadth 100%; extended collections, variables import/export, gradient stop and variant bindings: gap 14 down to its tail; the 2026-10-17 landings: `.fig` import fidelity, budgets for large files, the import report, a `.fig` copy from Save as and paste from another design app (gap 1); menus, the Actions palette, editor fixes, Selection colors and smart-selection spacing (gap 4); catalog counts re-measured (gap 5); bounded canvas pan overscan; reviewed Russian catalog and integer plurals; `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; sharing with a join code; text box sizes measured against documents re-saved by other software; live sessions per document; .fig export checked by opening written files in other software; experimental .fig export; keyboard shortcut parity suite and bindings; Simplified Chinese draft catalog; Latin American Spanish overlay; prototyping tail: gamepad triggers, widgets in prototypes, mode lookups; plugin directory on figcraft-server; Japanese and Korean draft catalogs and CJK UI fonts; plugin widgets and the plugin panel tail; French, German and Brazilian Portuguese draft catalogs; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and edit tail; dev resources links; extended collections tail; branch version history and finer list merges; comments and version history behaviour suite and fixes; canvas navigation, guides and grids behaviour suite and fixes; `.fig` import: editable vector networks, more layer kinds, variable prototype actions; `.fig` import, best effort: gap 1 down to its tail; Windows QA pass: everyday workflows on Windows 11, eight fixes incl. unsaved work kept after a crash or a forced quit; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; localization layer with a draft Spanish catalog; hosting figcraft-server: wss in the desktop app, server releases, deployment guide; plugin panels and settings; canvas fixes: boolean hit testing on the result, group drags, frame outlines and slices; code connect; stretch and scatter brushes, pen pressure; text on a path and pattern fills; team libraries on the server and swap library; branches: create, update from main, review and merge; animated GIF fills and TIFF images; Open recent, outlines for the selection and mask outlines: menu breadth 100%; extended collections, variables import/export, gradient stop and variant bindings: gap 14 down to its tail) · **Target:** Figma Design (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (egui/eframe 0.37 verified for gap 18; known gaps from the #1311 review in gaps 4, 14, 15 and 16; gap 16: measurements kept on the canvas, a read-only layers panel in Dev Mode; gap 24: boards and their tail; Dev Mode tail: import lines in layer trees, compare with versions, an inspect-only canvas; gap 5: reviewed Turkish, Czech and Indonesian drafts, the Japanese draft completed; reviewed Russian catalog and integer plurals; `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; sharing with a join code; text box sizes measured against documents re-saved by other software; live sessions per document; .fig export checked by opening written files in other software; experimental .fig export; keyboard shortcut parity suite and bindings; Simplified Chinese draft catalog; Latin American Spanish overlay; prototyping tail: gamepad triggers, widgets in prototypes, mode lookups; plugin directory on figcraft-server; Japanese and Korean draft catalogs and CJK UI fonts; plugin widgets and the plugin panel tail; French, German and Brazilian Portuguese draft catalogs; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and edit tail; dev resources links; extended collections tail; branch version history and finer list merges; comments and version history behaviour suite and fixes; canvas navigation, guides and grids behaviour suite and fixes; `.fig` import: editable vector networks, more layer kinds, variable prototype actions; `.fig` import, best effort: gap 1 down to its tail; Windows QA pass: everyday workflows on Windows 11, eight fixes incl. unsaved work kept after a crash or a forced quit; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; localization layer with a draft Spanish catalog; hosting figcraft-server: wss in the desktop app, server releases, deployment guide; plugin panels and settings; canvas fixes: boolean hit testing on the result, group drags, frame outlines and slices; code connect; stretch and scatter brushes, pen pressure; text on a path and pattern fills; team libraries on the server and swap library; branches: create, update from main, review and merge; animated GIF fills and TIFF images; Open recent, outlines for the selection and mask outlines: menu breadth 100%; extended collections, variables import/export, gradient stop and variant bindings: gap 14 down to its tail; the 2026-10-17 landings: `.fig` import fidelity, budgets for large files, the import report, a `.fig` copy from Save as and paste from another design app (gap 1); menus, the Actions palette, editor fixes, Selection colors and smart-selection spacing (gap 4); catalog counts re-measured (gap 5); bounded canvas pan overscan; reviewed Russian catalog and integer plurals; `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; sharing with a join code; text box sizes measured against documents re-saved by other software; live sessions per document; .fig export checked by opening written files in other software; experimental .fig export; keyboard shortcut parity suite and bindings; Simplified Chinese draft catalog; Latin American Spanish overlay; prototyping tail: gamepad triggers, widgets in prototypes, mode lookups; plugin directory on figcraft-server; Japanese and Korean draft catalogs and CJK UI fonts; plugin widgets and the plugin panel tail; French, German and Brazilian Portuguese draft catalogs; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and edit tail; dev resources links; extended collections tail; branch version history and finer list merges; comments and version history behaviour suite and fixes; canvas navigation, guides and grids behaviour suite and fixes; `.fig` import: editable vector networks, more layer kinds, variable prototype actions; `.fig` import, best effort: gap 1 down to its tail; Windows QA pass: everyday workflows on Windows 11, eight fixes incl. unsaved work kept after a crash or a forced quit; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; localization layer with a draft Spanish catalog; hosting figcraft-server: wss in the desktop app, server releases, deployment guide; plugin panels and settings; canvas fixes: boolean hit testing on the result, group drags, frame outlines and slices; code connect; stretch and scatter brushes, pen pressure; text on a path and pattern fills; team libraries on the server and swap library; branches: create, update from main, review and merge; animated GIF fills and TIFF images; Open recent, outlines for the selection and mask outlines: menu breadth 100%; extended collections, variables import/export, gradient stop and variant bindings: gap 14 down to its tail) · **Target:** Figma Design (desktop app 126.10.7) Every known shortfall against Figma, one entry each, ranked by how much it stops a Figma user from doing real work in FigCraft. Agents: pick work from the top unless the owner says otherwise. The @@ -439,8 +439,9 @@ No alpha blockers: the alpha gate in [`roadmap.md`](roadmap.md#alpha-gate) passe needs to; closing one asks about unsaved changes; `window.new`, `window.list`, `window.focus` and `window` on any control request. - **Missing:** wide-gamut colour on the canvas (egui draws sRGB, so P3 colours outside sRGB clip on - screen; exports keep them); a screen-reader tree in windows other than the main one (eframe 0.36 - gives only the main window one); window positions restored at the next start. + screen; exports keep them); a screen-reader tree in windows other than the main one (eframe 0.37 + gives only the main window one; verified in the fork's viewport setup); window positions restored at + the next start. - **Estimate:** 4–8 h. ### 19. AI features @@ -487,6 +488,7 @@ No alpha blockers: the alpha gate in [`roadmap.md`](roadmap.md#alpha-gate) passe | Date | Change | Summary | |---|---|---| +| 2026-10-25 | minor | egui/eframe 0.37 verified for gap 18: the remaining limitations are unchanged. egui-wgpu 0.37 still picks an 8-bit sRGB surface with no colour-space option, so P3 colours outside sRGB still clip on screen; eframe 0.37 still gives only the main window an AccessKit adapter, so other windows have no screen-reader tree. Numbers unchanged | | 2026-10-25 | minor | Known gaps from the #1311 review: gap 4, the export preview follows a slice's first export setting; gap 14, the scopes a paint style's color takes are FigCraft's own rule; gap 15, `proto.linkNotice` from the palette or control channel isn't saved until the next preferences save; gap 16, the file name field still renames in Dev Mode (to check against Figma first). Ranking and hours unchanged | | 2026-10-24 | minor | Gap 16: Measurements kept on the canvas (gap 16): `devMode.addMeasurement {from?, to?, side?}` places one between two layers, along one side of a layer or (neither) to the layer around it, stored on the layer it starts from (saved in `.figcraft`, synced, undoable; old files open without them); Dev Mode draws them as labelled redlines that follow the layers, the Inspect tab lists them (those of the selected layer, or every one on the page), places and removes them; `devMode.removeMeasurement` and `devMode.measurements` remove and list them; a copy keeps those to layers copied with it. The layers panel is read-only in Dev Mode: rows select and expand, but don't rename, reorder, hide or lock. Left: publishing mappings with a CLI; 2–4 h → 1–2 h | | 2026-10-24 | minor | Boards (M12): a file kind of its own (`file.newBoard`, saved in `.figcraft`, carried to live-session joiners) with sticky notes, shapes with text, connectors that re-route when what they join moves (an engine recompute, the same for local edits, undo and others' edits), marker, highlighter and eraser, stamps with the placer's name, a board toolbar and a contextual bar; prototyping and Dev Mode refuse on boards; design files and boards have their own marks on tabs and file rows. New gap 24 (the board tail, 30–60 h); the ranking above it is unchanged | diff --git a/docs/hardware-parity.md b/docs/hardware-parity.md index 1b2536dc..61282d53 100644 --- a/docs/hardware-parity.md +++ b/docs/hardware-parity.md @@ -1,6 +1,6 @@ # Hardware and platform parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (hidden-window screenshot deadlines; zoom previews; hidden windows answer control requests; macOS file opening, the Windows start-up message, Linux packaging; copy and paste in the browser; Windows QA pass; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; pen pressure for the Pencil and brushes on Windows and from browser styluses; macOS: quitting ends the process once everything is kept, avoiding the Touch Bar teardown crash (#781); Linux and BSD clipboard: images under Wayland, reads time out; minimised windows under Wayland; window controls on Wayland without server decorations; canvas textures on device pixels; copy and paste in the browser; Windows QA pass; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; pen pressure for the Pencil and brushes on Windows and from browser styluses) · **Target:** Figma Design (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (egui/eframe 0.37 dependency migration; hidden-window screenshot deadlines; zoom previews; hidden windows answer control requests; macOS file opening, the Windows start-up message, Linux packaging; copy and paste in the browser; Windows QA pass; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; pen pressure for the Pencil and brushes on Windows and from browser styluses; macOS: quitting ends the process once everything is kept, avoiding the Touch Bar teardown crash (#781); Linux and BSD clipboard: images under Wayland, reads time out; minimised windows under Wayland; window controls on Wayland without server decorations; canvas textures on device pixels; copy and paste in the browser; Windows QA pass; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; pen pressure for the Pencil and brushes on Windows and from browser styluses) · **Target:** Figma Design (desktop app 126.10.7) How FigCraft uses hardware and which platforms it runs on, against Figma. Figma's desktop app is Electron with a GPU helper process; its canvas renders on the GPU (WebGL, with WebGPU rolling out @@ -15,10 +15,10 @@ since 2025). FigCraft renders the canvas on the CPU and presents it through wgpu | Canvas rendering | GPU | CPU (tiny-skia), banded across cores, retained (re-renders only what an edit or pan touches), levels of detail below 50% zoom; when renders from scratch are slow, a new zoom shows the whole view coarsely first, then refines it (#312); shown through wgpu (WebGPU or WebGL2 in the browser) | 30–60 for a GPU path | | Effects (blurs, glass, noise) | GPU | CPU | in the above | | HiDPI / Retina | yes | yes (all); a canvas image rendered at the screen's density is placed on whole device pixels, so fractional pans, zooms and display scales don't blur it (#359; geometry tests, the snapping not judged by eye) | — | -| Wide-gamut display (Display P3) | yes, on capable displays | colours stored and exported in P3; the screen shows sRGB: eframe/egui-wgpu 0.36 configure an 8-bit sRGB surface with no colour space option, although wgpu 30 can present Display P3 or extended sRGB on Metal, DX12, Vulkan and WebGPU (see gaps #18). The colour picker warns about colours outside sRGB and View ▸ Soft-proof sRGB stripes them on the canvas | 2–5 | +| Wide-gamut display (Display P3) | yes, on capable displays | colours stored and exported in P3; the screen shows sRGB: eframe/egui-wgpu 0.37 configure an 8-bit sRGB surface with no colour space option, although wgpu 30 can present Display P3 or extended sRGB on Metal, DX12, Vulkan and WebGPU (see gaps #18). The colour picker warns about colours outside sRGB and View ▸ Soft-proof sRGB stripes them on the canvas | 2–5 | | Trackpad pinch zoom and two-finger pan | yes | yes (egui zoom delta, smooth scroll) | — | | Pen tablet pressure (pencil, Figma Draw brushes) | yes (forum reports of regressions in 2025) | Windows pens (winit pointer input) and browser styluses that send touch events with a force (an Apple Pencil in Safari); the Pencil records it as the stroke's width profile. A mouse, macOS and Linux tablets and pens sending only pointer events in a browser report none: constant width | 1–3 | -| Several windows / multi-monitor | yes (a window per file; presenter in its own window) | desktop: File ▸ New window, a tab's Open in new window or a tab dragged off the strip; each window has its own tabs, panels and canvas, draws only when it needs to and asks about unsaved changes when it closes; a minimised or covered window still answers control and MCP requests, while screenshots with hidden or unknown visibility request a hidden paint and expire at their 60-second admission deadline if unfinished; injected pointer/key/text input waits for a real UI frame (#313, #332, #720). Browser and Wayland hidden-paint behavior remain unqualified. Only the main window has a screen-reader tree (eframe 0.36), so files stay tabs while a screen reader runs; positions aren't restored at the next start; the presenter stays inside its window; one window in the browser | 1–2 | +| Several windows / multi-monitor | yes (a window per file; presenter in its own window) | desktop: File ▸ New window, a tab's Open in new window or a tab dragged off the strip; each window has its own tabs, panels and canvas, draws only when it needs to and asks about unsaved changes when it closes; a minimised or covered window still answers control and MCP requests, while screenshots with hidden or unknown visibility request a hidden paint and expire at their 60-second admission deadline if unfinished; injected pointer/key/text input waits for a real UI frame (#313, #332, #720). Browser and Wayland hidden-paint behavior remain unqualified. Only the main window has a screen-reader tree (eframe 0.37), so files stay tabs while a screen reader runs; positions aren't restored at the next start; the presenter stays inside its window; one window in the browser | 1–2 | | Screen readers | partial | AccessKit tree on desktop (names, roles, states), never tested with a real screen reader; none in the browser | 4–8 + human QA | | Keyboard layouts (non-US) | yes | keymap uses logical keys; not checked on AZERTY/QWERTZ/JIS | 1–2 | @@ -50,6 +50,7 @@ Nothing has been timed against Figma on the same document (needs `.fig` import). | Date | Change | Summary | |---|---|---| +| 2026-10-25 | minor | egui/eframe 0.37 dependency migration: the workspace pins the egui family at 0.37, and the wide-gamut and several-windows rows now cite 0.37. The limitations are unchanged: egui-wgpu 0.37 offers no surface colour-space option, so the screen still shows sRGB; eframe 0.37 still gives only the main window an AccessKit adapter, so files stay tabs while a screen reader runs. Numbers unchanged | | 2026-10-25 | minor | Hidden or unknown-visibility screenshots request a hidden paint and expire at their 60-second admission deadline if unfinished; injected pointer/key/text input waits for a real UI frame. Browser and Wayland hidden-paint behavior remain unqualified. Numbers unchanged. | | 2026-10-15 | minor | Community fixes (#290, #306, #312, #313, #328, #332, #346, #474): coarse zoom previews when renders from scratch are slow; a minimised or covered window answers control and MCP requests (screenshots and input fail at once while it is hidden); `.figcraft` files open from Finder on macOS; a message box when the window can't open on Windows; on Linux the window id matches the desktop entry, the RPM requires glibc 2.35 and user fonts under `XDG_DATA_HOME` are found. Numbers unchanged | | 2026-10-18 | minor | macOS quit crash (#781): on Macs with a Touch Bar the app could crash as it quit (an exception in AppKit's Touch Bar support while the window's content view, which the accessibility adapter subclasses, was torn down). Quitting now keeps everything (preferences, this run's recovery copies, live sessions ended) and then ends the process before that teardown. Quit from the menu bar ends the app without the unsaved-changes question, so unsaved files' recovery copies now stay and reopen at the next start instead of being removed. Numbers unchanged | diff --git a/docs/ui-parity.md b/docs/ui-parity.md index e1c219c6..74b056d8 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI and interaction parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-24 · **Change:** minor (the Text on a path tool; board tool keys pinned; community fixes: the text box by dragging, the font picker keys, the pen path on leaving Design, a still canvas in vector edit mode, a scrolling pages list, colour emoji, readable new text in frames, system theme on first run; the Small caps sample in Type settings drawn from capitals; recent files as cards; vector edit mode: hovering, hatching, selecting and dragging filled regions; home screen: Templates tab, first-run templates and Getting started tips; number fields: scrub rates, arrow steps, arithmetic with brackets, relative edits of mixed values; outline mode's hidden layers and object bounds; Hide when publishing; cursors per tool and modifier; panel widths; dark pages for files made in the dark theme; drag threshold and double-clicks into text in groups; rotation origin on Alt+R and placing with Enter: no documented shortcut missing; keyboard shortcut parity suite and bindings; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and the vector edit tail; canvas navigation, guides and grids behaviour suite and fixes; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; layers panel keyboard: F2 rename, Shift+F10 context menu, F8 box selection; selection and transform behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; boolean hit testing on the result, group drags, frame outlines and slices; outlines for the selection, mask outlines; arc fields, live boolean editing, shape builder on strokes, one-sided widths; fields select their text on focus; Typography spacing icons support scrubbing (#373); CSS colour names in hex fields; the Small caps sample in Type settings drawn from capitals; recent files as cards; vector edit mode: hovering, hatching, selecting and dragging filled regions; home screen: Templates tab, first-run templates and Getting started tips; number fields: scrub rates, arrow steps, arithmetic with brackets, relative edits of mixed values; outline mode's hidden layers and object bounds; Hide when publishing; cursors per tool and modifier; panel widths; dark pages for files made in the dark theme; drag threshold and double-clicks into text in groups; rotation origin on Alt+R and placing with Enter: no documented shortcut missing; keyboard shortcut parity suite and bindings; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and the vector edit tail; canvas navigation, guides and grids behaviour suite and fixes; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; layers panel keyboard: F2 rename, Shift+F10 context menu, F8 box selection; selection and transform behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; boolean hit testing on the result, group drags, frame outlines and slices; outlines for the selection, mask outlines; arc fields, live boolean editing, shape builder on strokes, one-sided widths; a rename selects the whole name, so typing replaces it; Escape or Enter after a pen path stays on the same vector (#760); IME composition kept on through idle frames of a text edit, candidates at the caret (#747); Selection colors for mixed selections and smart-selection spacing (#753); submenus with a hover delay and a safe triangle; the Actions palette's tabs, ranked search, highlight and recents; menu items that ask for a value; editor fixes from the community batches; fields select their text on focus; Typography spacing icons support scrubbing (#373); CSS colour names in hex fields; the Small caps sample in Type settings drawn from capitals; recent files as cards; vector edit mode: hovering, hatching, selecting and dragging filled regions; home screen: Templates tab, first-run templates and Getting started tips; number fields: scrub rates, arrow steps, arithmetic with brackets, relative edits of mixed values; outline mode's hidden layers and object bounds; Hide when publishing; cursors per tool and modifier; panel widths; dark pages for files made in the dark theme; drag threshold and double-clicks into text in groups; rotation origin on Alt+R and placing with Enter: no documented shortcut missing; keyboard shortcut parity suite and bindings; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and the vector edit tail; canvas navigation, guides and grids behaviour suite and fixes; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; layers panel keyboard: F2 rename, Shift+F10 context menu, F8 box selection; selection and transform behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; boolean hit testing on the result, group drags, frame outlines and slices; outlines for the selection, mask outlines; arc fields, live boolean editing, shape builder on strokes, one-sided widths) · **Target:** Figma Design UI3 (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (Context menus: the Menu key reaches egui 0.37 but is unbound (row done → partial); the Text on a path tool; board tool keys pinned; community fixes: the text box by dragging, the font picker keys, the pen path on leaving Design, a still canvas in vector edit mode, a scrolling pages list, colour emoji, readable new text in frames, system theme on first run; the Small caps sample in Type settings drawn from capitals; recent files as cards; vector edit mode: hovering, hatching, selecting and dragging filled regions; home screen: Templates tab, first-run templates and Getting started tips; number fields: scrub rates, arrow steps, arithmetic with brackets, relative edits of mixed values; outline mode's hidden layers and object bounds; Hide when publishing; cursors per tool and modifier; panel widths; dark pages for files made in the dark theme; drag threshold and double-clicks into text in groups; rotation origin on Alt+R and placing with Enter: no documented shortcut missing; keyboard shortcut parity suite and bindings; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and the vector edit tail; canvas navigation, guides and grids behaviour suite and fixes; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; layers panel keyboard: F2 rename, Shift+F10 context menu, F8 box selection; selection and transform behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; boolean hit testing on the result, group drags, frame outlines and slices; outlines for the selection, mask outlines; arc fields, live boolean editing, shape builder on strokes, one-sided widths; fields select their text on focus; Typography spacing icons support scrubbing (#373); CSS colour names in hex fields; the Small caps sample in Type settings drawn from capitals; recent files as cards; vector edit mode: hovering, hatching, selecting and dragging filled regions; home screen: Templates tab, first-run templates and Getting started tips; number fields: scrub rates, arrow steps, arithmetic with brackets, relative edits of mixed values; outline mode's hidden layers and object bounds; Hide when publishing; cursors per tool and modifier; panel widths; dark pages for files made in the dark theme; drag threshold and double-clicks into text in groups; rotation origin on Alt+R and placing with Enter: no documented shortcut missing; keyboard shortcut parity suite and bindings; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and the vector edit tail; canvas navigation, guides and grids behaviour suite and fixes; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; layers panel keyboard: F2 rename, Shift+F10 context menu, F8 box selection; selection and transform behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; boolean hit testing on the result, group drags, frame outlines and slices; outlines for the selection, mask outlines; arc fields, live boolean editing, shape builder on strokes, one-sided widths; a rename selects the whole name, so typing replaces it; Escape or Enter after a pen path stays on the same vector (#760); IME composition kept on through idle frames of a text edit, candidates at the caret (#747); Selection colors for mixed selections and smart-selection spacing (#753); submenus with a hover delay and a safe triangle; the Actions palette's tabs, ranked search, highlight and recents; menu items that ask for a value; editor fixes from the community batches; fields select their text on focus; Typography spacing icons support scrubbing (#373); CSS colour names in hex fields; the Small caps sample in Type settings drawn from capitals; recent files as cards; vector edit mode: hovering, hatching, selecting and dragging filled regions; home screen: Templates tab, first-run templates and Getting started tips; number fields: scrub rates, arrow steps, arithmetic with brackets, relative edits of mixed values; outline mode's hidden layers and object bounds; Hide when publishing; cursors per tool and modifier; panel widths; dark pages for files made in the dark theme; drag threshold and double-clicks into text in groups; rotation origin on Alt+R and placing with Enter: no documented shortcut missing; keyboard shortcut parity suite and bindings; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and the vector edit tail; canvas navigation, guides and grids behaviour suite and fixes; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; layers panel keyboard: F2 rename, Shift+F10 context menu, F8 box selection; selection and transform behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; boolean hit testing on the result, group drags, frame outlines and slices; outlines for the selection, mask outlines; arc fields, live boolean editing, shape builder on strokes, one-sided widths) · **Target:** Figma Design UI3 (desktop app 126.10.7) Fine canvas control is what Figma users feel first: handles, snapping, nudging, modifier keys, drag behaviour, numeric precision. This checklist covers the tools, gestures and panels. Status: @@ -20,7 +20,7 @@ interaction feel not yet compared. | Minimize UI (Cmd+\\) | done | | | Resizable panels | done | each panel's edge drags its width (left 200–480, right 240–480, 240 by default; a double-click on the edge or View ▸ Panels ▸ Reset panel widths puts the default back); the widths are each window's own, the main window's are kept in the preferences when a drag ends and come back at the next start, a new window opens with those of the window it comes from; Minimize UI hides the panels and brings them back as they were; the view keeps its centre and zoom while a panel is resized; in a window too small for them the panels give way so the canvas keeps 160 px (the left one first), down to the smallest window (800×500) (`panel_width_tests`). Not compared with Figma's widths; no snap points | | Actions palette (Cmd+K, Cmd+/) | done | tabs: All (every command, grouped by menu, or Other), Assets (components and styles) and Plugins & widgets; results ranked prefix first, then shortest, at most 60 rows; Up/Down move a highlight and Enter runs it; Recents list what was run from the palette (matching translated labels); one open/toggle path from every entry point (`palette_tests`). Ranking and the Assets results not compared with Figma's | -| Context menus | done | canvas and layers; submenus as in the main menu below, and a right-click in a new spot starts a fresh menu (Select layer closed); Shift+F10 opens them from the keyboard (at the focused layer row or below the canvas selection) and the menu takes the keyboard; the Menu key isn't delivered by the windowing layer (egui 0.36 has no key for it) | +| Context menus | partial | canvas and layers; submenus as in the main menu below, and a right-click in a new spot starts a fresh menu (Select layer closed); Shift+F10 opens them from the keyboard (at the focused layer row or below the canvas selection) and the menu takes the keyboard; the Menu key reaches egui as `Key::Menu` (egui-winit 0.37 maps the native key), but FigCraft's keymap has no binding for `Menu`, so it does nothing yet | | Home screen: Recents, Online and Templates | done (ours) | The sidebar switches between the three (`ui.set {homeSection}`). Online: your online files (see the collaboration checklist). Recents: new file, open, join with a code, open files, recent files (cards with the picture each file carries on its page colour, the file's icon, name and "Edited ... ago" or "File not found", full path on hover; or a Name, Last modified and Created table with sortable headers; sorted by name, creation or last change either way; grid or list and the sort kept in the preferences, `ui.set {homeRecentsView, homeRecentsSort, homeRecentsOrder}`; a click selects, a double-click or Enter opens, arrow keys move the selection; Open, Show in folder and Remove from recents on right-click), a Getting started card (six tips with their shortcuts from the keymap; its close button is remembered in the preferences and Help ▸ Getting started brings it back) and, while there are no recent files, four templates to start from. Templates: the eight starter templates as cards (thumbnail rendered from the document, cached per theme; name, description, kind and size), a search field and a kind filter, an empty state; Tab reaches every card and Enter opens it; cards and tabs are named for screen readers. A first run opens here. No Community files or drafts folder | | Main menu from the logo | done | generated from `catalog.rs`; popups sized to content. Submenus open after 0.15 s on their row (a click or the keyboard opens one at once) and close at once when another row is hovered; while the pointer heads for an open submenu inside the triangle to its near edge, the rows it crosses don't take over, and resting 0.3 s on one hands over; closing the menu, however it closes, clears which submenus were open, so it reopens with none (`menu_aim_tests`, 10 tests; timings tuned by feel, not measured against Figma). Menu and palette items that need a value ask for it first: Create link, Offset path and Move to page in a dialog of the shared controls, the language, user name, server and nudge items in Preferences, Open recent on the home screen's Recents; File ▸ Rename edits the file name in place | | Keyboard shortcuts panel | done | closes when the home screen shows (#548); docked, tabbed by group like the documentation, searchable, per-platform keycaps; held keys, gestures and presentation keys listed beside the bindings; a label too long for its column ends with "…" and shows in full on hover | @@ -172,6 +172,7 @@ in the table. `crates/ui-egui/src/shortcut_keys_tests.rs` drives the keys a look | Date | Change | Summary | |---|---|---| +| 2026-10-25 | minor | Context menus: the Menu key is no longer an egui limitation at 0.37 (egui-winit maps the native Menu/ContextMenu key to egui's `Key::Menu`), but FigCraft normalizes no binding for `Menu`, so it does not open a context menu yet; Shift+F10 still does, with the same behaviour. The row moves from done to partial. Numbers unchanged | | 2026-10-24 | minor | Selection colors: a row's Styles menu also lists the document's color variables, and picking one binds it to every fill and stroke the row stands for, replacing a color style there (`selection.bindColorVariable`; a text range with fills of its own takes the variable's value); a row linked to a style or variable has a Detach button that unlinks it and keeps the color (`selection.detachColor`). Still partial: no library styles or variables, no new style or variable from a row | | 2026-10-24 | minor | The Text on a path tool (`tool.textOnPath`, in the Text flyout): a click on a shape's or vector's path puts new text on it, starting at the click, with the path's fill (when one shows) and effects, as the help center's Guide to text describes; the path layer is removed, and an edit left empty puts it back with no undo step (`draw_tools_tests`, `cursor_tests`) | | 2026-10-24 | minor | Boards (M12): eight board bindings pinned (tool keys Q sticky, B shapes, X connector, M marker, U highlighter, E eraser, W stamp, and Shift+Cmd/Ctrl+Enter for the next sticky; boards only, on keys no design-file shortcut uses): 49 → 57 pinned | From d7da3f1bb15baf8a26074ffc03953f789b171543 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sun, 25 Oct 2026 18:01:22 +0000 Subject: [PATCH 33/50] Scale down images past 16384 px a side instead of drawing nothing Fixes #1336 Co-Authored-By: Claude Opus 5.5 --- crates/render/src/image_budget_tests.rs | 22 ++++++++++++++++++---- crates/render/src/images.rs | 19 +++++++++++-------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/crates/render/src/image_budget_tests.rs b/crates/render/src/image_budget_tests.rs index 6228efc5..9a51f405 100644 --- a/crates/render/src/image_budget_tests.rs +++ b/crates/render/src/image_budget_tests.rs @@ -48,9 +48,11 @@ fn an_image_within_the_limits_decodes() { } #[test] -fn an_image_wider_or_taller_than_the_limit_is_refused() { - assert!(images::decode_within(&png(30, 20), ColorProfile::Srgb, 29, u64::MAX).is_none()); - assert!(images::decode_within(&png(20, 30), ColorProfile::Srgb, 29, u64::MAX).is_none()); +fn an_image_wider_or_taller_than_the_limit_is_scaled_down_to_fit() { + let (p, _) = images::decode_within(&png(30, 20), ColorProfile::Srgb, 15, u64::MAX).unwrap(); + assert_eq!((p.width(), p.height()), (15, 10)); + let (p, _) = images::decode_within(&png(20, 30), ColorProfile::Srgb, 15, u64::MAX).unwrap(); + assert_eq!((p.width(), p.height()), (10, 15)); } #[test] @@ -63,10 +65,22 @@ fn a_huge_image_is_refused_from_its_header_alone() { // 16 000 × 16 000 is within the side limit; its pixels (1 GB) aren't within a 1 MB budget, and // the file has none to decode: only the header is read. assert!(images::decode_within(&png_header_only(16_000, 16_000), ColorProfile::Srgb, 16_384, 1 << 20).is_none()); - // Past the side limit, the shipped decode refuses it the same way. + // Past the side limit, the shipped decode reads its header and finds no pixels to scale down. assert!(images::decode(&png_header_only(20_000, 10)).is_none()); } +#[test] +fn an_image_past_the_side_limit_is_drawn_downscaled() { + // #1336: one side over 16 384 px drew nothing. + let p = images::decode(&png(16_385, 4)).unwrap(); + assert_eq!(p.width(), 16_384); + assert!(p.height() >= 1 && p.height() <= 4); + assert!(p.pixels().iter().all(|c| c.alpha() == 255)); + let p = images::decode(&png(4, 18_078)).unwrap(); + assert_eq!(p.height(), 16_384); + assert!(p.width() >= 1 && p.width() <= 4); +} + fn key(name: &str) -> images::Key { (name.to_string(), [0; 7], ColorProfile::Srgb) } diff --git a/crates/render/src/images.rs b/crates/render/src/images.rs index f4f9c5d9..586c2dac 100644 --- a/crates/render/src/images.rs +++ b/crates/render/src/images.rs @@ -15,7 +15,7 @@ use tiny_skia::Pixmap; pub(crate) type Key = (String, [i32; 7], ColorProfile); -/// The largest image side decoded. +/// The largest side of a decoded image: larger images are scaled down to fit. const MAX_SIDE: u32 = 16_384; /// The most bytes one image's decoding may allocate: the image crate's own default limit (a /// larger image is refused from its header). @@ -83,26 +83,25 @@ fn fkey(f: &ImageFilters) -> [i32; 7] { [q(f.exposure), q(f.contrast), q(f.saturation), q(f.temperature), q(f.tint), q(f.highlights), q(f.shadows)] } -/// Decode encoded image bytes into a premultiplied sRGB pixmap (max 16k per side). +/// Decode encoded image bytes into a premultiplied sRGB pixmap (scaled down to 16k per side). pub fn decode(bytes: &[u8]) -> Option { decode_in(bytes, ColorProfile::Srgb).map(|(p, _)| p) } -/// Decode encoded image bytes into a premultiplied pixmap (max 16k per side): converted from the +/// Decode encoded image bytes into a premultiplied pixmap (scaled down to 16k per side): converted from the /// image's own profile into `target` (`false`), or as sRGB when it has none (`true`: the sRGB → /// `target` conversion is still to do). fn decode_in(bytes: &[u8], target: ColorProfile) -> Option<(Pixmap, bool)> { decode_within(bytes, target, MAX_SIDE, MAX_DECODED_BYTES) } -/// [`decode_in`] for images at most `max_side` wide and tall whose decoded pixels take at most -/// `max_bytes`; larger ones are refused from their header, before any pixels are decoded. +/// [`decode_in`] for images whose decoded pixels take at most `max_bytes` (larger ones are refused +/// from their header, before any pixels are decoded), scaled down to at most `max_side` wide and +/// tall. pub(crate) fn decode_within(bytes: &[u8], target: ColorProfile, max_side: u32, max_bytes: u64) -> Option<(Pixmap, bool)> { use image::ImageDecoder; let mut reader = image::ImageReader::new(std::io::Cursor::new(bytes)).with_guessed_format().ok()?; let mut limits = image::Limits::default(); - limits.max_image_width = Some(max_side); - limits.max_image_height = Some(max_side); limits.max_alloc = Some(max_bytes); reader.limits(limits); let mut dec = reader.into_decoder().ok()?; @@ -110,7 +109,11 @@ pub(crate) fn decode_within(bytes: &[u8], target: ColorProfile, max_side: u32, m return None; } let source = crate::image_profile::Source::read(bytes, &mut dec); - let img = image::DynamicImage::from_decoder(dec).ok()?; + let mut img = image::DynamicImage::from_decoder(dec).ok()?; + if img.width() > max_side || img.height() > max_side { + // `thumbnail` keeps the aspect ratio and works in integers (no float copy of the pixels). + img = img.thumbnail(max_side, max_side); + } match source.convert(&img, target) { Some(rgba) => Some((premultiplied(&rgba)?, false)), None => Some((premultiplied(&img.to_rgba8())?, true)), From 35cea3ef8c7ecbf7f5d08c76f608992a9348a16e Mon Sep 17 00:00:00 2001 From: Davit Matchakhelidze Date: Sun, 25 Oct 2026 22:13:52 +0400 Subject: [PATCH 34/50] i18n(ka): shorter wording for labels that were cut off Decided in the native-speaker review of the screens (all-t01). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01YMTAbGNRxnMEzRvYnQGphF --- crates/ui-egui/locales/ka.toml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/locales/ka.toml b/crates/ui-egui/locales/ka.toml index eefb2dd3..aebbe528 100644 --- a/crates/ui-egui/locales/ka.toml +++ b/crates/ui-egui/locales/ka.toml @@ -21,7 +21,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "A collection of this file with these modes and variables: override their values per mode and add variables of its own" = "ამ ფაილის კოლექცია ამ რეჟიმებითა და ცვლადებით: შეცვალეთ მათი მნიშვნელობები თითოეული რეჟიმისთვის და დაამატეთ საკუთარი ცვლადები" "A .figcraft file with this name already exists. Choose its full name to confirm replacement." = "ამ სახელით .figcraft ფაილი უკვე არსებობს. ჩანაცვლების დასადასტურებლად აირჩიეთ მისი სრული სახელი." "A layer on its own aligns to its frame: select more layers, or one in a frame" = "ცალკე შრე თავის ჩარჩოსთან სწორდება: მონიშნეთ მეტი შრე ან ჩარჩოში მყოფი შრე" -"A responsive product page: hero, features, figures, a quote and a footer" = "პროდუქტის ადაპტური გვერდი: მთავარი ბლოკი, შესაძლებლობები, ციფრები, ციტატა და ქვედა ზოლი" +"A responsive product page: hero, features, figures, a quote and a footer" = "პროდუქტის ადაპტური გვერდი ყველა ძირითადი ბლოკით" "A spring plays until it settles: its mass, stiffness and damping set how long" = "ზამბარა მოძრაობს, სანამ არ დამშვიდდება: მისი მასა, სიხისტე და მილევა განსაზღვრავს ხანგრძლივობას" "A title, an agenda, a big figure, a chart and a closing slide" = "სათაური, დღის წესრიგი, დიდი ციფრი, დიაგრამა და დასკვნითი სლაიდი" "A to Z" = "ა-დან ჰ-მდე" @@ -104,7 +104,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Alpha" = "ალფა" "Alphabetical" = "ანბანის მიხედვით" "Alt+drag" = "Alt+გადათრევა" -"An analytics screen on a grid: figures, charts drawn from vectors and a table" = "ანალიტიკის ეკრანი ბადეზე: ციფრები, ვექტორებით დახატული დიაგრამები და ცხრილი" +"An analytics screen on a grid: figures, charts drawn from vectors and a table" = "ანალიტიკა ბადეზე: ციფრები, დიაგრამები და ცხრილი" "An invite link that opens FigCraft and joins" = "მოსაწვევი ბმული, რომელიც ხსნის FigCraft-ს და უერთდება სესიას" "Anchor" = "საყრდენი" "Android" = "Android" @@ -215,7 +215,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Clear from this list" = "ამ სიიდან ამოღება" "Code or invite link" = "კოდი ან მოსაწვევი ბმული" "Color profile: {name}" = "ფერის პროფილი: {name}" -"Colour and text styles, Light and Dark variables, buttons, inputs and cards" = "ფერისა და ტექსტის სტილები, ღია და მუქი ცვლადები, ღილაკები, შეყვანის ველები და ბარათები" +"Colour and text styles, Light and Dark variables, buttons, inputs and cards" = "სტილები, ღია და მუქი ცვლადები, ღილაკები და ბარათები" "Connector" = "შემაერთებელი" "Convert to frame" = "ჩარჩოდ გარდაქმნა" "Convert to section" = "სექციად გარდაქმნა" @@ -480,7 +480,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Expand" = "გაშლა" "Export" = "ექსპორტირება" "Export all" = "ყველაფრის ექსპორტირება" -"Export frames and layers as PNG, JPG, SVG or PDF" = "ჩარჩოებისა და შრეების ექსპორტირება PNG, JPG, SVG ან PDF ფორმატში" +"Export frames and layers as PNG, JPG, SVG or PDF" = "ჩარჩოები და შრეები PNG, JPG, SVG ან PDF ფორმატში" "Export page as PNG" = "გვერდის PNG ფაილად ექსპორტირება" "Export settings" = "ექსპორტის პარამეტრები" "Export variables" = "ცვლადების ექსპორტირება" @@ -553,7 +553,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Font size" = "შრიფტის ზომა" "Font style" = "შრიფტის სტილი" "Forget on this computer" = "ამ კომპიუტერზე დავიწყება" -"Four screens of a trail app with components and a prototype flow" = "ლაშქრობის აპის ოთხი ეკრანი კომპონენტებითა და პროტოტიპის ნაკადით" +"Four screens of a trail app with components and a prototype flow" = "ლაშქრობის აპის ოთხი ეკრანი და პროტოტიპის ნაკადი" "Fractions" = "წილადები" "Frame" = "ჩარჩო" "Frame selection" = "მონიშნულის ჩარჩოში მოქცევა" @@ -576,7 +576,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Gradient" = "გრადიენტი" "Gray" = "ნაცრისფერი" "Green" = "მწვანე" -"Greyscale components and two example screens to sketch a flow with" = "ნაცრისფერი კომპონენტები და ორი სანიმუშო ეკრანი ნაკადის ჩანახატისთვის" +"Greyscale components and two example screens to sketch a flow with" = "ნაცრისფერი კომპონენტები ნაკადის ჩანახატისთვის" "Grid" = "ბადე" "Grid ({size})" = "ბადე ({size})" "Grid styles" = "ბადის სტილები" @@ -623,7 +623,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Hue" = "ფერის ტონი" "Hug" = "შიგთავსზე მორგება" "Hug contents" = "შიგთავსზე მორგება" -"Icon components on a 24 px grid with keylines and a size preview" = "ხატულების კომპონენტები 24 px ბადეზე საორიენტაციო ხაზებითა და ზომების გადახედვით" +"Icon components on a 24 px grid with keylines and a size preview" = "ხატულები 24 px ბადეზე, საორიენტაციო ხაზებით" "Icon set starter" = "ხატულების ნაკრების საწყისი" "If it keeps happening, please report it at {link} with this message." = "თუ ეს განმეორდება, გთხოვთ, ეს შეტყობინება გამოგვიგზავნეთ აქ: {link}" "If" = "თუ" @@ -745,7 +745,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Link" = "ბმული" "Link copied" = "ბმული დაკოპირდა" "Link docs, code or tickets for developers." = "მიაბით დოკუმენტაცია, კოდი ან ტიკეტები დეველოპერებისთვის." -"Link frames on the Prototype tab, then present the flow" = "დააკავშირეთ ჩარჩოები „პროტოტიპის“ ჩანართზე, შემდეგ წარადგინეთ ნაკადი" +"Link frames on the Prototype tab, then present the flow" = "დააკავშირეთ ჩარჩოები და წარადგინეთ ნაკადი" "Link this component to its code component: instances then show your real snippet with their values." = "დააკავშირეთ ეს კომპონენტი მის კოდის კომპონენტთან: ინსტანსები მაშინ თქვენს რეალურ ფრაგმენტს აჩვენებს მათი მნიშვნელობებით." "List spacing" = "სიის დაშორება" "List style" = "სიის სტილი" @@ -921,7 +921,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "On click" = "დაწკაპუნებით" "On drag" = "გადათრევისას" "On this page" = "ამ გვერდზე" -"One announcement in five common sizes: square, portrait, story, link and banner" = "ერთი განცხადება ხუთ ხშირად გამოყენებულ ზომაში: კვადრატი, ვერტიკალური, სთორი, ბმული და ბანერი" +"One announcement in five common sizes: square, portrait, story, link and banner" = "ერთი განცხადება ხუთ პოპულარულ ზომაში" "Online" = "ონლაინ" "Online files" = "ონლაინ ფაილები" "Online sharing is off: files are shared on the local network only." = "ონლაინ გაზიარება გამორთულია: ფაილები მხოლოდ ლოკალურ ქსელში ზიარდება." @@ -1003,7 +1003,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Pick color" = "ფერის არჩევა" "Pick color (I)" = "ფერის აღება (I)" "Pick one font family first" = "ჯერ აირჩიეთ ერთი შრიფტის ოჯახი" -"Pick the Frame tool, then drag on the canvas or choose a device size" = "აირჩიეთ ჩარჩოს ხელსაწყო, შემდეგ გადაათრიეთ ტილოზე ან აირჩიეთ მოწყობილობის ზომა" +"Pick the Frame tool, then drag on the canvas or choose a device size" = "ჩარჩოს ხელსაწყოთი გადაათრიეთ ან აირჩიეთ ზომა" "Pin a property" = "თვისების მიმაგრება" "Pinch" = "მოჭყლეტა" "Pixel grid" = "პიქსელური ბადე" @@ -1182,7 +1182,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Save files automatically" = "ფაილების ავტომატურად შენახვა" "Search templates" = "შაბლონების ძიება" "See all templates" = "ყველა შაბლონის ნახვა" -"Select layers and they space themselves as their content changes" = "მონიშნეთ შრეები და შიგთავსის ცვლილებისას ისინი ავტომატურად დაშორდება ერთმანეთს" +"Select layers and they space themselves as their content changes" = "შრეები შიგთავსის ცვლილებისას თავად დაშორდება" "SHA-256: {sha}…" = "SHA-256: {sha}…" "Same as layer" = "შრის მსგავსად" "Saturation" = "გაჯერება" @@ -1330,7 +1330,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Start on path" = "დასაწყისი ტრაექტორიაზე" "Start point" = "საწყისი წერტილი" "Start sharing" = "გაზიარების დაწყება" -"Start sharing with the Share button, then pass on the code it gives" = "გაზიარება დაიწყეთ ღილაკით „გაზიარება“, შემდეგ გადაეცით მის მიერ მოცემული კოდი" +"Start sharing with the Share button, then pass on the code it gives" = "დააჭირეთ „გაზიარებას“ და გადაეცით მიღებული კოდი" "Starting to share…" = "გაზიარების დაწყება…" "Status" = "სტატუსი" "Sticky" = "მიმაგრებული" @@ -1451,7 +1451,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Try another search or filter." = "სცადეთ სხვა ძიება ან ფილტრი." "Try another search, or browse templates." = "სცადეთ სხვა ძიება ან დაათვალიერეთ შაბლონები." "Try another word, or look at every kind." = "სცადეთ სხვა სიტყვა ან ნახეთ ყველა სახეობა." -"Turn a layer into a component, reuse it, and change every copy at once" = "შრე აქციეთ კომპონენტად, გამოიყენეთ ხელახლა და შეცვალეთ ყველა ასლი ერთდროულად" +"Turn a layer into a component, reuse it, and change every copy at once" = "შრე აქციეთ კომპონენტად და შეცვალეთ ყველა ასლი" "Two digits" = "ორი ციფრი" "Type" = "ტიპი" "Type settings" = "ტექსტის პარამეტრები" From abfdaa24366b8bf81c05268efd9205401391715a Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Sun, 25 Oct 2026 20:14:50 +0100 Subject: [PATCH 35/50] M-egui037: retain one explicit session switch in the qualified regression --- crates/collab-net/src/sessions_tests.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/collab-net/src/sessions_tests.rs b/crates/collab-net/src/sessions_tests.rs index 5da0e020..4a2579f8 100644 --- a/crates/collab-net/src/sessions_tests.rs +++ b/crates/collab-net/src/sessions_tests.rs @@ -134,10 +134,6 @@ fn two_files_are_hosted_and_joined_independently() { guest.execute("doc.switch", &json!({"index": guest.docs.iter().position(|d| d.uid == gb).unwrap()})).unwrap(); assert_eq!(guest.ds().unwrap().uid, gb, "B is in front while A receives edits"); // An edit in A reaches the guest's copy of A only, while B is in front at the guest. - // Concurrent joins may complete in either order. Put B in front explicitly so the - // following assertions exercise A's background session independent of network timing. - guest.execute("doc.switch", &json!({"index": guest.docs.iter().position(|d| d.uid == gb).unwrap()})).unwrap(); - assert_eq!(guest.ds().unwrap().uid, gb, "B is in front while A receives edits"); let in_a = rect(&mut host); host.execute("doc.switch", &json!({"index": 1})).unwrap(); let in_b = rect(&mut host); From b7a0d892d728a79e36a6bff67e583cf40f2ab3ef Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Sun, 25 Oct 2026 20:39:43 +0100 Subject: [PATCH 36/50] M14: cover synthetic Copy link clipboard isolation --- crates/ui-egui/src/clipboard_fence_tests.rs | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/crates/ui-egui/src/clipboard_fence_tests.rs b/crates/ui-egui/src/clipboard_fence_tests.rs index 76ddf81c..9b7ed4fe 100644 --- a/crates/ui-egui/src/clipboard_fence_tests.rs +++ b/crates/ui-egui/src/clipboard_fence_tests.rs @@ -131,6 +131,37 @@ fn a_copy_command_invoked_for_a_synthetic_click_still_keeps_the_clipboard() { assert_eq!(w.writes(), (1, 0)); } +/// Asserts a real `ui.menu.invoke` of Copy link is fenced from the system clipboard, while the +/// same menu item invoked by the user writes the selected layer's link. +#[test] +fn a_synthetic_ui_menu_invoke_copy_link_keeps_the_clipboard_then_a_user_copy_writes_the_link() { + let mut w = Win::new(); + let selected = *w.app.session.selection().first().expect("a selected layer"); + let link = format!("figcraft://node/{}", selected.0); + + let (tx, rx) = std::sync::mpsc::channel(); + w.app.control_queue.push(ControlRequest { + id: json!(1), + method: "ui.menu.invoke".into(), + params: json!({"id": "edit.copyLink"}), + reply: tx, + state: Default::default(), + }); + w.frame(vec![]); + let reply = rx.try_recv().expect("the menu invocation is acknowledged"); + assert_eq!(reply.id, json!(1)); + assert!(reply.result.is_ok(), "the menu item ran: {:?}", reply.result); + assert_eq!(w.writes(), (0, 0), "a synthetic menu invocation never replaces the user's clipboard"); + assert_eq!(w.app.ui.toast.as_ref().map(|t| t.0.as_str()), Some("Link copied")); + assert!(!w.app.control_synthetic, "the fence ends with the frame"); + + crate::menus::invoke(&mut w.app, "edit.copyLink"); + assert_eq!(w.writes(), (1, 0), "the user's invocation writes exactly one text clipboard entry"); + let recorded = w.recorded.lock().unwrap(); + assert_eq!(recorded.text, vec![link.clone()]); + assert_eq!(recorded.last_text.as_deref(), Some(link.as_str())); +} + /// Return the characters of a text node in the test window. fn edit_text(w: &Win, id: NodeId) -> String { match &w.app.session.doc().unwrap().node(id).unwrap().kind { From 84d782c85b43477c3db7b4904e0fa7bfbd4fa53c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 25 Oct 2026 14:19:01 -0700 Subject: [PATCH 37/50] M5: controller buttons wait while the link notice shows A controller button pressed while the notice before a website link shows no longer plays the prototype's gamepad triggers, as keys do not. Buttons play again once the notice closes. --- crates/ui-egui/src/present.rs | 2 ++ crates/ui-egui/src/present_links_tests.rs | 28 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/crates/ui-egui/src/present.rs b/crates/ui-egui/src/present.rs index bbaae4b6..b5c7eb0f 100644 --- a/crates/ui-egui/src/present.rs +++ b/crates/ui-egui/src/present.rs @@ -2506,7 +2506,9 @@ fn input(p: &mut Presenter, ctx: &egui::Context, l: &Layout, over_area: bool, ke ) }); let keys = if keys_on { keys } else { Vec::new() }; + // Controller buttons pressed while a link notice shows are dropped, as keys are. let pads = std::mem::take(&mut p.pads); + let pads = if p.link_notice.is_none() { pads } else { Vec::new() }; // A transition a drag started follows the pointer while it stays down, then plays on from there. if let Some(a) = p.anim.as_mut() && let Some((from, dir, len)) = a.follow diff --git a/crates/ui-egui/src/present_links_tests.rs b/crates/ui-egui/src/present_links_tests.rs index 31a6b2bc..a2b571af 100644 --- a/crates/ui-egui/src/present_links_tests.rs +++ b/crates/ui-egui/src/present_links_tests.rs @@ -162,6 +162,34 @@ fn the_presenter_keys_wait_while_the_notice_shows() { assert_eq!(notice(&u), "https://example.com/a"); } +#[test] +fn the_prototype_takes_no_controller_buttons_while_the_notice_shows() { + let mut s = Session::new(); + let a = id(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 300, "height": 400, "name": "A"}))); + let b = id(&ex(&mut s, "frame.create", json!({"x": 400, "y": 0, "width": 300, "height": 400, "name": "B"}))); + let layer = id(&ex(&mut s, "shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 30, "parent": a}))); + let link = json!({"type": "openUrl", "url": "https://example.com/a"}); + ex(&mut s, "proto.interaction.add", json!({"id": layer, "trigger": {"type": "afterDelay", "ms": 100}, "action": link})); + let to_b = json!({"type": "navigate", "dest": b}); + ex(&mut s, "proto.interaction.add", json!({"id": a, "trigger": {"type": "keyPress", "key": "Gamepad A"}, "action": to_b})); + let mut u = Harness::new(s); + u.app.services = Box::new(Opened::default()); + u.ctx.enable_accesskit(); + u.run("proto.present", json!({"start": a})); + u.frames(40, Vec::new); + assert_eq!(notice(&u), "https://example.com/a"); + let ctx = u.ctx.clone(); + crate::control::handle(&mut u.app, &ctx, "ui.input", &json!({"events": [{"gamepad": "A"}]})).unwrap(); + u.frames(2, Vec::new); + assert_eq!(u.app.inspect()["presenter"]["current"], json!(a), "the Gamepad A trigger did not run"); + assert_eq!(notice(&u), "https://example.com/a"); + click(&mut u, "Cancel"); + assert!(notice(&u).is_null()); + crate::control::handle(&mut u.app, &ctx, "ui.input", &json!({"events": [{"gamepad": "A"}]})).unwrap(); + u.frames(2, Vec::new); + assert_eq!(u.app.inspect()["presenter"]["current"], json!(b), "the button plays once the notice closes"); +} + #[test] fn dont_show_this_again_is_saved_with_the_preferences() { let (mut u, seen) = presented("https://example.com/a", false); From 2581b0bfd92af9560a950d28b39dea566afd25fb Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 25 Oct 2026 15:23:51 -0700 Subject: [PATCH 38/50] Docs: the PNG row names ignore overlapping layers and include bounding box for text layers The PNG row of docs/file-format-parity.md listed the export settings as "contents only" and "include bounding box (the layer's own box)". Since #1307 the Export section labels the first option Ignore overlapping layers and shows Include bounding box for text layers. The row now uses those names, says that ignore overlapping layers is on by default, and gives include bounding box for text layers, as the help page lists them. The status line gets the new date and topic, and the revision history gets a row; the percentages and hours are unchanged. --- docs/file-format-parity.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index d1819ee0..a31732f1 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -1,6 +1,6 @@ # File format parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-24 · **Change:** minor (the Fonts table's missing-font row describes the Missing fonts window; `.figcraft` carries the file kind (boards); `.fig` import: resized instances and variable modes by asset key; atomic saves; auto-save; SVG export clip of nested frames; SVG/PDF export depth refusal (#208); `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; `.fig` export: written files checked by opening them in other software; experimental `.fig` export; export and inspect behaviour suite and fixes; .fig import: editable vector networks and more layer kinds; embedded image colour profiles; `.fig` import, best effort; animated GIF fills and TIFF images; last major: created, formats from the installed Figma's Info.plist and help center, ours from source; REST import keeps slot layers and instances' slot content (#792); REST import reads grid track sizes (#465); `.fig` import fidelity from the community batches, budgets for large files, the import report, a `.fig` copy from Save as, paste from another design app; instance layers' size and resizing and Hug on import (#731, #732)) · **Target:** Figma Design (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (the PNG row names ignore overlapping layers and include bounding box for text layers; the Fonts table's missing-font row describes the Missing fonts window; `.figcraft` carries the file kind (boards); `.fig` import: resized instances and variable modes by asset key; atomic saves; auto-save; SVG export clip of nested frames; SVG/PDF export depth refusal (#208); `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; `.fig` export: written files checked by opening them in other software; experimental `.fig` export; export and inspect behaviour suite and fixes; .fig import: editable vector networks and more layer kinds; embedded image colour profiles; `.fig` import, best effort; animated GIF fills and TIFF images; last major: created, formats from the installed Figma's Info.plist and help center, ours from source; REST import keeps slot layers and instances' slot content (#792); REST import reads grid track sizes (#465); `.fig` import fidelity from the community batches, budgets for large files, the import report, a `.fig` copy from Save as, paste from another design app; instance layers' size and resizing and Hug on import (#731, #732)) · **Target:** Figma Design (desktop app 126.10.7) 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 @@ -49,7 +49,7 @@ export limit, not a native document nesting limit. | Format | Figma | FigCraft | Notes | Hours | |---|---|---|---|---| -| PNG | yes, scales/suffixes | yes | export settings per layer, presets (`2x`, `512w`, `512h`), preview, "Export N layers"; contents only (off: every layer showing in the area) and include bounding box (the layer's own box); slashes in layer names export into folders. The exported area is what the layer paints: shadows towards their offset, outside and centre strokes, unclipped children, a mask group's mask, nothing for hidden layers; slices export everything under them, except that with contents only on a slice inside a frame or group exports only that frame or group; sides round up to whole pixels | — | +| PNG | yes, scales/suffixes | yes | export settings per layer, presets (`2x`, `512w`, `512h`), preview, "Export N layers"; ignore overlapping layers (on by default; off: every layer showing in the area) and, for text layers, include bounding box (the layer's own box); slashes in layer names export into folders. The exported area is what the layer paints: shadows towards their offset, outside and centre strokes, unclipped children, a mask group's mask, nothing for hidden layers; slices export everything under them, except that with ignore overlapping layers on a slice inside a frame or group exports only that frame or group; sides round up to whole pixels | — | | JPG | yes | yes | white where transparent; fixed quality (90) | — | | SVG | yes (outline text option, ids) | yes | alpha/luminance masks kept; noise, texture, progressive and background blur, glass embedded as images; outline text (off: `` with one `` per line, one style per layer), unique id attributes from layer names, explicit depth-limit refusal, nested frames clipped by their parent's clip (#327), simplified strokes (stroke attributes for centred strokes and for inside and outside strokes on boxes and ellipses) | — | | PDF | yes | yes | one page per frame, real selectable text in subset fonts, links, vectors and gradients as vectors, effects as images; bleed, crop/bleed marks, page boxes, naive CMYK; checked by rendering the PDF back against PNG exports; explicit depth-limit refusal | CMYK output intent 2–4 | @@ -165,6 +165,7 @@ each. | Date | Change | Summary | |---|---|---| +| 2026-10-25 | patch | PNG: the export settings were listed as "contents only" and "include bounding box (the layer's own box)"; the row now names ignore overlapping layers, on by default, and include bounding box for text layers, as the Export section shows them (#1307). Numbers unchanged | | 2026-10-24 | patch | Fonts: the missing-font row said "warnings only (REST import)"; it now names the Missing fonts window (#752), `text.missingFonts` and the `missing font` lines of `figcraft-cli info`. Replacing a missing font is still missing. Numbers unchanged | | 2026-10-24 | minor | Slices and contents only (Figma's Ignore overlapping layers): with it on, a slice inside a frame or group exports only that frame or group and the layers in it, and its Export preview shows the same; with it off, or for a slice on the page or in a section, the slice exports everything in its area as before | | 2026-10-24 | minor | Boards (M12): `.figcraft` saves the file kind (`kind: "board"`, absent for design files) and each board object's `board` metadata; the `.jam` row points at boards | From 7820825ea10bd2ab67af1a12280d4e12b91aa70e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 25 Oct 2026 17:09:48 -0700 Subject: [PATCH 39/50] M5: controller buttons pressed with no frame shown are dropped A controller button pressed while the player has no frame to show, for example after the frame is deleted, no longer plays the prototype's gamepad trigger once the frame comes back. --- crates/ui-egui/src/present.rs | 5 +++++ crates/ui-egui/src/present_tests.rs | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/crates/ui-egui/src/present.rs b/crates/ui-egui/src/present.rs index b5c7eb0f..b1947a68 100644 --- a/crates/ui-egui/src/present.rs +++ b/crates/ui-egui/src/present.rs @@ -2198,6 +2198,9 @@ fn player(p: &mut Presenter, ui: &mut Ui, rect: Rect, now: f64, chrome: Chrome) p.restart(p.start, now); } if p.doc.as_ref().is_none_or(|d| !d.contains(p.current)) { + // Controller buttons pressed with no frame to show are dropped, as they are while a link + // notice shows. + p.pads.clear(); if !chrome.pane { return Some(BarAction::Close); } @@ -2228,6 +2231,8 @@ fn player(p: &mut Presenter, ui: &mut Ui, rect: Rect, now: f64, chrome: Chrome) // the prototype takes neither keys nor the pointer (Escape there cancels the notice). let keys = chrome.keys && p.link_notice.is_none() && (!chrome.pane || over); input(p, &ctx, &l, over && p.link_notice.is_none(), keys, chrome.pane, now); + } else { + p.pads.clear(); } let Some(l) = layout(p, area, chrome) else { return action }; p.shown = Some((p.current, l.place, l.clip.intersect(area))); diff --git a/crates/ui-egui/src/present_tests.rs b/crates/ui-egui/src/present_tests.rs index 93729922..4a3819c0 100644 --- a/crates/ui-egui/src/present_tests.rs +++ b/crates/ui-egui/src/present_tests.rs @@ -137,6 +137,26 @@ fn preview_pane_opens_follows_edits_and_the_selection() { assert!(u.app.ui.preview.is_none()); } +/// A controller button pressed while the pane has no frame to show is dropped, and does not play +/// once the frame comes back. +#[test] +fn controller_buttons_pressed_with_no_frame_shown_are_dropped() { + let (mut u, a, b, _) = setup(); + let to_b = json!({"type": "navigate", "dest": b}); + u.run("proto.interaction.add", json!({"id": a, "trigger": {"type": "keyPress", "key": "Gamepad A"}, "action": to_b})); + u.run("proto.preview", json!({"start": a})); + u.run("edit.delete", json!({"ids": [a]})); + let ctx = u.ctx.clone(); + crate::control::handle(&mut u.app, &ctx, "ui.input", &json!({"events": [{"gamepad": "A"}]})).unwrap(); + u.frames(2, Vec::new); + u.run("edit.undo", json!({})); + u.frames(2, Vec::new); + assert_eq!(u.preview()["current"], json!(a), "the button pressed with no frame shown did not play"); + crate::control::handle(&mut u.app, &ctx, "ui.input", &json!({"events": [{"gamepad": "A"}]})).unwrap(); + u.frames(2, Vec::new); + assert_eq!(u.preview()["current"], json!(b), "a button pressed with the frame shown plays"); +} + /// Asserts the preview's device viewport and scroll range, wheel and drag scrolling, the /// end clamp with spring-back, and that navigation resets scroll to the top. #[test] From 1bac7367ba41610377f6114f170a89fcceb9e974 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 25 Oct 2026 17:34:11 -0700 Subject: [PATCH 40/50] Docs: the PNG row's include bounding box applies to any layer from the commands The Export section offers include bounding box for text layers, and file.export and export.update take it for any layer. --- docs/file-format-parity.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index a31732f1..a530d8a5 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -1,6 +1,6 @@ # File format parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (the PNG row names ignore overlapping layers and include bounding box for text layers; the Fonts table's missing-font row describes the Missing fonts window; `.figcraft` carries the file kind (boards); `.fig` import: resized instances and variable modes by asset key; atomic saves; auto-save; SVG export clip of nested frames; SVG/PDF export depth refusal (#208); `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; `.fig` export: written files checked by opening them in other software; experimental `.fig` export; export and inspect behaviour suite and fixes; .fig import: editable vector networks and more layer kinds; embedded image colour profiles; `.fig` import, best effort; animated GIF fills and TIFF images; last major: created, formats from the installed Figma's Info.plist and help center, ours from source; REST import keeps slot layers and instances' slot content (#792); REST import reads grid track sizes (#465); `.fig` import fidelity from the community batches, budgets for large files, the import report, a `.fig` copy from Save as, paste from another design app; instance layers' size and resizing and Hug on import (#731, #732)) · **Target:** Figma Design (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (the PNG row names ignore overlapping layers and where include bounding box is offered; the Fonts table's missing-font row describes the Missing fonts window; `.figcraft` carries the file kind (boards); `.fig` import: resized instances and variable modes by asset key; atomic saves; auto-save; SVG export clip of nested frames; SVG/PDF export depth refusal (#208); `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; `.fig` export: written files checked by opening them in other software; experimental `.fig` export; export and inspect behaviour suite and fixes; .fig import: editable vector networks and more layer kinds; embedded image colour profiles; `.fig` import, best effort; animated GIF fills and TIFF images; last major: created, formats from the installed Figma's Info.plist and help center, ours from source; REST import keeps slot layers and instances' slot content (#792); REST import reads grid track sizes (#465); `.fig` import fidelity from the community batches, budgets for large files, the import report, a `.fig` copy from Save as, paste from another design app; instance layers' size and resizing and Hug on import (#731, #732)) · **Target:** Figma Design (desktop app 126.10.7) 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 @@ -49,7 +49,7 @@ export limit, not a native document nesting limit. | Format | Figma | FigCraft | Notes | Hours | |---|---|---|---|---| -| PNG | yes, scales/suffixes | yes | export settings per layer, presets (`2x`, `512w`, `512h`), preview, "Export N layers"; ignore overlapping layers (on by default; off: every layer showing in the area) and, for text layers, include bounding box (the layer's own box); slashes in layer names export into folders. The exported area is what the layer paints: shadows towards their offset, outside and centre strokes, unclipped children, a mask group's mask, nothing for hidden layers; slices export everything under them, except that with ignore overlapping layers on a slice inside a frame or group exports only that frame or group; sides round up to whole pixels | — | +| PNG | yes, scales/suffixes | yes | export settings per layer, presets (`2x`, `512w`, `512h`), preview, "Export N layers"; ignore overlapping layers (on by default; off: every layer showing in the area) and include bounding box (the layer's own box; the Export section offers it for text layers, and `file.export` and `export.update` take it for any layer); slashes in layer names export into folders. The exported area is what the layer paints: shadows towards their offset, outside and centre strokes, unclipped children, a mask group's mask, nothing for hidden layers; slices export everything under them, except that with ignore overlapping layers on a slice inside a frame or group exports only that frame or group; sides round up to whole pixels | — | | JPG | yes | yes | white where transparent; fixed quality (90) | — | | SVG | yes (outline text option, ids) | yes | alpha/luminance masks kept; noise, texture, progressive and background blur, glass embedded as images; outline text (off: `` with one `` per line, one style per layer), unique id attributes from layer names, explicit depth-limit refusal, nested frames clipped by their parent's clip (#327), simplified strokes (stroke attributes for centred strokes and for inside and outside strokes on boxes and ellipses) | — | | PDF | yes | yes | one page per frame, real selectable text in subset fonts, links, vectors and gradients as vectors, effects as images; bleed, crop/bleed marks, page boxes, naive CMYK; checked by rendering the PDF back against PNG exports; explicit depth-limit refusal | CMYK output intent 2–4 | @@ -165,7 +165,7 @@ each. | Date | Change | Summary | |---|---|---| -| 2026-10-25 | patch | PNG: the export settings were listed as "contents only" and "include bounding box (the layer's own box)"; the row now names ignore overlapping layers, on by default, and include bounding box for text layers, as the Export section shows them (#1307). Numbers unchanged | +| 2026-10-25 | patch | PNG: the export settings were listed as "contents only" and "include bounding box (the layer's own box)"; the row now names ignore overlapping layers, on by default, and says that the Export section offers include bounding box for text layers (#1307), while `file.export` and `export.update` take it for any layer. Numbers unchanged | | 2026-10-24 | patch | Fonts: the missing-font row said "warnings only (REST import)"; it now names the Missing fonts window (#752), `text.missingFonts` and the `missing font` lines of `figcraft-cli info`. Replacing a missing font is still missing. Numbers unchanged | | 2026-10-24 | minor | Slices and contents only (Figma's Ignore overlapping layers): with it on, a slice inside a frame or group exports only that frame or group and the layers in it, and its Export preview shows the same; with it off, or for a slice on the page or in a section, the slice exports everything in its area as before | | 2026-10-24 | minor | Boards (M12): `.figcraft` saves the file kind (`kind: "board"`, absent for design files) and each board object's `board` metadata; the `.jam` row points at boards | From 8ae2e206fbcb508c92c478b16141d1d529ec9098 Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Sun, 25 Oct 2026 20:48:41 -0400 Subject: [PATCH 41/50] chore(deps): safe dependency refresh (#1352) --- Cargo.lock | 124 ++++++++++++++++++++++++++--------------------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb904655..8d6b8c87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,18 +4,18 @@ version = 4 [[package]] name = "accesskit" -version = "0.25.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad442f58ee04714aaa0ba0a2768c1ea1935b29507bb22ddece8cbbc76db02932" +checksum = "4e883d1d28c5fd5568c79ed2d2bd48d9f2fd3945c8974ed0f53690ceddb051be" dependencies = [ "uuid", ] [[package]] name = "accesskit_atspi_common" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52c182f9c282ac9c5638d876d551d15e5f7d397ec263349a0c6a2b61595dd5e4" +checksum = "24f5baf62e34a4a6c30e3d697e4782f821a7337049c44c3b40576a27dfbb580d" dependencies = [ "accesskit", "accesskit_consumer", @@ -27,9 +27,9 @@ dependencies = [ [[package]] name = "accesskit_consumer" -version = "0.39.1" +version = "0.39.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a45e2bb300bea6d5f33a82c3e051c3ddc6f41c209750f68a0acbe991a284344" +checksum = "f3da8f27636015191b2264ee1df681503170a632cafd832fdc1edfdd4e3a2fd3" dependencies = [ "accesskit", "hashbrown 0.17.1", @@ -37,9 +37,9 @@ dependencies = [ [[package]] name = "accesskit_ios" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28e539d64b27fd4c14de8f78ada8f7c944c092f52f7e49fb63316507a57f6937" +checksum = "a5280724673bbfa8b30a838c013500b719392989be3b97c5a9964062c252c232" dependencies = [ "accesskit", "accesskit_consumer", @@ -51,9 +51,9 @@ dependencies = [ [[package]] name = "accesskit_macos" -version = "0.27.1" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5701624bf6a11efb6d4c8e922bf44126ed96250e5faa9a7a0468c979635839a4" +checksum = "123828ceeec755b05255e3976cb0852993202de98a0626c97dd8d34246991f84" dependencies = [ "accesskit", "accesskit_consumer", @@ -65,9 +65,9 @@ dependencies = [ [[package]] name = "accesskit_unix" -version = "0.24.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "202f24df034a7476d07b7f74284de84f6d62aabd858dbe7ee9cad3b7ad6f8f9d" +checksum = "30d5192871228c54f1b0fb4a85cef000e11a3804f25d2165f14afa0daa67f3f6" dependencies = [ "accesskit", "accesskit_atspi_common", @@ -83,9 +83,9 @@ dependencies = [ [[package]] name = "accesskit_windows" -version = "0.35.1" +version = "0.35.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce63f35d6bdcf59f26b76b3379063f738e6412cef46999cc772d46aa3de35adb" +checksum = "498668b90da9995302a0055aaecad4756932333da2ddef6baee1c00844c430fc" dependencies = [ "accesskit", "accesskit_consumer", @@ -97,9 +97,9 @@ dependencies = [ [[package]] name = "accesskit_winit" -version = "0.34.1" +version = "0.34.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee96dd150375c05912d8a473f98c2fb155fb3234fac88292d396548a2460fa77" +checksum = "cd4ab4437b520ff03088fbe48676a11e7d44a929535e64b31432c1073e48dbcc" dependencies = [ "accesskit", "accesskit_ios", @@ -695,9 +695,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877bf67ac8e52449eb2f9e98a344ea163beb70dd1f9eebe3cc5357dcfeaee4df" +checksum = "86e055fa6e3e40ad6187ba25b6855eeb635d5271f8e0f0e1e9a5826b8d75bea0" dependencies = [ "find-msvc-tools", "jobserver", @@ -748,9 +748,9 @@ dependencies = [ [[package]] name = "clipboard-win" -version = "5.4.1" +version = "5.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bde03770d3df201d4fb868f2c9c59e66a3e4e2bd06692a0fe701e7103c7e84d4" +checksum = "052af7878466feccda12ba7a6a67d019d712f296809559b47c12c8cc196d3a9a" dependencies = [ "error-code", ] @@ -931,7 +931,7 @@ dependencies = [ "verifysign", "winreg", "winsafe", - "zip 9.1.0", + "zip 9.1.1", ] [[package]] @@ -2334,9 +2334,9 @@ dependencies = [ [[package]] name = "icu_collections" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" +checksum = "fe090a42a0d3140fed8c63263ed1fecc02422cb2f4bfe55cd8de2de1b8e105dd" dependencies = [ "displaydoc", "potential_utf", @@ -2348,9 +2348,9 @@ dependencies = [ [[package]] name = "icu_locale_core" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" +checksum = "25d29b57c17c6528d0dc4c2141cfa2d08200465acb537a3909c8b9b8a4a984c0" dependencies = [ "displaydoc", "litemap", @@ -2361,9 +2361,9 @@ dependencies = [ [[package]] name = "icu_normalizer" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" +checksum = "404a3b8c486f205c87fe7f23ab6894d84a4ad76d6e4671ae1981ba7def87c599" dependencies = [ "icu_collections", "icu_normalizer_data", @@ -2375,15 +2375,15 @@ dependencies = [ [[package]] name = "icu_normalizer_data" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" +checksum = "20f0088bfb7441f7a37fa0c9e20cb1e9cba1cac6b9ce8cd2a6dc44294f8e8cbc" [[package]] name = "icu_properties" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" +checksum = "2ea83d991c56158f7cf898bf86436c1dfe7c07ee82fe88951f2695c9f37a379f" dependencies = [ "displaydoc", "icu_collections", @@ -2396,15 +2396,15 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" +checksum = "b98f29af82d02b163fe50161388350e743bb3107cc8e8c2f7314cb505faddfcf" [[package]] name = "icu_provider" -version = "2.3.1" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" +checksum = "413099315636c588ee8f011190b329b971a09a8fae9d157e01dcae8379468514" dependencies = [ "displaydoc", "icu_locale_core", @@ -2809,9 +2809,9 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" [[package]] name = "memmap2" -version = "0.9.11" +version = "0.9.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1219ed1b7f229ee7104d281dd01d6802fe28bb6e95d292942c4daacdeb798c0" +checksum = "6b0ca1155a9ecc25aa12e8313a119f32edf0255fea2f44839c4ac0a12b2ac157" dependencies = [ "libc", ] @@ -3329,9 +3329,9 @@ dependencies = [ [[package]] name = "ordered-float" -version = "5.5.0" +version = "5.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c7c9e0d9b23589f26070720bac724174bfec1083e82f7854cdd0267518343c0" +checksum = "7f59006ce1e204c30956638535b74d317bca99477b9356dfaec54c37f6f600ab" dependencies = [ "num-traits", ] @@ -3974,9 +3974,9 @@ checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97" [[package]] name = "roxmltree" -version = "0.21.1" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1964b10c76125c36f8afe190065a4bf9a87bf324842c05701330bba9f1cacbb" +checksum = "9da7f59328b09405b181fee1018925fad50f157afb43c0c0f5c522c256dd5907" dependencies = [ "memchr", ] @@ -4430,9 +4430,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.16.3" +version = "1.16.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b" +checksum = "d0d5d4b1981b8bbbb7aed204cae5726d683d5d6ac7e74ec54122ea28f315e7c8" dependencies = [ "serde", ] @@ -4785,9 +4785,9 @@ dependencies = [ [[package]] name = "tinystr" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" +checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a" dependencies = [ "displaydoc", "zerovec", @@ -4801,9 +4801,9 @@ checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" [[package]] name = "tokio" -version = "1.54.0" +version = "1.54.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c168a474b95bfecfe908a65d4bdffc523144b649a74c09c286afb35d53e0bc" +checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3" dependencies = [ "pin-project-lite", ] @@ -5087,7 +5087,7 @@ dependencies = [ "kurbo", "log", "pico-args", - "roxmltree 0.21.1", + "roxmltree 0.21.2", "simplecss", "siphasher", "skrifa 0.44.0", @@ -5120,9 +5120,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.28.0" +version = "1.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc1186384beb7dd8eedea376413fd654937285ea6c9cfbb928dc3043ea4b606" +checksum = "4a0e2d11620c50695fe12bbbfde96b3477fe606e7284c22d505c12ce51214514" dependencies = [ "js-sys", "serde_core", @@ -5512,9 +5512,9 @@ dependencies = [ [[package]] name = "webbrowser" -version = "1.2.4" +version = "1.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62c35be770821a214dbc362fc26908c853e776c0004294d0b10b8a6bad582f94" +checksum = "d2c8ddfbbf66e501434657400268cefe51b95140a0266236415cda7627732df7" dependencies = [ "jni", "log", @@ -5537,9 +5537,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9" +checksum = "f5f280bbb2b287bc8e7de7e3852945a0ff50d1bbcb5ed42b6c7a568c546df171" dependencies = [ "rustls-pki-types", ] @@ -6178,9 +6178,9 @@ dependencies = [ [[package]] name = "yoke" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +checksum = "417ef3fcf6c300b7dbd25c85531a746931c02ad536f3cf4786ed1e88223340b3" dependencies = [ "stable_deref_trait", "yoke-derive", @@ -6365,9 +6365,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.8" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" +checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40" dependencies = [ "yoke", "zerofrom", @@ -6376,9 +6376,9 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.11.6" +version = "0.11.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" +checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a" dependencies = [ "proc-macro2", "quote", @@ -6402,9 +6402,9 @@ dependencies = [ [[package]] name = "zip" -version = "9.1.0" +version = "9.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2886b00003a72c4ccee3f42cfc34908d33b2508a74d827dc2a4244706475c704" +checksum = "518b847fd864440c379748ad684c449f293af68978a485a4ff16f7c901c1f7c4" dependencies = [ "crc32fast", "flate2", From 4fc0a39304a25a7ad3f569b9a25f813135028543 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 25 Oct 2026 21:11:43 -0400 Subject: [PATCH 42/50] refactor(ui-egui): split style text_properties into helpers (SonarCloud S3776) Each logical section of the text style editor (sample, font menu, style and size row, line height and letter spacing, and the two menus) is its own helper. UI calls keep their order; no behaviour change. --- crates/ui-egui/src/style_picker.rs | 312 +++++++++++++++++------------ 1 file changed, 184 insertions(+), 128 deletions(-) diff --git a/crates/ui-egui/src/style_picker.rs b/crates/ui-egui/src/style_picker.rs index f81bcd81..d29d33ba 100644 --- a/crates/ui-egui/src/style_picker.rs +++ b/crates/ui-egui/src/style_picker.rs @@ -715,13 +715,22 @@ fn text_binding(ui: &mut Ui, style: &str, field: &str, kind: VariableType, rect: } } -/// A text style's typography in the editor: a sample, then font, style, size, line height and -/// letter spacing; a change redefines the style (every linked char follows). Each field takes a -/// variable: the font and style menus start with Apply variable, the other fields show a variable -/// button on hover, and a bound field shows its variable instead of its value. -fn text_properties(ui: &mut Ui, doc: &Document, style: &Style, def: &TextStyle, out: &mut Frame) { - let id = style.id.as_str(); - let bound = |field: &str| style.bound.get(field).map(|v| doc.variables.get(v).map_or_else(|| v.clone(), |x| x.name.clone())); +/// The text style's variable name for `field`, or None when the field is not bound. +fn bound_name(doc: &Document, style: &Style, field: &str) -> Option { + style.bound.get(field).map(|v| doc.variables.get(v).map_or_else(|| v.clone(), |x| x.name.clone())) +} + +/// Redefines the text style `def` through `f`; the edit is queued only when it changes the style. +fn set_text(def: &TextStyle, id: &str, out: &mut Frame, f: impl FnOnce(&mut TextStyle)) { + let mut d = def.clone(); + f(&mut d); + if d != *def { + out.act = Some(Act::SetText(id.to_string(), d)); + } +} + +/// The sample of the text style, with its font, style and metrics beside it. +fn text_sample_header(ui: &mut Ui, def: &TextStyle, out: &mut Frame) { let t = Tokens::get(ui.ctx()); let (r, _) = ui.allocate_exact_size(vec2(W, 40.0), Sense::hover()); ui.painter().rect_filled(r, CornerRadius::same(5), Color32::from_white_alpha(14)); @@ -730,133 +739,180 @@ fn text_properties(ui: &mut Ui, doc: &Document, style: &Style, def: &TextStyle, let g = ui.painter().layout(summary, regular(10.5), t.menu_dim, W - 80.0); ui.painter().galley(pos2(r.min.x + 72.0, r.center().y - g.size().y / 2.0), g, t.menu_dim); ui.add_space(6.0); - let set = |out: &mut Frame, f: &dyn Fn(&mut TextStyle)| { - let mut d = def.clone(); - f(&mut d); - if d != *def { - out.act = Some(Act::SetText(id.to_string(), d)); +} + +/// The font field: a variable chip when bound, else a dropdown whose menu is returned. +fn font_family_field(ui: &mut Ui, doc: &Document, style: &Style, def: &TextStyle, out: &mut Frame) -> Option { + let id = style.id.as_str(); + match bound_name(doc, style, "fontFamily") { + Some(name) => { + let (r, _) = ui.allocate_exact_size(vec2(W, widgets::FIELD_H), Sense::hover()); + text_binding(ui, id, "fontFamily", VariableType::String, r, &name, widgets::Lead::Named(tr("Font")), out); + None } - }; - let half = (W - 8.0) / 2.0; - // The dropdowns' menus open outside the dark scope (they're regular popups). - let (family_resp, style_resp) = crate::theme::on_dark(ui, |ui| { - ui.spacing_mut().item_spacing = vec2(8.0, 6.0); - let family_resp = match bound("fontFamily") { - Some(name) => { - let (r, _) = ui.allocate_exact_size(vec2(W, widgets::FIELD_H), Sense::hover()); - text_binding(ui, id, "fontFamily", VariableType::String, r, &name, widgets::Lead::Named(tr("Font")), out); - None - } - None => Some(widgets::dropdown(ui, &def.font_family, W, None).on_hover_text(tr("Font"))), - }; - let mut style_resp = None; - ui.horizontal(|ui| { - match bound("fontStyle") { - Some(name) => { - let (r, _) = ui.allocate_exact_size(vec2(half, widgets::FIELD_H), Sense::hover()); - text_binding(ui, id, "fontStyle", VariableType::String, r, &name, widgets::Lead::Named(tr("Font style")), out); - } - None => style_resp = Some(widgets::dropdown(ui, &def.font_style, half, None).on_hover_text(tr("Font style"))), - } - let size = bound("fontSize"); - let (edit, ev) = widgets::number_field_bindable( - ui, - Id::unique(("ts_size", id)), - widgets::Lead::Text(tr("Size")), - Some(def.font_size), - "", - half, - 1.0, - Some(size.as_deref()), - widgets::Empty::Text(tr("Mixed")), - ); - if let Some(widgets::FieldEdit::Set(v) | widgets::FieldEdit::Scrub(v, true)) = edit.and_then(|e| e.settled()) { - set(out, &|d| d.font_size = v.clamp(1.0, 5000.0)); - } - match ev { - Some(widgets::BindEvent::Open(at)) => crate::variable_ui::open_style(ui, id, "fontSize", VariableType::Number, at), - Some(widgets::BindEvent::Detach) => out.act = Some(Act::Unbind(id.to_string(), "fontSize".to_string())), - None => {} - } - }); - ui.horizontal(|ui| { - let area = Rect::from_min_size(ui.cursor().min, vec2(half, widgets::FIELD_H)); - match bound("lineHeight") { - Some(name) => { - let (r, _) = ui.allocate_exact_size(area.size(), Sense::hover()); - text_binding(ui, id, "lineHeight", VariableType::Number, r, &name, widgets::Lead::Named(tr("Line height")), out); - } - None => { - if let Some(v) = widgets::text_field(ui, Id::unique(("ts_lh", id)), &def.line_height.label(), half, tr("Line height")) - && let Some(lh) = - crate::typography::parse_line_height(&v, Some(def.line_height)).and_then(|v| crate::typography::line_height_of(&v)) - { - set(out, &|d| d.line_height = lh); - } - if crate::variable_ui::variable_button(ui, area, Id::unique(("ts_bind", id, "lineHeight"))) { - crate::variable_ui::open_style(ui, id, "lineHeight", VariableType::Number, area.left_bottom()); - } - } - } - let area = Rect::from_min_size(ui.cursor().min, vec2(half, widgets::FIELD_H)); - match bound("letterSpacing") { - Some(name) => { - let (r, _) = ui.allocate_exact_size(area.size(), Sense::hover()); - text_binding(ui, id, "letterSpacing", VariableType::Number, r, &name, widgets::Lead::Named(tr("Letter spacing")), out); - } - None => { - if let Some(v) = widgets::text_field(ui, Id::unique(("ts_ls", id)), &def.letter_spacing.label(), half, tr("Letter spacing")) - && let Some(ls) = crate::typography::parse_letter_spacing(&v, Some(def.letter_spacing)) - .and_then(|v| crate::typography::letter_spacing_of(&v)) - { - set(out, &|d| d.letter_spacing = ls); - } - if crate::variable_ui::variable_button(ui, area, Id::unique(("ts_bind", id, "letterSpacing"))) { - crate::variable_ui::open_style(ui, id, "letterSpacing", VariableType::Number, area.left_bottom()); - } - } - } - }); - (family_resp, style_resp) - }); - if let Some(family_resp) = family_resp { - crate::right::menu_popup(&family_resp).width(260.0).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| { - if crate::right::menu_item(ui, tr("Apply variable"), "") { - crate::variable_ui::open_style(ui, id, "fontFamily", VariableType::String, family_resp.rect.left_bottom()); - ui.close(); - return; - } - ui.separator(); - if let Some(f) = crate::typography::font_picker(ui, Some(&def.font_family), family_resp.clicked()).picked { - set(out, &|d| { - d.font_family = f.clone(); - let styles = figcraft_text::family_styles(&f); - if !styles.is_empty() && !styles.contains(&d.font_style) { - d.set_font_style(styles.iter().find(|s| s.eq_ignore_ascii_case("Regular")).or(styles.first()).cloned().unwrap_or_default()); - } - }); - ui.close(); - } - }); + None => Some(widgets::dropdown(ui, &def.font_family, W, None).on_hover_text(tr("Font"))), } - if let Some(sr) = style_resp { - crate::right::menu_popup(&sr).width(200.0).show(|ui| { - if crate::right::menu_item(ui, tr("Apply variable"), "") { - crate::variable_ui::open_style(ui, id, "fontStyle", VariableType::String, sr.rect.left_bottom()); - ui.close(); - return; +} + +/// The font style field (a dropdown, whose menu is returned, or a variable chip) and the size field, in one row. +fn font_style_size_row(ui: &mut Ui, doc: &Document, style: &Style, def: &TextStyle, half: f32, out: &mut Frame) -> Option { + let id = style.id.as_str(); + let mut style_resp = None; + ui.horizontal(|ui| { + match bound_name(doc, style, "fontStyle") { + Some(name) => { + let (r, _) = ui.allocate_exact_size(vec2(half, widgets::FIELD_H), Sense::hover()); + text_binding(ui, id, "fontStyle", VariableType::String, r, &name, widgets::Lead::Named(tr("Font style")), out); } - ui.separator(); - egui::ScrollArea::vertical().max_height(320.0).show(ui, |ui| { - for s in figcraft_text::family_styles(&def.font_family) { - let mark = if def.font_style == s { "✓ " } else { " " }; - if crate::right::menu_item(ui, &format!("{mark}{s}"), "") { - set(out, &|d| d.set_font_style(s.clone())); - ui.close(); - } + None => style_resp = Some(widgets::dropdown(ui, &def.font_style, half, None).on_hover_text(tr("Font style"))), + } + font_size_field(ui, doc, style, def, half, out); + }); + style_resp +} + +/// The font size field, which also takes a variable. +fn font_size_field(ui: &mut Ui, doc: &Document, style: &Style, def: &TextStyle, half: f32, out: &mut Frame) { + let id = style.id.as_str(); + let size = bound_name(doc, style, "fontSize"); + let (edit, ev) = widgets::number_field_bindable( + ui, + Id::unique(("ts_size", id)), + widgets::Lead::Text(tr("Size")), + Some(def.font_size), + "", + half, + 1.0, + Some(size.as_deref()), + widgets::Empty::Text(tr("Mixed")), + ); + if let Some(widgets::FieldEdit::Set(v) | widgets::FieldEdit::Scrub(v, true)) = edit.and_then(|e| e.settled()) { + set_text(def, id, out, |d| d.font_size = v.clamp(1.0, 5000.0)); + } + match ev { + Some(widgets::BindEvent::Open(at)) => crate::variable_ui::open_style(ui, id, "fontSize", VariableType::Number, at), + Some(widgets::BindEvent::Detach) => out.act = Some(Act::Unbind(id.to_string(), "fontSize".to_string())), + None => {} + } +} + +/// The line height field: a variable chip when bound, else a text field with a variable button beside it. +fn line_height_field(ui: &mut Ui, doc: &Document, style: &Style, def: &TextStyle, half: f32, area: Rect, out: &mut Frame) { + let id = style.id.as_str(); + match bound_name(doc, style, "lineHeight") { + Some(name) => { + let (r, _) = ui.allocate_exact_size(area.size(), Sense::hover()); + text_binding(ui, id, "lineHeight", VariableType::Number, r, &name, widgets::Lead::Named(tr("Line height")), out); + } + None => { + if let Some(v) = widgets::text_field(ui, Id::unique(("ts_lh", id)), &def.line_height.label(), half, tr("Line height")) + && let Some(lh) = crate::typography::parse_line_height(&v, Some(def.line_height)).and_then(|v| crate::typography::line_height_of(&v)) + { + set_text(def, id, out, |d| d.line_height = lh); + } + if crate::variable_ui::variable_button(ui, area, Id::unique(("ts_bind", id, "lineHeight"))) { + crate::variable_ui::open_style(ui, id, "lineHeight", VariableType::Number, area.left_bottom()); + } + } + } +} + +/// The letter spacing field: a variable chip when bound, else a text field with a variable button beside it. +fn letter_spacing_field(ui: &mut Ui, doc: &Document, style: &Style, def: &TextStyle, half: f32, area: Rect, out: &mut Frame) { + let id = style.id.as_str(); + match bound_name(doc, style, "letterSpacing") { + Some(name) => { + let (r, _) = ui.allocate_exact_size(area.size(), Sense::hover()); + text_binding(ui, id, "letterSpacing", VariableType::Number, r, &name, widgets::Lead::Named(tr("Letter spacing")), out); + } + None => { + if let Some(v) = widgets::text_field(ui, Id::unique(("ts_ls", id)), &def.letter_spacing.label(), half, tr("Letter spacing")) + && let Some(ls) = + crate::typography::parse_letter_spacing(&v, Some(def.letter_spacing)).and_then(|v| crate::typography::letter_spacing_of(&v)) + { + set_text(def, id, out, |d| d.letter_spacing = ls); + } + if crate::variable_ui::variable_button(ui, area, Id::unique(("ts_bind", id, "letterSpacing"))) { + crate::variable_ui::open_style(ui, id, "letterSpacing", VariableType::Number, area.left_bottom()); + } + } + } +} + +/// The fields of a text style, in rows: font, then style and size, then line height and letter +/// spacing. Returns the font and style dropdowns, whose menus are opened after the fields. +fn text_property_fields(ui: &mut Ui, doc: &Document, style: &Style, def: &TextStyle, out: &mut Frame) -> (Option, Option) { + let half = (W - 8.0) / 2.0; + ui.spacing_mut().item_spacing = vec2(8.0, 6.0); + let family_resp = font_family_field(ui, doc, style, def, out); + let style_resp = font_style_size_row(ui, doc, style, def, half, out); + ui.horizontal(|ui| { + let area = Rect::from_min_size(ui.cursor().min, vec2(half, widgets::FIELD_H)); + line_height_field(ui, doc, style, def, half, area, out); + let area = Rect::from_min_size(ui.cursor().min, vec2(half, widgets::FIELD_H)); + letter_spacing_field(ui, doc, style, def, half, area, out); + }); + (family_resp, style_resp) +} + +/// The font menu: Apply variable, then the installed fonts. Picking a font keeps its style when the +/// family has one, else falls back to Regular or the first style. +fn font_family_menu(id: &str, def: &TextStyle, family_resp: &Response, out: &mut Frame) { + crate::right::menu_popup(family_resp).width(260.0).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| { + if crate::right::menu_item(ui, tr("Apply variable"), "") { + crate::variable_ui::open_style(ui, id, "fontFamily", VariableType::String, family_resp.rect.left_bottom()); + ui.close(); + return; + } + ui.separator(); + if let Some(f) = crate::typography::font_picker(ui, Some(&def.font_family), family_resp.clicked()).picked { + set_text(def, id, out, |d| { + d.font_family = f.clone(); + let styles = figcraft_text::family_styles(&f); + if !styles.is_empty() && !styles.contains(&d.font_style) { + d.set_font_style(styles.iter().find(|s| s.eq_ignore_ascii_case("Regular")).or(styles.first()).cloned().unwrap_or_default()); } }); + ui.close(); + } + }); +} + +/// The font style menu: Apply variable, then the styles of the current font, the current one checked. +fn font_style_menu(id: &str, def: &TextStyle, style_resp: &Response, out: &mut Frame) { + crate::right::menu_popup(style_resp).width(200.0).show(|ui| { + if crate::right::menu_item(ui, tr("Apply variable"), "") { + crate::variable_ui::open_style(ui, id, "fontStyle", VariableType::String, style_resp.rect.left_bottom()); + ui.close(); + return; + } + ui.separator(); + egui::ScrollArea::vertical().max_height(320.0).show(ui, |ui| { + for s in figcraft_text::family_styles(&def.font_family) { + let mark = if def.font_style == s { "✓ " } else { " " }; + if crate::right::menu_item(ui, &format!("{mark}{s}"), "") { + set_text(def, id, out, |d| d.set_font_style(s.clone())); + ui.close(); + } + } }); + }); +} + +/// A text style's typography in the editor: a sample, then font, style, size, line height and +/// letter spacing; a change redefines the style (every linked char follows). Each field takes a +/// variable: the font and style menus start with Apply variable, the other fields show a variable +/// button on hover, and a bound field shows its variable instead of its value. +fn text_properties(ui: &mut Ui, doc: &Document, style: &Style, def: &TextStyle, out: &mut Frame) { + let id = style.id.as_str(); + text_sample_header(ui, def, out); + // The dropdowns' menus open outside the dark scope (they're regular popups). + let (family_resp, style_resp) = crate::theme::on_dark(ui, |ui| text_property_fields(ui, doc, style, def, out)); + if let Some(family_resp) = family_resp { + font_family_menu(id, def, &family_resp, out); + } + if let Some(sr) = style_resp { + font_style_menu(id, def, &sr, out); } } From 7dc5d3b37770a6b81970a6dc00f7b636505247d4 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 25 Oct 2026 21:11:43 -0400 Subject: [PATCH 43/50] refactor(mcp): group with_marker's cut sizes into a struct (SonarCloud S107) The depth and wire-size numbers describing a cut subtree are now one Cut value, so with_marker takes 5 parameters instead of 8. Output is unchanged. --- crates/mcp/src/tools.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/crates/mcp/src/tools.rs b/crates/mcp/src/tools.rs index 32ad8832..a0e51f0a 100644 --- a/crates/mcp/src/tools.rs +++ b/crates/mcp/src/tools.rs @@ -742,7 +742,7 @@ fn get_node(b: &mut dyn Backend, a: &Map) -> Result) -> Result budget || next.is_some(); let mut out = with_marker( value, - depth, - used, - wire, - used_wire, + Cut { asked: depth, used, asked_wire: wire, used_wire }, max_bytes, over, Some(json!({ @@ -812,19 +809,19 @@ fn children_window(value: &mut Value, offset: usize, budget: usize) -> bool { true } -/// `value` with the `truncated` object saying how it was cut. `over`: the subtree asked for passed -/// the limit (else the window is only the `offset` asked for). `children`: the window, when the -/// children were cut as well as (or instead of) the depth. -fn with_marker( - mut value: Value, +/// How a subtree was cut: the depth asked for and the depth reported, with their sizes on the wire. +struct Cut { asked: u64, used: u64, asked_wire: usize, used_wire: usize, - max_bytes: usize, - over: bool, - children: Option, -) -> Value { +} + +/// `value` with the `truncated` object saying how it was cut. `over`: the subtree asked for passed +/// the limit (else the window is only the `offset` asked for). `children`: the window, when the +/// children were cut as well as (or instead of) the depth. +fn with_marker(mut value: Value, cut: Cut, max_bytes: usize, over: bool, children: Option) -> Value { + let Cut { asked, used, asked_wire, used_wire } = cut; if let Some(obj) = value.as_object_mut() { let mut marker = json!({ "requestedDepth": asked, From 887676207ab9c2934074e85ad7cc70b63ab21bfb Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 25 Oct 2026 21:11:43 -0400 Subject: [PATCH 44/50] ci(sonar): exclude the generated coverage-archive tree from analysis CI unpacks a coverage archive containing a build-generated locales.rs (the i18n table from crates/ui-egui/build.rs) into coverage-archive/. Scanning it made almost all new code duplicated (new_duplicated_lines_density 67.8%). --- sonar-project.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/sonar-project.properties b/sonar-project.properties index 92562d54..12ecf38e 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,2 +1,3 @@ sonar.projectKey=storytold_figcraft sonar.organization=storytold +sonar.exclusions=coverage-archive/** From 831fa599f1f9d8848d3d0307adfabfaec50c4777 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 25 Oct 2026 21:25:39 -0400 Subject: [PATCH 45/50] Revert "ci(sonar): exclude the generated coverage-archive tree from analysis" This reverts commit 887676207ab9c2934074e85ad7cc70b63ab21bfb. --- sonar-project.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 12ecf38e..92562d54 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,3 +1,2 @@ sonar.projectKey=storytold_figcraft sonar.organization=storytold -sonar.exclusions=coverage-archive/** From f124d907bcbc4e58837846cd6b3e501db263d410 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 24 Oct 2026 10:02:35 +0700 Subject: [PATCH 46/50] #1184: boolean operands use the rounded per-side strokes too One side_strokes helper (square or rounded, as #1044 paints them) serves stroke_area and the boolean operand outline, instead of a second, square-only copy; test for a rounded per-side border. --- crates/render/src/boolean_cache_tests.rs | 20 ++++++++++ crates/render/src/draw.rs | 47 +++++++++++++----------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/crates/render/src/boolean_cache_tests.rs b/crates/render/src/boolean_cache_tests.rs index 6e10f746..452626c2 100644 --- a/crates/render/src/boolean_cache_tests.rs +++ b/crates/render/src/boolean_cache_tests.rs @@ -253,3 +253,23 @@ fn stroke_only_text_operands_use_glyphs_instead_of_the_text_box() { text.characters = " ".into(); assert!(outline(&d, b).elements().is_empty(), "spaces have no stroked glyphs"); } + +#[test] +fn rounded_side_borders_follow_their_corners_in_booleans() { + use figcraft_doc::StrokeAlign; + use figcraft_geom::Point; + let mut d = Document::new("rounded borders"); + let page = d.first_page().unwrap(); + let b = d.create(page, NodeKind::BooleanOp { op: BoolOp::Union }, "B", 0.0, 0.0, 100.0, 100.0).unwrap(); + let id = d.create(b, NodeKind::Rectangle, "operand", 0.0, 0.0, 100.0, 100.0).unwrap(); + let n = d.get_mut(id).unwrap(); + n.fills.clear(); + n.strokes = vec![Paint::solid(Color::BLACK)]; + n.stroke.align = StrokeAlign::Inside; + n.stroke.sides = Some([8.0; 4]); + n.corners.radii = [30.0; 4]; + let p = outline(&d, b); + assert_ne!(p.winding(Point::new(50.0, 4.0)), 0, "top border"); + assert_eq!(p.winding(Point::new(3.0, 3.0)), 0, "the rounded corner leaves the square's tip out"); + assert_eq!(p.winding(Point::new(50.0, 50.0)), 0, "hollow inside"); +} diff --git a/crates/render/src/draw.rs b/crates/render/src/draw.rs index f36c51fa..1da5e495 100644 --- a/crates/render/src/draw.rs +++ b/crates/render/src/draw.rs @@ -156,19 +156,26 @@ pub(crate) fn hash_path(p: &BezPath, h: &mut impl Hasher) { } } +/// Per-side strokes on rectangles and frames (a ring under non-zero winding too), if `n` has them. +fn side_strokes(n: &Node) -> Option> { + let props = &n.stroke; + let sides = props.sides?; + if !matches!(n.kind, NodeKind::Rectangle | NodeKind::Frame | NodeKind::Component { .. } | NodeKind::Instance { .. }) { + return None; + } + let c = &n.corners; + Some(Arc::new(if c.uniform() == Some(0.0) { + figcraft_pathops::rect_side_strokes(n.width, n.height, sides, props.align) + } else { + figcraft_pathops::rounded_side_strokes(n.width, n.height, c.radii, c.smoothing, sides, props.align) + })) +} + /// The stroke area of a node in local coordinates. pub fn stroke_area(n: &Node, path: &BezPath, closed: bool) -> Arc { let props = &n.stroke; - // Per-side strokes on rectangles/frames. - if let Some(sides) = props.sides - && matches!(n.kind, NodeKind::Rectangle | NodeKind::Frame | NodeKind::Component { .. } | NodeKind::Instance { .. }) - { - let c = &n.corners; - return Arc::new(if c.uniform() == Some(0.0) { - figcraft_pathops::rect_side_strokes(n.width, n.height, sides, props.align) - } else { - figcraft_pathops::rounded_side_strokes(n.width, n.height, c.radii, c.smoothing, sides, props.align) - }); + if let Some(p) = side_strokes(n) { + return p; } // Rect/ellipse inside/outside strokes without booleans: an even-odd ring of two outlines. if props.dashes.is_empty() && props.profile().is_none() && props.brush.is_none() && closed && props.align != StrokeAlign::Center { @@ -212,15 +219,15 @@ pub fn stroke_area(n: &Node, path: &BezPath, closed: bool) -> Arc { cached_stroke_outline(n, path, closed) } -/// A non-zero stroke outline, shared by painting and boolean operands. +/// The stroke a boolean operand contributes: like [`stroke_area`], but never an even-odd ring +/// (boolean folding uses non-zero winding). +fn operand_stroke(n: &Node, path: &BezPath, closed: bool) -> Arc { + side_strokes(n).unwrap_or_else(|| cached_stroke_outline(n, path, closed)) +} + +/// A non-zero stroke outline (cached), shared by painting and boolean operands. fn cached_stroke_outline(n: &Node, path: &BezPath, closed: bool) -> Arc { let props = &n.stroke; - if let Some(sides) = props.sides - && matches!(n.kind, NodeKind::Rectangle | NodeKind::Frame | NodeKind::Component { .. } | NodeKind::Instance { .. }) - && n.corners.uniform() == Some(0.0) - { - return Arc::new(figcraft_pathops::rect_side_strokes(n.width, n.height, sides, props.align)); - } let mut h = std::collections::hash_map::DefaultHasher::new(); hash_path(path, &mut h); (props.weight.to_bits(), props.align as u8, props.cap_start as u8, props.cap_end as u8, props.join as u8, props.miter_limit.to_bits(), closed) @@ -334,7 +341,7 @@ fn subtree_outline_at(doc: &Document, n: &Node, depth: usize, stroke_only: bool) if n.fills.iter().any(|f| f.visible) { out.extend(p.elements().iter().copied()); } else if stroke_only && n.has_visible_stroke() { - out.extend(cached_stroke_outline(n, &p, true).elements().iter().copied()); + out.extend(operand_stroke(n, &p, true).elements().iter().copied()); } } for c in n.children.iter().filter_map(|c| doc.node(*c)) { @@ -352,9 +359,7 @@ fn subtree_outline_at(doc: &Document, n: &Node, depth: usize, stroke_only: bool) let (path, _) = node_outline_at(doc, n, depth)?; let path = if matches!(n.kind, NodeKind::Text(_)) { path } else { figcraft_doc::geometry::stroke_geometry(n).unwrap_or(path) }; let closed = figcraft_doc::geometry::is_closed(n) || matches!(n.kind, NodeKind::BooleanOp { .. }); - // Boolean folding uses non-zero winding; the canvas stroke cache also contains - // even-odd rectangle rings, so use the winding-correct stroke outline here. - Some(((*cached_stroke_outline(n, &path, closed)).clone(), FillRule::Winding)) + Some(((*operand_stroke(n, &path, closed)).clone(), FillRule::Winding)) } _ => node_outline_at(doc, n, depth), } From 39215564277b3be629dea90748199651631bde9b Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 24 Oct 2026 10:10:01 +0700 Subject: [PATCH 47/50] #919: the windows_slim_errors flag applies to every Windows GNU target, matching the compile check --- .cargo/config.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 8abc94d7..30d819a2 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -6,8 +6,9 @@ CRAFT_FONTS_DIR = { value = "../craft-fonts", relative = true } # The Windows UI Automation adapter can be asked about a node that disappeared in the # same frame. On MinGW, converting that HRESULT through windows-result's thread COM # error-info path has crashed in GetErrorInfo. Keep the HRESULT without that extra -# COM lookup; this leaves the AccessKit tree and screen-reader support enabled. -[target.x86_64-pc-windows-gnu] +# COM lookup; this leaves the AccessKit tree and screen-reader support enabled. Every Windows GNU +# target (x86_64, i686, the gnullvm ones) gets it, as the check in apps/figcraft/src/main.rs asks. +[target.'cfg(all(windows, target_env = "gnu"))'] rustflags = ["--cfg=windows_slim_errors"] [alias] From 08ce40fd88356372033adffbc6bbcfd98e34a4ac Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 24 Oct 2026 09:57:21 +0700 Subject: [PATCH 48/50] #1134: name the snapshot checksum's place SNAP_HEADER - 4, not 13 --- apps/figcraft-server/src/disk.rs | 2 +- docs/server-memory-retention.md | 23 ----------------------- 2 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 docs/server-memory-retention.md diff --git a/apps/figcraft-server/src/disk.rs b/apps/figcraft-server/src/disk.rs index cb6e0453..312b4aea 100644 --- a/apps/figcraft-server/src/disk.rs +++ b/apps/figcraft-server/src/disk.rs @@ -135,7 +135,7 @@ pub fn encode_snapshot(generation: u64, state: &SessionState) -> Result, out.extend_from_slice(&0u32.to_le_bytes()); let mut out = message::encode_into(state, out).map_err(|e| e.to_string())?; let sum = crc(&out[SNAP_HEADER..]); - out[13..SNAP_HEADER].copy_from_slice(&sum.to_le_bytes()); + out[SNAP_HEADER - 4..SNAP_HEADER].copy_from_slice(&sum.to_le_bytes()); Ok(out) } diff --git a/docs/server-memory-retention.md b/docs/server-memory-retention.md deleted file mode 100644 index ef4e0b94..00000000 --- a/docs/server-memory-retention.md +++ /dev/null @@ -1,23 +0,0 @@ -# Server memory follow-up - -Joining a persisted session issues a client id and makes its journal dirty, even if nobody edits -the document. Previously, the last client leaving caused a full snapshot rewrite for that id. -For image-heavy documents this creates large temporary allocations and unnecessary disk writes; -an allocator can retain the freed memory after the room closes. - -On idle, the server now flushes the journal and only compacts when the document sequence is newer -than the stored snapshot, or when flushing failed and a snapshot must be attempted as a fallback. -Issued ids and refusals remain durable in the journal. Existing size/count compaction thresholds -remain in effect, and edited documents still compact when the last participant leaves. - -Snapshot encoding also appends the versioned postcard body directly to the snapshot header's -buffer, then fills the checksum. It no longer holds a separate complete encoded body alongside -the finished snapshot. The bytes, generation, checksum and file format are unchanged. - -Regression coverage uses synthetic documents: six read-only sessions across store reopenings -must preserve increasing client ids without rewriting the snapshot; exact legacy framing and -checksum must match; the binary message body must be unchanged when appended to a prefix. -Existing crash recovery, damaged-input and edit compaction tests continue to apply. - -This reduces unnecessary temporary allocations. It does not promise that the operating system -immediately reclaims every freed allocation, or that all large-document memory costs are solved. From b162ef884c2079be1b891b8383005bd219a6beef Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 24 Oct 2026 09:57:21 +0700 Subject: [PATCH 49/50] #1134: the server memory note becomes a revision row and a line in docs/server.md The paragraph above the ROADMAP stage line moves into the revision history; docs/server-memory-retention.md is folded into the compaction bullet of docs/server.md. --- ROADMAP.md | 6 +----- docs/server.md | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 6f4d2884..8581dbaa 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,10 +1,5 @@ # FigCraft Roadmap -M9 / M7.4 server memory follow-up: read-only disconnects retain their durable client-id journal -without rebuilding the image-bearing snapshot. Snapshot encoding appends into its header buffer, -avoiding a second full payload copy while preserving the existing disk format. See -[`docs/server-memory-retention.md`](docs/server-memory-retention.md). - **Stage: alpha** · next: beta, ~26 points and ~162–292 h away (one Opus 5.5 agent; ~33–67 h wall-clock with 5 agents) > **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (egui 0.37 hidden-capture deadline contract; Dev Mode measurements kept on the canvas and a read-only layers panel; boards: a board area row and progress entry; community fixes in #507, #510, #529 and #530: auto-save, a text box by dragging, batch step references, removing someone from a live session, Russian and Turkish catalogs reviewed, Czech and Indonesian drafts, the Japanese draft completed, zoom previews, the web clipboard, Alt-drag snapping and Cmd+D repeat, recovery copies, crash and rollback fixes, colour emoji, `.fig` import fixes; earlier changes are in the revision history below) · **Target:** Figma Design (desktop app 126.10.7) @@ -341,6 +336,7 @@ Ranked; detail and milestones in [`docs/roadmap.md`](docs/roadmap.md). | Date | Change | Summary | |---|---|---| | 2026-10-25 | minor | egui 0.37 capture lifecycle: screenshots with hidden or unknown visibility queue, request a hidden paint, and expire after 60 seconds if no capture arrives (headless-tested contract). Logic-only edits, saves and inspection continue while hidden. Native visible GUI and forced hidden-window paint, browser and Wayland behavior remain unqualified; parity percentages are unchanged. | +| 2026-10-24 | minor | Server memory (#1134): when the last person leaves a file nobody edited, figcraft-server keeps the client ids it issued in the log instead of rewriting the snapshot (compaction still follows `compact_after`/`compact_mb` and edits), and a snapshot is encoded straight into its file buffer, without a second copy of the body; the file format is unchanged. Numbers unchanged | | 2026-10-24 | minor | Dev Mode tail (M6, gap 16): Measurements kept on the canvas (gap 16): `devMode.addMeasurement {from?, to?, side?}` places one between two layers, along one side of a layer or (neither) to the layer around it, stored on the layer it starts from (saved in `.figcraft`, synced, undoable; old files open without them); Dev Mode draws them as labelled redlines that follow the layers, the Inspect tab lists them (those of the selected layer, or every one on the page), places and removes them; `devMode.removeMeasurement` and `devMode.measurements` remove and list them; a copy keeps those to layers copied with it. The layers panel is read-only in Dev Mode: rows select and expand, but don't rename, reorder, hide or lock. Dev Mode 97% → 98% breadth, 76% → 78% ready, 2–4 h → 1–2 h; headline numbers unchanged at this rounding | | 2026-10-24 | minor | Boards (M12): a file kind of its own (`file.newBoard`, saved in `.figcraft`, carried to live-session joiners) with sticky notes, shapes with text, connectors that re-route when what they join moves (an engine recompute, the same for local edits, undo and others' edits), marker, highlighter and eraser, stamps with the placer's name, a board toolbar and a contextual bar; prototyping and Dev Mode refuse on boards; design files and boards have their own marks on tabs and file rows. Boards row added outside the weighted numbers; headline numbers unchanged at this rounding | | 2026-10-15 | minor | Auto-save (#305, #296): Preferences ▸ Save files automatically (`pref.autoSave`, off by default; desktop only, the browser has no files to save to) saves each open file that has a path 3 s after its last change, so steady editing doesn't save every few seconds, and never during a gesture, a live text preview or while a version is shown. The file is encoded on a thread of its own and written as of that moment (edits made meanwhile stay unsaved); a failed save says why in a toast and is tried again a minute later, and version history checkpoints keep coming with it on. Numbers unchanged | diff --git a/docs/server.md b/docs/server.md index 87e68b3d..a4c79ee3 100644 --- a/docs/server.md +++ b/docs/server.md @@ -336,8 +336,8 @@ the address it came from and when it was last opened (for expiry). beside it, flushed, then renamed over the old one. The log is only ever appended to, and synced before the server tells anyone about the change. - **Compaction** writes the file's state as the next snapshot and starts an empty log, after - `compact_after` entries or `compact_mb` of log, when the last person leaves, and when the server - stops. A log left over from a compaction cut short is replayed over the snapshot, which already + `compact_after` entries or `compact_mb` of log, when the last person leaves a file that was + edited (the ids of people who only joined stay in the log), and when the server stops. A log left over from a compaction cut short is replayed over the snapshot, which already holds it all, so nothing changes. If a damaged generation field made a current log look like such a leftover, its edits the snapshot lacks are recovered the same way and the damage is reported. - **Damage is skipped and reported, never deleted.** At startup a folder whose description, links From 3c9fee8dbd0d654b3465e1ffb7f49315f88bc04c Mon Sep 17 00:00:00 2001 From: BFlat Date: Mon, 26 Oct 2026 08:59:52 +0700 Subject: [PATCH 50/50] build: one craft-libs rev for every craft-libs crate (495e597) (#1354) --- Cargo.lock | 22 +++++++++++----------- Cargo.toml | 10 +++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d6b8c87..9a3896b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -253,7 +253,7 @@ dependencies = [ "objc2-foundation 0.3.2", "parking_lot", "percent-encoding", - "windows-sys 0.61.2", + "windows-sys 0.52.0", "wl-clipboard-rs", "x11rb", ] @@ -907,7 +907,7 @@ dependencies = [ [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=82a24b006eefa036b43c09a67fb9a3fbd17ffe63#82a24b006eefa036b43c09a67fb9a3fbd17ffe63" +source = "git+https://github.com/storytold/craft-libs?rev=495e5971bc024aa96e6ed318cb6e7cd3a0103184#495e5971bc024aa96e6ed318cb6e7cd3a0103184" [[package]] name = "craft-update" @@ -937,7 +937,7 @@ dependencies = [ [[package]] name = "craft-window" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=25da1314d443171b4adeaad2cd9454b273f35c6f#25da1314d443171b4adeaad2cd9454b273f35c6f" +source = "git+https://github.com/storytold/craft-libs?rev=495e5971bc024aa96e6ed318cb6e7cd3a0103184#495e5971bc024aa96e6ed318cb6e7cd3a0103184" dependencies = [ "wayland-client", ] @@ -1437,7 +1437,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -2666,7 +2666,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" [[package]] name = "krilla" version = "0.8.2" -source = "git+https://github.com/storytold/craft-libs?rev=9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef#9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef" +source = "git+https://github.com/storytold/craft-libs?rev=495e5971bc024aa96e6ed318cb6e7cd3a0103184#495e5971bc024aa96e6ed318cb6e7cd3a0103184" dependencies = [ "base64 0.22.1", "bumpalo", @@ -3353,7 +3353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -4025,7 +4025,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -4082,7 +4082,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -4633,10 +4633,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.4.3", + "getrandom 0.3.4", "once_cell", "rustix 1.1.5", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -5749,7 +5749,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 64a8c8a2..2be79ed1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,14 +32,14 @@ figcraft-mcp = { path = "crates/mcp" } figcraft-collab-net = { path = "crates/collab-net" } figcraft-plugin = { path = "crates/plugin" } +# craft-libs crates all pin one rev (craftrules standards/shared-libraries.md): bump them together. # Which paths stored in a document may be followed (craft-libs). -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "82a24b006eefa036b43c09a67fb9a3fbd17ffe63" } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "495e5971bc024aa96e6ed318cb6e7cd3a0103184" } # Who draws the window frame on Linux — the compositor or the app — so every Craft app shows the # same native titlebar per desktop (craft-libs). FigCraft only reads the probe result and maps it # to its own `TitleBar`, so it does not enable craft-window's optional `egui` helpers (which would -# pull a second egui family version). The rev is the last merged one; the released 0.37 pin is -# supplied by the migration's reviewed craft-libs revision. -craft-window = { git = "https://github.com/storytold/craft-libs", rev = "25da1314d443171b4adeaad2cd9454b273f35c6f" } +# pull a second egui family version). +craft-window = { git = "https://github.com/storytold/craft-libs", rev = "495e5971bc024aa96e6ed318cb6e7cd3a0103184" } craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "495e5971bc024aa96e6ed318cb6e7cd3a0103184", features = ["egui"] } # foundation @@ -154,4 +154,4 @@ winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457 # craft-libs' vendored krilla 0.8.2: decoded PNGs are capped at 1 GiB and reserved fallibly, and a # panic while drawing unwinds without aborting. -krilla = { git = "https://github.com/storytold/craft-libs", rev = "9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef" } +krilla = { git = "https://github.com/storytold/craft-libs", rev = "495e5971bc024aa96e6ed318cb6e7cd3a0103184" }