Skip to content

Commit

Permalink
refactor(color): rename color matrix fns
Browse files Browse the repository at this point in the history
BREAKING CHANGE: rename color matrix fns

- add `Mat` suffix, e.g. `grayscale()` => `grayscaleMat()`
  • Loading branch information
postspectacular committed Jan 3, 2022
1 parent 22057e5 commit 00fdc31
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/color/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const IDENTITY: ColorMatrix = [
* @param src - source color
*/
// prettier-ignore
export const subtract = (src: ReadonlyColor = WHITE): ColorMatrix => [
export const subtractMat = (src: ReadonlyColor = WHITE): ColorMatrix => [
-1, 0, 0, 0, src[0],
0, -1, 0, 0, src[1],
0, 0, -1, 0, src[2],
Expand All @@ -80,39 +80,39 @@ export const subtract = (src: ReadonlyColor = WHITE): ColorMatrix => [
* @param x - brightness offset
*/
// prettier-ignore
export const brightness = (x: number): ColorMatrix => [
export const brightnessMat = (x: number): ColorMatrix => [
1, 0, 0, 0, x,
0, 1, 0, 0, x,
0, 0, 1, 0, x,
0, 0, 0, 1, 0
];

// prettier-ignore
export const contrast = (x: number, o = 0.5 * (1 - x)): ColorMatrix => [
export const contrastMat = (x: number, o = 0.5 * (1 - x)): ColorMatrix => [
x, 0, 0, 0, o,
0, x, 0, 0, o,
0, 0, x, 0, o,
0, 0, 0, 1, 0
];

// prettier-ignore
export const exposure = (x: number): ColorMatrix => [
export const exposureMat = (x: number): ColorMatrix => [
x, 0, 0, 0, 0,
0, x, 0, 0, 0,
0, 0, x, 0, 0,
0, 0, 0, 1, 0
];

// prettier-ignore
export const saturation = (x: number): ColorMatrix => [
export const saturationMat = (x: number): ColorMatrix => [
S1 + S4 * x, S3 - S3 * x, S0 - S0 * x, 0, 0,
S1 - S1 * x, S3 + S2 * x, S0 - S0 * x, 0, 0,
S1 - S1 * x, S3 - S3 * x, S0 + S5 * x, 0, 0,
0, 0, 0, 1, 0
];

// prettier-ignore
export const hueRotate = (theta: number): ColorMatrix => {
export const hueRotateMat = (theta: number): ColorMatrix => {
const s = Math.sin(theta);
const c = Math.cos(theta);
return [
Expand All @@ -124,23 +124,23 @@ export const hueRotate = (theta: number): ColorMatrix => {
};

// prettier-ignore
export const temperature = (x: number): ColorMatrix => [
export const temperatureMat = (x: number): ColorMatrix => [
1 + x, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1 - x, 0, 0,
0, 0, 0, 1, 0
];

// prettier-ignore
export const sepia = (x = 1): ColorMatrix => [
export const sepiaMat = (x = 1): ColorMatrix => [
mix(1, 0.393, x), 0.769 * x, 0.189 * x, 0, 0,
0.349 * x, mix(1, 0.686, x), 0.168 * x, 0, 0,
0.272 * x, 0.534 * x, mix(1, 0.131, x), 0, 0,
0, 0, 0, 1, 0
];

// prettier-ignore
export const tint = (x: number): ColorMatrix => [
export const tintMat = (x: number): ColorMatrix => [
1 + x, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1 + x, 0, 0,
Expand All @@ -158,7 +158,7 @@ export const tint = (x: number): ColorMatrix => [
* @param offset - brightness offset
*/
// prettier-ignore
export const grayscale = ([r, g, b] = RGB_LUMINANCE_REC709, offset = 0): ColorMatrix => [
export const grayscaleMat = ([r, g, b] = RGB_LUMINANCE_REC709, offset = 0): ColorMatrix => [
r, g, b, 0, offset,
r, g, b, 0, offset,
r, g, b, 0, offset,
Expand All @@ -176,7 +176,7 @@ export const grayscale = ([r, g, b] = RGB_LUMINANCE_REC709, offset = 0): ColorMa
* @param coeffs - luminance coefficients
*/
// prettier-ignore
export const luminanceAlpha = ([r, g, b] = RGB_LUMINANCE_REC709): ColorMatrix => [
export const luminanceAlphaMat = ([r, g, b] = RGB_LUMINANCE_REC709): ColorMatrix => [
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
Expand Down

0 comments on commit 00fdc31

Please sign in to comment.