feat: add slider field

This commit is contained in:
2026-08-23 05:18:10 +05:00
parent 7e391a420b
commit 3701fc8045
6 changed files with 123 additions and 11 deletions
+12 -1
View File
@@ -1,7 +1,18 @@
import { describe, expect, it } from 'vitest';
import { brightnessContrast, grayscale, invert } from './color';
import { brightnessContrast, grayscale, invert, rgbToHex } from './color';
import { makeImage } from './test-helpers';
describe('rgbToHex', () => {
it('форматирует базовые цвета', () => {
expect(rgbToHex(255, 0, 0)).toBe('#ff0000');
expect(rgbToHex(1, 2, 3)).toBe('#010203');
});
it('округляет дробные значения и клампит диапазон', () => {
expect(rgbToHex(127.6, -5, 300)).toBe('#8000ff');
});
});
describe('grayscale', () => {
it('считает luma по весам BT.601 с округлением', () => {
const out = grayscale(
+5
View File
@@ -42,6 +42,11 @@ export function brightnessContrast(
return out;
}
export function rgbToHex(r: number, g: number, b: number): string {
const byte = (v: number) => clamp(Math.round(v), 0, 255).toString(16).padStart(2, '0');
return `#${byte(r)}${byte(g)}${byte(b)}`;
}
function clamp(value: number, min: number, max: number): number {
return Math.min(max, Math.max(min, value));
}