DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge remote-tracking branch 'origin/main' into codex/new-gradient-swatch
moppeeercb0a95265722
diff --cc ROADMAP.mdindex e34e69c17,c60a04107..083f8aa2e--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -129,7 -128,13 +128,14 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+- **2026-10-13** · New Swatch works as InDesign's: a gradient made in the Gradient panel becomes "New Gradient Swatch" (still applied), an unnamed colour a listed swatch, a named swatch a "copy" (`swatch.new`); `swatch.create {gradient}` makes a gradient swatch from colour swatches. No readiness percentage change.+ - **2026-10-12** · Text threads by hand: click a selected text frame's in or out port to load+ the text cursor, then click a frame to thread it, click empty space for a column-wide frame or+ drag one (it snaps like frame drawing); Shift-click autoflows, Alt-click stays loaded on the+ frame just added; click the linked frame or double-click a port to break the thread.+ `text.thread`, `text.unthread`, `text.removeFromThread` with undo; locked frames and layers+ refuse threads. The alpha gate now waits only on the Primary Text Frame page fixes (#165). No+ readiness percentage change.- **2026-10-12** · macOS Dock Quit uses the same unsaved-document prompts as window and menu Quit. Repeated requests keep the current answers; Cancel retains every tab and unsaved recovery checkpoint, and completed Save/Don't Save answers exit through the ordinary event loop. No readiness percentage change.- **2026-10-12** · Orderly native exit writes the latest recovery state after finalizing current quit approvals; incomplete or stale plans keep their documents, and Undo to the saved state clears stale recovery. Unavailable or failed recovery is reported. Cancelable macOS Dock Quit remains open (#544). No readiness percentage change.- **2026-10-12** · Recovered documents keep a checkpoint until saved, closed or reverted, including a second crash before autosave. Restarted document IDs and explicit recovery folders preserve other snapshots; failed republishing retains the original. No readiness percentage change.diff --cc crates/engine/src/cmd/style.rsindex fa2ee78d0,0280612d1..52f0d9467--- a/crates/engine/src/cmd/style.rs+++ b/crates/engine/src/cmd/style.rs@@@ -1840,71 -1845,6 +1933,75 @@@ mod sample_color_tests}}+#[cfg(test)]+mod gradient_swatch_tests {+ use designcraft_color::SwatchValue;+ use serde_json::json;++ fn doc() -> crate::Session {+ let mut s = crate::Session::new();+ s.execute("file.new", &json!({})).unwrap();+ s+ }++ #[test]+ fn a_gradient_swatch_from_colour_swatches() {+ let mut s = doc();+ // As the Gradient panel's stops take swatches dragged onto them.+ let r = s+ .execute(+ "swatch.create",+ &json!({"gradient": {"stops": [{"location": 100, "swatch": "C=100 M=0 Y=0 K=0"}, {"location": 0, "swatch": "C=0 M=100 Y=0 K=0"}]}}),+ )+ .unwrap();+ assert_eq!(r["name"], "New Gradient Swatch");+ let d = &s.doc().unwrap().doc;+ let w = d.swatch("New Gradient Swatch").unwrap();+ assert!(w.named && !w.hidden);+ let SwatchValue::Gradient { gradient } = &w.value else { panic!("{w:?}") };+ assert_eq!(gradient.stops[0].color, d.resolve_color("C=0 M=100 Y=0 K=0", 1.0).unwrap(), "sorted: magenta first");+ assert_eq!(gradient.stops[1].color, d.resolve_color("C=100 M=0 Y=0 K=0", 1.0).unwrap());+ // A second one gets its own name; bad stops are refused.+ let r = s+ .execute(+ "swatch.create",+ &json!({"gradient": {"kind": "radial", "stops": [{"color": "#ff0000"}, {"location": 100, "color": "#0000ff"}]}}),+ )+ .unwrap();+ assert_eq!(r["name"], "New Gradient Swatch 2");+ for bad in [+ json!({"stops": [{"swatch": "C=0 M=100 Y=0 K=0"}]}),+ json!({"stops": [{"swatch": "Nope"}, {"swatch": "[Black]"}]}),+ json!({"stops": [{"swatch": "New Gradient Swatch"}, {"swatch": "[Black]"}]}),+ json!({"kind": "conic", "stops": [{"color": "#000000"}, {"color": "#ffffff"}]}),+ ] {+ assert!(s.execute("swatch.create", &json!({"gradient": bad})).is_err(), "{bad}");+ }+ }++ #[test]+ fn new_swatch_names_the_selections_gradient_or_duplicates_a_swatch() {+ let mut s = doc();+ let id = s.execute("frame.create", &json!({"rect": [0, 0, 100, 100], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();+ // A gradient made in the Gradient panel is unnamed (and not listed) …+ s.execute("object.gradient", &json!({"ids": [id], "stops": [{"location": 0, "color": {"c": 0, "m": 100, "y": 0, "k": 0}}, {"location": 100, "color": {"c": 100, "m": 0, "y": 0, "k": 0}}]})).unwrap();+ let fill = |s: &crate::Session| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().fill.swatch.clone();+ assert!(s.doc().unwrap().doc.swatch(&fill(&s)).unwrap().hidden);+ // … until New Swatch: "New Gradient Swatch", listed, still the object's fill.+ s.execute("selection.set", &json!({"ids": [id]})).unwrap();+ assert_eq!(s.execute("swatch.new", &json!({})).unwrap()["name"], "New Gradient Swatch");+ assert_eq!(fill(&s), "New Gradient Swatch");+ let w = s.doc().unwrap().doc.swatch("New Gradient Swatch").unwrap().clone();+ assert!(w.named && !w.hidden && matches!(w.value, SwatchValue::Gradient { .. }));+ // A named swatch: a copy.+ assert_eq!(s.execute("swatch.new", &json!({})).unwrap()["name"], "New Gradient Swatch copy");+ assert_eq!(s.execute("swatch.new", &json!({"swatch": "C=100 M=0 Y=0 K=0"})).unwrap()["name"], "C=100 M=0 Y=0 K=0 copy");+ assert!(s.execute("swatch.new", &json!({"swatch": "[None]"})).is_err());+ s.execute("edit.deselectAll", &json!({})).unwrap();+ assert!(s.execute("swatch.new", &json!({})).is_err(), "nothing selected, no swatch given");+ }+}+++ #[cfg(test)]+ #[path = "text_color_tests.rs"]+ mod text_color_tests;