Skip to content

Commit 33533b8

Browse files
committed
chore: Update SRGB type definitions to include prefix for color space conflicts
1 parent a169e6e commit 33533b8

File tree

7 files changed

+38
-29
lines changed

7 files changed

+38
-29
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
if: steps.npm-version.outputs.SHOULD_PUBLISH == 'true'
5454
run: |
5555
NEW_VERSION=${{ steps.package-version.outputs.current-version }}
56-
sed -n "/## \[$NEW_VERSION\]/,/## \[/p" CHANGELOG.md | sed '$d' > RELEASE_CHANGELOG.md
56+
sed -n "/## \[$NEW_VERSION\]/,/## \[/p" CHANGELOG.md | sed '$d' > RELEASE_NOTES.md
5757
5858
- name: Create GitHub Release
5959
if: steps.npm-version.outputs.SHOULD_PUBLISH == 'true'
@@ -63,6 +63,6 @@ jobs:
6363
with:
6464
name: Release ${{ steps.package-version.outputs.current-version }}
6565
tag_name: v${{ steps.package-version.outputs.current-version }}
66-
files: RELEASE_CHANGELOG.md
66+
body_path: RELEASE_NOTES.md
6767
draft: false
6868
prerelease: false

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
## [Unreleased]
1010

11-
## [1.3.0] - 2024-07-12
11+
## [1.3.1] - 2024-07-17
12+
13+
### Changed
14+
15+
- Updated SRGB type definitions to include prefix to avoid conflicts with other color spaces
16+
17+
## [1.3.0] - 2024-07-17
1218

1319
## BIG UPDATE 🎉
1420

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "color-core",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "A comprehensive color manipulation library for Next.js and React applications",
55
"author": "Tariel Davidashvili <[email protected]> (http://tariel.me/)",
66
"license": "MIT",
@@ -121,4 +121,4 @@
121121
}
122122
],
123123
"packageManager": "[email protected]"
124-
}
124+
}

src/color.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
adobeRGBToRGB, cieLuvToRgb, ciexyyToRgb, cmykToRgb, hexToRgb, hpluvToRgb, hsiToRgb, hslToRgb, hsluvToRgb, hsvToRgb, hwbToRgb, labToRgb, lchToRgb, oklabToRgb, oklchToRgb, rgbToAdobeRGB, rgbToCIELuv, rgbToCIExyY, rgbToCmyk, rgbToHex, rgbToHPLuv, rgbToHsi, rgbToHsl, rgbToHSLuv, rgbToHsv, rgbToHwb, rgbToLab, rgbToLabD50, rgbToLch, rgbToOklab, rgbToOklch, rgbToSrgb, rgbToXyz, rgbToXyzD50, rgbToYuv,
3+
srgbToRgb,
34
xyzToRgb, yuvToRgb
45
} from './conversions';
56
import {
@@ -32,12 +33,14 @@ export class Color {
3233
* Creates a new Color instance.
3334
* @param color - The color value to initialize with. Can be a string (hex) or an object representing various color spaces.
3435
*/
35-
constructor(color: string | RGB | HSL | HSV | CMYK | LAB | LCH | LUV | XYZ | YUV | Oklab | Oklch | HSLuv | HPLuv | CIExyY | HSI | HWB | AdobeRGB) {
36+
constructor(color: string | RGB | SRGB | HSL | HSV | CMYK | LAB | LCH | LUV | XYZ | YUV | Oklab | Oklch | HSLuv | HPLuv | CIExyY | HSI | HWB | AdobeRGB) {
3637
if (typeof color === 'string') {
3738
this._rgb = hexToRgb(color);
3839

3940
} else if ('r' in color && 'g' in color && 'b' in color) {
4041
this._rgb = { ...color, a: color.a ?? 1 };
42+
} else if ('sr' in color && 'sg' in color && 'sb' in color) {
43+
this._rgb = srgbToRgb(color as SRGB);
4144
} else if ('x' in color && 'y' in color && 'z' in color) {
4245
this._rgb = xyzToRgb(color as XYZ);
4346
} else if ('l' in color && 'a' in color && 'b' in color) {

src/conversions/components/__tests__/srgb.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { rgbToSrgb, srgbToRgb } from '../srgb';
44
describe('sRGB <-> RGB Conversions', () => {
55
describe('rgbToSrgb', () => {
66
it('should convert RGB to sRGB correctly', () => {
7-
expect(rgbToSrgb({ r: 255, g: 0, b: 0 })).toEqual({ r: 1, g: 0, b: 0 });
8-
expect(rgbToSrgb({ r: 0, g: 255, b: 0 })).toEqual({ r: 0, g: 1, b: 0 });
9-
expect(rgbToSrgb({ r: 0, g: 0, b: 255 })).toEqual({ r: 0, g: 0, b: 1 });
10-
expect(rgbToSrgb({ r: 255, g: 255, b: 255 })).toEqual({ r: 1, g: 1, b: 1 });
11-
expect(rgbToSrgb({ r: 0, g: 0, b: 0 })).toEqual({ r: 0, g: 0, b: 0 });
7+
expect(rgbToSrgb({ r: 255, g: 0, b: 0 })).toEqual({ sr: 1, sg: 0, sb: 0 });
8+
expect(rgbToSrgb({ r: 0, g: 255, b: 0 })).toEqual({ sr: 0, sg: 1, sb: 0 });
9+
expect(rgbToSrgb({ r: 0, g: 0, b: 255 })).toEqual({ sr: 0, sg: 0, sb: 1 });
10+
expect(rgbToSrgb({ r: 255, g: 255, b: 255 })).toEqual({ sr: 1, sg: 1, sb: 1 });
11+
expect(rgbToSrgb({ r: 0, g: 0, b: 0 })).toEqual({ sr: 0, sg: 0, sb: 0 });
1212
});
1313

1414
it('should throw error for invalid input', () => {
@@ -20,17 +20,17 @@ describe('sRGB <-> RGB Conversions', () => {
2020

2121
describe('srgbToRgb', () => {
2222
it('should convert sRGB to RGB correctly', () => {
23-
expect(srgbToRgb({ r: 1, g: 0, b: 0 })).toEqual({ r: 255, g: 0, b: 0 });
24-
expect(srgbToRgb({ r: 0, g: 1, b: 0 })).toEqual({ r: 0, g: 255, b: 0 });
25-
expect(srgbToRgb({ r: 0, g: 0, b: 1 })).toEqual({ r: 0, g: 0, b: 255 });
26-
expect(srgbToRgb({ r: 1, g: 1, b: 1 })).toEqual({ r: 255, g: 255, b: 255 });
27-
expect(srgbToRgb({ r: 0, g: 0, b: 0 })).toEqual({ r: 0, g: 0, b: 0 });
23+
expect(srgbToRgb({ sr: 1, sg: 0, sb: 0 })).toEqual({ r: 255, g: 0, b: 0 });
24+
expect(srgbToRgb({ sr: 0, sg: 1, sb: 0 })).toEqual({ r: 0, g: 255, b: 0 });
25+
expect(srgbToRgb({ sr: 0, sg: 0, sb: 1 })).toEqual({ r: 0, g: 0, b: 255 });
26+
expect(srgbToRgb({ sr: 1, sg: 1, sb: 1 })).toEqual({ r: 255, g: 255, b: 255 });
27+
expect(srgbToRgb({ sr: 0, sg: 0, sb: 0 })).toEqual({ r: 0, g: 0, b: 0 });
2828
});
2929

3030
it('should throw error for invalid input', () => {
3131
expect(() => srgbToRgb(123 as any)).toThrow('Input must be an object');
3232
expect(() => srgbToRgb({ r: 'invalid', g: 0, b: 0 } as any)).toThrow('sRGB values must be numbers');
33-
expect(() => srgbToRgb({ r: -1, g: 0, b: 0 })).toThrow('sRGB values must be between 0 and 1');
33+
expect(() => srgbToRgb({ sr: -1, sg: 0, sb: 0 })).toThrow('sRGB values must be between 0 and 1');
3434
});
3535
});
3636

src/conversions/components/srgb.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export function rgbToSrgb(rgb: RGB): SRGB {
3030
const gammaCorrect = (c: number) => (c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4));
3131

3232
return {
33-
r: gammaCorrect(rNorm),
34-
g: gammaCorrect(gNorm),
35-
b: gammaCorrect(bNorm),
33+
sr: gammaCorrect(rNorm),
34+
sg: gammaCorrect(gNorm),
35+
sb: gammaCorrect(bNorm),
3636
};
3737
}
3838

@@ -47,22 +47,22 @@ export function srgbToRgb(srgb: SRGB): RGB {
4747
throw new Error('Input must be an object');
4848
}
4949

50-
const { r, g, b } = srgb;
50+
const { sr, sg, sb } = srgb;
5151

52-
if (typeof r !== 'number' || typeof g !== 'number' || typeof b !== 'number') {
52+
if (typeof sr !== 'number' || typeof sg !== 'number' || typeof sb !== 'number') {
5353
throw new Error('sRGB values must be numbers');
5454
}
5555

56-
if (r < 0 || r > 1 || g < 0 || g > 1 || b < 0 || b > 1) {
56+
if (sr < 0 || sr > 1 || sg < 0 || sg > 1 || sb < 0 || sb > 1) {
5757
throw new Error('sRGB values must be between 0 and 1');
5858
}
5959

6060
// Apply inverse gamma correction
6161
const inverseGammaCorrect = (c: number) => (c <= 0.0031308 ? 12.92 * c : 1.055 * Math.pow(c, 1 / 2.4) - 0.055);
6262

6363
return {
64-
r: Math.round(inverseGammaCorrect(r) * 255),
65-
g: Math.round(inverseGammaCorrect(g) * 255),
66-
b: Math.round(inverseGammaCorrect(b) * 255),
64+
r: Math.round(inverseGammaCorrect(sr) * 255),
65+
g: Math.round(inverseGammaCorrect(sg) * 255),
66+
b: Math.round(inverseGammaCorrect(sb) * 255),
6767
};
6868
}

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ export type CIExyY = {
187187
* Values are typically between 0 and 255.
188188
*/
189189
export type SRGB = {
190-
r: number;
191-
g: number;
192-
b: number;
190+
sr: number;
191+
sg: number;
192+
sb: number;
193193
};
194194

195195
/**

0 commit comments

Comments
 (0)