This repository was archived by the owner on Jul 26, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +33
-2
lines changed Expand file tree Collapse file tree 1 file changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,38 @@ import { getOutputImage } from '../utils/getOutputImage';
4
4
5
5
import * as greyAlgorithms from './greyAlgorithms' ;
6
6
7
- export type GreyAlgorithms = keyof typeof greyAlgorithms ;
7
+ export const GreyAlgorithm = {
8
+ LUMA_709 : 'luma709' ,
9
+ LUMA_601 : 'luma601' ,
10
+ MAX : 'max' ,
11
+ MIN : 'min' ,
12
+ AVERAGE : 'average' ,
13
+ MINMAX : 'minmax' ,
14
+ RED : 'red' ,
15
+ GREEN : 'green' ,
16
+ BLUE : 'blue' ,
17
+ BLACK : 'black' ,
18
+ CYAN : 'cyan' ,
19
+ MAGENTA : 'magenta' ,
20
+ YELLOW : 'yellow' ,
21
+ HUE : 'hue' ,
22
+ SATURATION : 'saturation' ,
23
+ LIGHTNESS : 'lightness' ,
24
+ } as const satisfies Record < string , keyof typeof greyAlgorithms > ;
25
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
26
+ export type GreyAlgorithm = ( typeof GreyAlgorithm ) [ keyof typeof GreyAlgorithm ] ;
27
+
28
+ {
29
+ // Check that all the algorithms are in the enum.
30
+ const algos = new Set < string > ( Object . values ( GreyAlgorithm ) ) ;
31
+ for ( const algo of Object . keys ( greyAlgorithms ) ) {
32
+ if ( ! algos . has ( algo ) ) {
33
+ throw new Error (
34
+ `Grey algorithm ${ algo } is missing in the GreyAlgorithm enum` ,
35
+ ) ;
36
+ }
37
+ }
38
+ }
8
39
9
40
/**
10
41
* Call back that converts the RGB channels to grey. It is clamped afterwards.
@@ -28,7 +59,7 @@ export interface GreyOptions {
28
59
*
29
60
* @default 'luma709'
30
61
*/
31
- algorithm ?: GreyAlgorithms | GreyAlgorithmCallback ;
62
+ algorithm ?: GreyAlgorithm | GreyAlgorithmCallback ;
32
63
/**
33
64
* Specify wether to keep an alpha channel in the new image or not.
34
65
*
You can’t perform that action at this time.
0 commit comments