@winput/utils
v1.0.11
Published
Utility functions for winput - color conversion, geometry helpers
Maintainers
Readme
@winput/utils 🛠️
Color conversion and geometry utilities.
Requirements
- OS: Windows 64-bit
- Runtime: Bun (npm not supported)
Installation
bun add @winput/utilsUsage
import { utils } from "@winput/utils";
const hex = utils.rgbToHex({ r: 255, g: 128, b: 0 }); // "#FF8000"
const rgb = utils.hexToRgb("#FF8000"); // { r: 255, g: 128, b: 0 }
const similar = utils.isColorSimilar(
{ r: 255, g: 0, b: 0 },
{ r: 250, g: 10, b: 5 },
20
); // true
const inside = utils.pointInRect(
{ x: 150, y: 150 },
{ left: 100, top: 100, right: 200, bottom: 200 }
); // trueAPI
utils
| Method | Params | Returns | Description |
| ----------------------------------- | -------------------------------------- | ------------- | ------------------ |
| rgbToHex(rgb) | RGB | string | RGB to hex string |
| hexToRgb(hex) | string | RGB | Hex to RGB |
| rgbToHsv(r, g, b) | number, number, number | HSV | RGB to HSV |
| hsvToRgb(h, s, v) | number, number, number | RGB | HSV to RGB |
| colorDistance(c1, c2) | RGB, RGB | number | Distance (0-441) |
| isColorSimilar(c1, c2, tolerance) | RGB, RGB, number | boolean | Check similarity |
| pointInRect(point, rect) | Point, Rect | boolean | Point in rectangle |
Types
RGB
{
r: number;
g: number;
b: number;
}HSV
{
h: number;
s: number;
v: number;
}Point
{
x: number;
y: number;
}Rect
{
left: number;
top: number;
right: number;
bottom: number;
}Exports
| Export | Type | Description |
| ------- | ----------------- | ---------------------- |
| utils | Utils | Main utility functions |
| RGB | RGB | RGB color structure |
| HSV | HSV | HSV color structure |
