feat(ui): change inputnumber to snap to values when alt is pressed
Some checks failed
🚀 Lint & Test & Deploy / release (push) Has been cancelled

This commit is contained in:
2026-02-06 15:44:24 +01:00
parent 6acce72fb8
commit de1f9d6ab6

View File

@@ -26,11 +26,18 @@
return Math.min(max, Math.max(min, v)); return Math.min(max, Math.max(min, v));
} }
function snap(v: number) { function snap(v: number, s = step) {
if (step) v = Math.round(v / step) * step; if (s) v = Math.round(v / s) * s;
return +v.toFixed(3); return +v.toFixed(3);
} }
function getAutoStep(v: number): number {
const abs = Math.abs(v);
if (abs === 0) return 0.1; // fallback for 0
const exponent = Math.floor(Math.log10(abs));
return Math.pow(10, exponent);
}
let dragging = $state(false); let dragging = $state(false);
let startValue = 0; let startValue = 0;
let rect: DOMRect; let rect: DOMRect;
@@ -58,7 +65,8 @@
value = snap( value = snap(
e.ctrlKey e.ctrlKey
? startValue + delta ? startValue + delta
: clamp(startValue + delta) : clamp(startValue + delta),
(e.altKey && !step) ? getAutoStep(value) : step
); );
} }
@@ -129,7 +137,7 @@
<div <div
class="absolute inset-y-0 left-0 bg-layer-3 opacity-30 pointer-events-none transition-[width]" class="absolute inset-y-0 left-0 bg-layer-3 opacity-30 pointer-events-none transition-[width]"
class:transition-none={dragging} class:transition-none={dragging}
style={`width: ${Math.min((value - min) / (max - min), 1) * 100}%`} style={`width: ${Math.max(0, Math.min((value - min) / (max - min), 1) * 100)}%`}
> >
</div> </div>