Integration: #826 grey stops keep their value (model form); a stale ramp drag can't index past the stops

This commit is contained in:
aiongg
2026-10-13 19:26:54 +00:00
parent da8aaa9cdc
commit ba95ae2dae
2 changed files with 69 additions and 31 deletions
+1 -5
View File
@@ -188,7 +188,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Gradient",
[],
None,
"{kind?: linear|radial, stops?: [{location: 0–100, color: \"#rrggbb\"|{c,m,y,k}|{gray}|[r,g,b] | swatch: name (its colour, as dropped on the Gradient panel), opacity?: 0–100, midpoint?: 13–87}], reverse?: bool, angle?: degrees, from?: [x,y], to?: [x,y] (spread coords: the Gradient Swatch tool's drag), ids?} → {swatch, kind, stops} — edits the fill's gradient (an unnamed gradient unless it equals a gradient swatch)",
"{kind?: linear|radial, stops?: [{location: 0–100, color: \"#rrggbb\"|{c,m,y,k}(0..100)|[r,g,b](0..255)|{model: rgb|cmyk|gray, …}(0..1) | swatch: name (its colour, as dropped on the Gradient panel), opacity?: 0–100, midpoint?: 13–87}], reverse?: bool, angle?: degrees, from?: [x,y], to?: [x,y] (spread coords: the Gradient Swatch tool's drag), ids?} → {swatch, kind, stops} — edits the fill's gradient (an unnamed gradient unless it equals a gradient swatch)",
super::has_selection,
apply_gradient
),
@@ -1006,10 +1006,6 @@ pub fn parse_color(v: &Value) -> Option<designcraft_color::Color> {
return Some(Color::gray(if gray > 1.0 { gray / 100.0 } else { gray } as f32));
}
let g = |k: &str| o.get(k).and_then(Value::as_f64);
// {gray: 0–100} is a grey with that much black.
if let Some(k) = g("gray") {
return Some(Color::gray((k.clamp(0.0, 100.0) / 100.0) as f32));
}
let v = [g("c")?, g("m")?, g("y")?, g("k")?];
let scale = if v.iter().any(|&x| x > 1.0) { 100.0 } else { 1.0 };
Some(Color::cmyk((v[0] / scale) as f32, (v[1] / scale) as f32, (v[2] / scale) as f32, (v[3] / scale) as f32))