fix: sanitize customScale in getZoomScale and fix isCustomActive styling

This commit is contained in:
makaradam
2026-05-02 11:05:48 +02:00
parent 37215531c2
commit f30090bf88
2 changed files with 11 additions and 4 deletions
@@ -473,6 +473,9 @@ export function SettingsPanel({
);
const zoomEnabled = Boolean(selectedZoomDepth);
const isCustomActive =
selectedZoomCustomScale != null &&
!Object.values(ZOOM_DEPTH_SCALES).some((s) => s === selectedZoomCustomScale);
const trimEnabled = Boolean(selectedTrimId);
const handleDeleteClick = () => {
@@ -644,7 +647,7 @@ export function SettingsPanel({
<span
className={cn(
"text-xs font-mono font-semibold tabular-nums",
selectedZoomCustomScale != null ? "text-[#34B27B]" : "text-slate-400",
isCustomActive ? "text-[#34B27B]" : "text-slate-400",
)}
>
{(
@@ -675,7 +678,7 @@ export function SettingsPanel({
<SliderPrimitive.Range
className={cn(
"absolute h-full transition-colors duration-150",
selectedZoomCustomScale != null ? "bg-[#34B27B]" : "bg-white/20",
isCustomActive ? "bg-[#34B27B]" : "bg-white/20",
)}
/>
</SliderPrimitive.Track>
@@ -684,7 +687,7 @@ export function SettingsPanel({
"block h-3.5 w-3.5 rounded-full border-2 shadow transition-all duration-150",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#34B27B]/50",
"disabled:pointer-events-none disabled:opacity-50 cursor-grab active:cursor-grabbing",
selectedZoomCustomScale != null
isCustomActive
? "border-[#34B27B] bg-[#34B27B] shadow-[0_0_6px_rgba(52,178,123,0.4)]"
: "border-white/20 bg-[#2a2a30] hover:border-white/40",
)}
+5 -1
View File
@@ -365,7 +365,11 @@ export const DEFAULT_ZOOM_DEPTH: ZoomDepth = 3;
/** Returns the effective zoom scale for a region, preferring customScale over the preset. */
export function getZoomScale(region: ZoomRegion): number {
return region.customScale ?? ZOOM_DEPTH_SCALES[region.depth];
if (region.customScale != null) {
const clamped = Math.max(MIN_ZOOM_SCALE, Math.min(MAX_ZOOM_SCALE, region.customScale));
if (Number.isFinite(clamped)) return clamped;
}
return ZOOM_DEPTH_SCALES[region.depth];
}
export function clampFocusToDepth(focus: ZoomFocus, _depth: ZoomDepth): ZoomFocus {