Swatch libraries: Gradients › Holographic adds iridescent foil and glow gradients

Window › Swatch Libraries › Gradients gains Holographic, after Organic
Fades: seven foils (opaque linear gradients of six narrow pastel and
pearl bands with off-center midpoints) and seven glows (radial
gradients from a bright center out to a clear edge), all mixed with the
Perceptual method. They also list in the Swatches panel's library menu,
swatch.library.list/get/add and the Gradient panel's Presets.

The names, colors and stops are VectorCraft's own. A saved preset that
already uses one of the new names is renamed with the first free number
when the preferences load.

Docs: docs/target-app-parity.md Swatches line, ROADMAP.
This commit is contained in:
dotCooCoo
2026-11-11 23:19:16 -08:00
parent 5eefe7d1c5
commit fc8a7e46c6
33 changed files with 242 additions and 3 deletions
+46 -1
View File
@@ -40,7 +40,16 @@ fn built_in_presets_are_the_gradient_libraries_by_theme_with_unique_names() {
libraries.dedup();
assert_eq!(
libraries,
["Spectrum Gradients", "Sky Gradients", "Neutral Gradients", "Organic Fades", "Duotone Gradients", "Radial Glows", "Metallic Gradients"]
[
"Spectrum Gradients",
"Sky Gradients",
"Neutral Gradients",
"Organic Fades",
"Holographic",
"Duotone Gradients",
"Radial Glows",
"Metallic Gradients"
]
);
let mut seen = std::collections::HashSet::new();
assert!(names(&list).iter().all(|n| seen.insert(n.to_lowercase())), "a name names one preset");
@@ -82,6 +91,42 @@ fn an_organic_fade_applies_with_its_method_midpoints_and_opacities() {
assert_eq!(row["gradient"]["method"], "perceptual");
}
#[test]
fn a_holographic_foil_applies_in_place_as_one_undo_step() {
let (mut s, id) = session_with(json!({"gradient": {"angle": 30}}));
let before = paint(&s, id, false);
let undo = s.doc().unwrap().history.undo.len();
let veil = s.gradient_preset("prism veil").unwrap();
assert_eq!((veil.library, veil.gradient.method), (Some("Holographic"), GradientMethod::Perceptual));
let r = s.execute("gradient.presets.apply", &json!({"name": "prism veil"})).unwrap();
assert_eq!(r["name"].as_str(), Some("Prism Veil"));
let g = paint(&s, id, false);
assert_eq!((g.gradient.kind, g.gradient.method, &g.gradient.stops), (GradientKind::Linear, GradientMethod::Perceptual, &veil.gradient.stops));
assert_eq!(g.gradient.stops.len(), 6);
assert_eq!(g.angle, before.angle, "the placement stays");
assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1, "one undo step");
assert_eq!(s.gradient_preset_name(&g.gradient).as_deref(), Some("Prism Veil"));
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(paint(&s, id, false), before);
}
/// A preset saved as "Mint Halo" before Holographic existed stays listed under a free name.
#[test]
fn a_saved_preset_named_like_a_holographic_glow_gets_a_free_name() {
let (mut s, id) = session_with(json!({"gradient": {"kind": "radial"}}));
let halo = s.gradient_preset("Mint Halo").unwrap().gradient;
let mut own = paint(&s, id, false).gradient;
own.dither = true;
let mut prefs = s.prefs.clone();
prefs.gradient_presets = vec![crate::cmd::GradientPreset { name: "MINT HALO".into(), gradient: own.clone() }];
s.apply_prefs(prefs);
assert_eq!(s.prefs.gradient_presets.iter().map(|p| p.name.as_str()).collect::<Vec<_>>(), ["MINT HALO 2"]);
s.execute("gradient.presets.apply", &json!({"name": "mint halo 2"})).unwrap();
assert_eq!(paint(&s, id, false).gradient, own);
s.execute("gradient.presets.apply", &json!({"name": "Mint Halo"})).unwrap();
assert_eq!(paint(&s, id, false).gradient.stops, halo.stops);
}
#[test]
fn a_preset_applies_to_the_stroke_and_to_a_solid_paint() {
let (mut s, id) = session_with(json!({"color": "#336699"}));
+38
View File
@@ -671,6 +671,44 @@ fn organic_fades_add_with_their_method_midpoints_and_opacities_in_rgb_and_cmyk()
}
}
#[test]
fn holographic_glows_add_whole_in_rgb_and_cmyk_as_one_undo_step() {
let lib = vectorcraft_color::libraries::builtin_library("holographic").unwrap();
let Paint::Gradient(want) = &lib.swatch("Mint Halo").unwrap().paint else { panic!("Mint Halo is a gradient") };
for mode in ["rgb", "cmyk"] {
let mut s = Session::new();
run(&mut s, "file.new", json!({"width": 100, "height": 100, "colorMode": mode}));
let list = run(&mut s, "swatch.library.list", json!({}));
let row = list["libraries"].as_array().unwrap().iter().find(|l| l["id"] == "holographic").unwrap().clone();
assert_eq!((row["name"].as_str(), row["category"].as_str(), row["count"].as_u64()), (Some("Holographic"), Some("gradients"), Some(14)));
let got = run(&mut s, "swatch.library.get", json!({"library": "holographic"}));
assert!(got.to_string().contains("Mint Halo"), "{mode}: get lists Mint Halo");
let id = run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 50}))["id"].clone();
let node = vectorcraft_doc::NodeId(id.as_u64().unwrap());
let before = undo_len(&s);
let r = run(&mut s, "swatch.library.add", json!({"library": "holographic", "names": ["Mint Halo"], "apply": "fill"}));
assert_eq!((r["added"].clone(), r["applied"].clone()), (json!(["Mint Halo"]), json!("Mint Halo")), "{mode}");
assert_eq!(undo_len(&s), before + 1, "{mode}: added and applied as one step");
// The swatch comes as the library has it: kind, stops (RGB colors, opacities, midpoints) and method.
let Paint::Gradient(added) = &doc(&s).swatch("Mint Halo").unwrap().paint else { panic!("{mode}: a gradient swatch") };
assert_eq!(added.gradient, want.gradient, "{mode}");
assert!(added.gradient.stops.iter().all(|st| matches!(st.color, Color::Rgb { .. })), "{mode}: the stops stay RGB");
assert_eq!(added.gradient.stops.last().map(|st| st.opacity), Some(0.0), "{mode}: clear at the edge");
let Paint::Gradient(fill) = doc(&s).node(node).unwrap().appearance.fill_paint() else { panic!("{mode}: a gradient fill") };
assert_eq!((fill.gradient.kind, fill.gradient.method), (want.gradient.kind, want.gradient.method), "{mode}");
assert_eq!(fill.gradient.stops, want.gradient.stops, "{mode}");
run(&mut s, "edit.undo", json!({}));
assert!(doc(&s).swatch("Mint Halo").is_none(), "{mode}: undo removes the add");
assert!(!matches!(doc(&s).node(node).unwrap().appearance.fill_paint(), Paint::Gradient(_)), "{mode}: and the fill");
// A document swatch already named Mint Halo stays; the glow comes in under a number.
run(&mut s, "swatch.new", json!({"name": "Mint Halo", "color": "#123456"}));
let r = run(&mut s, "swatch.library.add", json!({"library": "holographic", "names": ["Mint Halo"]}));
assert_eq!(r["added"], json!(["Mint Halo 2"]), "{mode}");
assert!(doc(&s).swatch("Mint Halo").unwrap().paint.color().is_some(), "{mode}: the document's swatch is kept");
assert!(matches!(&doc(&s).swatch("Mint Halo 2").unwrap().paint, Paint::Gradient(g) if g.gradient == want.gradient));
}
}
#[test]
fn pattern_libraries_bring_their_patterns_and_add_each_once() {
let mut s = session();