Skip to content

Commit 309fa20

Browse files
committed
fix double stop regression
1 parent 13dc181 commit 309fa20

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/components/Presets.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@
296296
kind: 'stop',
297297
color: stop.color,
298298
auto: null,
299-
position1: stop.position1 || null,
300-
position2: stop.position2 || null,
299+
position1: (stop.position1 ?? null),
300+
position2: (stop.position2 ?? null),
301301
}
302302
}
303303
else return stop

src/utils/gradientString.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ function stopsToStrings(stops: any[], { convert_colors, new_lines }: { convert_c
9595
let p1 = s.position1
9696
let p2 = s.position2
9797

98-
// If position equals computed auto position, omit it
99-
if (p1 != null && s.auto != null && p1 == s.auto) p1 = null
100-
if (p2 != null && s.auto != null && p2 == s.auto) p2 = null
98+
// If first position equals computed auto position, omit it (keep explicit second positions)
99+
if (p1 != null && s.auto != null && String(p1) == String(s.auto)) p1 = null
101100

102101
// Omit default endpoints
103102
if (i === firstStopIdx && isPctZero(p1)) p1 = null

src/utils/stops.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,36 @@ export function updateStops(stops) {
33

44
let updated = stops.map((stop, i) => {
55
let autoVal = autoStops[i]
6-
6+
77
if (stop.kind == 'stop') {
88
if (stops.length === 1) {
9+
// For a single color stop, span the entire line
910
stop.position1 = 0
10-
stop.position2 = 100
11+
stop.position2 = 100
1112
}
12-
else if (!stop._manual && (!stop.position1 || stop.position1 === stop.auto)) {
13-
stop.position1 = autoVal
14-
stop.position2 = autoVal
13+
else if (!stop._manual) {
14+
// Treat null/undefined as unset; 0 is a valid value and must be preserved
15+
const p1Unset = (stop.position1 == null) || (stop.auto != null && String(stop.position1) == String(stop.auto))
16+
const p2UnsetOrAuto = (stop.position2 == null) || (stop.auto != null && String(stop.position2) == String(stop.auto))
17+
18+
// Only assign auto for position1 when it is unset or previously auto-managed
19+
if (p1Unset) stop.position1 = autoVal
20+
21+
// Only assign auto for position2 when it's unset or previously auto-managed.
22+
// Preserve any explicitly provided second position (e.g., from presets) to avoid regressions.
23+
if (p2UnsetOrAuto) stop.position2 = p1Unset ? autoVal : stop.position1
1524
}
1625
// Clear the manual flag after one normalization pass so future edits behave normally
1726
if (stop._manual) delete stop._manual
1827
}
1928
// is a hint
2029
else {
21-
if (!stop.percentage || stop.percentage === stop.auto)
30+
// Only auto-assign hint percentage when it's unset or previously auto-managed
31+
if (stop.percentage == null || (stop.auto != null && String(stop.percentage) == String(stop.auto)))
2232
stop.percentage = autoVal
2333
}
2434

35+
// Persist the computed auto value for future comparisons
2536
stop.auto = autoVal
2637
return stop
2738
})

0 commit comments

Comments
 (0)