mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-10 11:13:48 +02:00
Start on plugin ctx API (#64)
This commit is contained in:
@@ -104,6 +104,15 @@ export class YaakColor {
|
||||
return rgbaToHex(r, g, b, a);
|
||||
}
|
||||
|
||||
hexNoAlpha(): string {
|
||||
const h = this.hue;
|
||||
const s = this.saturation;
|
||||
const l = this.lightness;
|
||||
|
||||
const [r, g, b] = parseColor(`hsl(${h},${s}%,${l}%)`).rgb;
|
||||
return rgbaToHexNoAlpha(r, g, b);
|
||||
}
|
||||
|
||||
private _lighten(mod: number): YaakColor {
|
||||
const c = this.clone();
|
||||
c.lightness = this.lightness + (100 - this.lightness) * mod;
|
||||
@@ -125,6 +134,14 @@ function rgbaToHex(r: number, g: number, b: number, a: number): string {
|
||||
return '#' + [toHex(r), toHex(g), toHex(b), toHex(a * 255)].join('').toUpperCase();
|
||||
}
|
||||
|
||||
function rgbaToHexNoAlpha(r: number, g: number, b: number): string {
|
||||
const toHex = (n: number): string => {
|
||||
const hex = Number(Math.round(n)).toString(16);
|
||||
return hex.length === 1 ? `0${hex}` : hex;
|
||||
};
|
||||
return '#' + [toHex(r), toHex(g), toHex(b)].join('').toUpperCase();
|
||||
}
|
||||
|
||||
function hexToRgba(hex: string): [number, number, number, number] {
|
||||
const fromHex = (h: string): number => {
|
||||
if (h === '') return 255;
|
||||
|
||||
Reference in New Issue
Block a user