11import * as v from "valibot" ;
22
33import { formatValidationError , safeParse } from "@core/schemas" ;
4+ import { ensureNonNullable } from "@core/utils/assertions/ensureNonNullable" ;
45import { ValidationError } from "@core/utils/errors/ValidationError" ;
56
67import {
@@ -26,15 +27,41 @@ export const exportConfigSchema = v.pipe(
2627 v . object ( { name : levelNameSchema , contrast : baseContrastSchema , chroma : levelChromaSchema } ) ,
2728 ) ,
2829 hues : v . array ( v . object ( { name : hueNameSchema , angle : hueAngleSchema } ) ) ,
29- settings : v . object ( {
30- contrastModel : contrastModelSchema ,
31- directionMode : directionModeSchema ,
32- chromaMode : chromaModeSchema ,
33- bgLightStart : bgRightStartSchema ,
34- bgColorLight : colorStringSchema ,
35- bgColorDark : colorStringSchema ,
36- colorSpace : colorSpaceSchema ,
37- } ) ,
30+ settings : v . pipe (
31+ v . object ( {
32+ contrastModel : contrastModelSchema ,
33+ directionMode : directionModeSchema ,
34+ chromaMode : chromaModeSchema ,
35+ bgRightStart : v . optional ( bgRightStartSchema ) ,
36+ bgColorRight : v . optional ( colorStringSchema ) ,
37+ bgColorLeft : v . optional ( colorStringSchema ) ,
38+ colorSpace : colorSpaceSchema ,
39+ // Migration for old properties
40+ bgLightStart : v . optional ( bgRightStartSchema ) ,
41+ bgColorDark : v . optional ( colorStringSchema ) ,
42+ bgColorLight : v . optional ( colorStringSchema ) ,
43+ } ) ,
44+ v . transform ( ( parsed ) => {
45+ return {
46+ contrastModel : parsed . contrastModel ,
47+ directionMode : parsed . directionMode ,
48+ chromaMode : parsed . chromaMode ,
49+ bgRightStart : ensureNonNullable (
50+ parsed . bgRightStart ?? parsed . bgLightStart ,
51+ "At least one of properties must present in the config: 'bgRightStart' or 'bgLightStart'" ,
52+ ) ,
53+ bgColorRight : ensureNonNullable (
54+ parsed . bgColorRight ?? parsed . bgColorLight ,
55+ "At least one of properties must present in the config: 'bgColorRight' or 'bgColorLight'" ,
56+ ) ,
57+ bgColorLeft : ensureNonNullable (
58+ parsed . bgColorLeft ?? parsed . bgColorDark ,
59+ "At least one of properties must present in the config: 'bgColorLeft' or 'bgColorDark'" ,
60+ ) ,
61+ colorSpace : parsed . colorSpace ,
62+ } ;
63+ } ) ,
64+ ) ,
3865 } ) ,
3966 v . check ( ( { levels, settings } ) => {
4067 return levels . every (
@@ -100,9 +127,9 @@ export function toCompactExportConfig(config: ExportConfig): CompactExportConfig
100127 config . settings . contrastModel ,
101128 config . settings . directionMode ,
102129 config . settings . chromaMode ,
103- config . settings . bgColorLight ,
104- config . settings . bgColorDark ,
105- config . settings . bgLightStart ,
130+ config . settings . bgColorRight ,
131+ config . settings . bgColorLeft ,
132+ config . settings . bgRightStart ,
106133 config . settings . colorSpace ,
107134 ] ,
108135 ] ;
@@ -135,9 +162,9 @@ export function toExportConfig(compactConfig: CompactExportConfig): ExportConfig
135162 contrastModel,
136163 directionMode : compactConfig [ 2 ] [ 1 ] ,
137164 chromaMode : compactConfig [ 2 ] [ 2 ] ,
138- bgColorLight : compactConfig [ 2 ] [ 3 ] ,
139- bgColorDark : compactConfig [ 2 ] [ 4 ] ,
140- bgLightStart : compactConfig [ 2 ] [ 5 ] ,
165+ bgColorRight : compactConfig [ 2 ] [ 3 ] ,
166+ bgColorLeft : compactConfig [ 2 ] [ 4 ] ,
167+ bgRightStart : compactConfig [ 2 ] [ 5 ] ,
141168 colorSpace : compactConfig [ 2 ] [ 6 ] ,
142169 } ,
143170 } ;
0 commit comments