@@ -55,6 +55,35 @@ export const colorValidator = z
5555 message : "Enter a valid hex colour code." ,
5656 } )
5757
58+ /** Gradient picker colours: in-progress # + hex, complete values, or legacy hex without #. */
59+ export const gradientPickerColorValidator = z
60+ . string ( )
61+ . superRefine ( ( val , ctx ) => {
62+ if ( val === "" ) {
63+ ctx . addIssue ( {
64+ code : z . ZodIssueCode . custom ,
65+ message : "Enter a valid hex colour code." ,
66+ } )
67+ return
68+ }
69+ if ( / ^ # [ 0 - 9 A - F a - f ] { 0 , 8 } $ / . test ( val ) ) {
70+ const hex = val . slice ( 1 )
71+ if ( hex . length === 0 ) return
72+ if ( [ 1 , 2 , 4 , 5 , 7 ] . includes ( hex . length ) ) return
73+ if ( colorValidator . safeParse ( val ) . success ) return
74+ ctx . addIssue ( {
75+ code : z . ZodIssueCode . custom ,
76+ message : "Enter a valid hex colour code." ,
77+ } )
78+ return
79+ }
80+ if ( colorValidator . safeParse ( val ) . success ) return
81+ ctx . addIssue ( {
82+ code : z . ZodIssueCode . custom ,
83+ message : "Enter a valid hex colour code." ,
84+ } )
85+ } )
86+
5887const aspectRatioValueValidator = z
5988 . string ( )
6089 . regex ( / ^ \d + ( \. \d { 1 , 2 } ) ? - \d + ( \. \d { 1 , 2 } ) ? $ / )
0 commit comments