99 ...
1010} : let
1111 cfg = config . stylix ;
12+ adjustLightness = rgbColorString : primaryScale : let
13+ stripped = builtins . replaceStrings [ "rgb(" ")" ] [ "" "" ] rgbColorString ;
14+ values = builtins . split "," stripped ;
15+ v1 = builtins . fromJSON ( builtins . elemAt values 0 ) ;
16+ v2 = builtins . fromJSON ( builtins . elemAt values 2 ) ;
17+ v3 = builtins . fromJSON ( builtins . elemAt values 4 ) ;
18+ preLightness = ( v1 + v2 + v3 ) / 3.0 ;
19+ adj = preLightness / 255.0 * ( 1.0 - primaryScale ) + primaryScale ;
20+ v1adj = lib . max ( lib . min ( v1 * adj ) 255.0 ) 0.0 ;
21+ v2adj = lib . max ( lib . min ( v2 * adj ) 255.0 ) 0.0 ;
22+ v3adj = lib . max ( lib . min ( v3 * adj ) 255.0 ) 0.0 ;
23+ round = x : let
24+ floored = builtins . floor x ;
25+ diff = x - floored ;
26+ in
27+ if diff >= 0.5
28+ then floored + 1
29+ else floored ;
30+ in
31+ builtins . toString ( lib . strings . fixedWidthString 2 "0" ( lib . toHexString ( round v1adj ) ) )
32+ + builtins . toString ( lib . strings . fixedWidthString 2 "0" ( lib . toHexString ( round v2adj ) ) )
33+ + builtins . toString ( lib . strings . fixedWidthString 2 "0" ( lib . toHexString ( round v3adj ) ) ) ;
1234in {
1335 options . stylix = {
1436 scheme = lib . mkOption {
4466 '' ;
4567 } ;
4668
69+ primaryScale = {
70+ dark = lib . mkOption {
71+ type = lib . types . float ;
72+ default = 0.0 ;
73+ description = ''
74+ Use this option to change the generated dark color scheme's contrast.
75+
76+ Value from -1 to 1. -1 represents minimum contrast,
77+ 0 represents standard (i.e. the design as spec'd),
78+ and 1 represents maximum contrast.
79+
80+ By default, 0 will be used.
81+ '' ;
82+ } ;
83+ light = lib . mkOption {
84+ type = lib . types . float ;
85+ default = 0.0 ;
86+ description = ''
87+ Use this option to change the generated light color scheme's contrast.
88+
89+ Value from -1 to 1. -1 represents minimum contrast,
90+ 0 represents standard (i.e. the design as spec'd),
91+ and 1 represents maximum contrast.
92+
93+ By default, 0 will be used.
94+ '' ;
95+ } ;
96+ } ;
97+
4798 polarity = lib . mkOption {
4899 type = lib . types . enum [
49- "either"
50100 "light"
51101 "dark"
52102 ] ;
53- default = "either " ;
103+ default = "dark " ;
54104 description = ''
55105 Use this option to force a light or dark theme.
56106
112162 default = let
113163 raw = pkgs . runCommand "raw-palette.json" { } ''
114164 ${ pkgs . matugen } /bin/matugen \
115- --json hex \
165+ --json rgb \
116166 --type ${ cfg . scheme } \
117167 --contrast ${ lib . strings . floatToString cfg . contrast } \
118168 --dry-run \
@@ -130,41 +180,41 @@ in {
130180 if cfg . polarity == "light"
131181 then
132182 pkgs . writeText "palette.json" ( builtins . toJSON {
133- base00 = builtins . substring 1 6 colors . surface_container_lowest ;
134- base01 = builtins . substring 1 6 colors . surface_container ;
135- base02 = builtins . substring 1 6 colors . surface_container_highest ;
136- base03 = builtins . substring 1 6 colors . outline ;
137- base04 = builtins . substring 1 6 colors . on_surface_variant ;
138- base05 = builtins . substring 1 6 colors . on_surface ;
139- base06 = builtins . substring 1 6 colors . surface_bright ;
140- base07 = builtins . substring 1 6 colors . on_primary_container ;
141- base08 = builtins . substring 1 6 colors . error ;
142- base09 = builtins . substring 1 6 colors . primary ;
143- base0A = builtins . substring 1 6 colors . secondary ;
144- base0B = builtins . substring 1 6 colors . tertiary ;
145- base0C = builtins . substring 1 6 colors . on_tertiary_fixed_variant ;
146- base0D = builtins . substring 1 6 colors . primary ;
147- base0E = builtins . substring 1 6 colors . on_tertiary_container ;
148- base0F = builtins . substring 1 6 colors . error_container ;
183+ base00 = adjustLightness colors . surface_container_lowest cfg . primaryScale . light ;
184+ base01 = adjustLightness colors . surface_container cfg . primaryScale . light ;
185+ base02 = adjustLightness colors . surface_container_highest cfg . primaryScale . light ;
186+ base03 = adjustLightness colors . outline cfg . primaryScale . light ;
187+ base04 = adjustLightness colors . on_surface_variant cfg . primaryScale . light ;
188+ base05 = adjustLightness colors . on_surface cfg . primaryScale . light ;
189+ base06 = adjustLightness colors . surface_bright cfg . primaryScale . light ;
190+ base07 = adjustLightness colors . on_primary_container cfg . primaryScale . light ;
191+ base08 = adjustLightness colors . error cfg . primaryScale . light ;
192+ base09 = adjustLightness colors . primary cfg . primaryScale . light ;
193+ base0A = adjustLightness colors . secondary cfg . primaryScale . light ;
194+ base0B = adjustLightness colors . tertiary cfg . primaryScale . light ;
195+ base0C = adjustLightness colors . on_tertiary_fixed_variant cfg . primaryScale . light ;
196+ base0D = adjustLightness colors . primary cfg . primaryScale . light ;
197+ base0E = adjustLightness colors . on_tertiary_container cfg . primaryScale . light ;
198+ base0F = adjustLightness colors . error_container cfg . primaryScale . light ;
149199 } )
150200 else
151201 pkgs . writeText "palette.json" ( builtins . toJSON {
152- base00 = builtins . substring 1 6 colors . background ;
153- base01 = builtins . substring 1 6 colors . surface_container ;
154- base02 = builtins . substring 1 6 colors . surface_container_highest ;
155- base03 = builtins . substring 1 6 colors . outline ;
156- base04 = builtins . substring 1 6 colors . on_surface_variant ;
157- base05 = builtins . substring 1 6 colors . on_surface ;
158- base06 = builtins . substring 1 6 colors . on_primary_fixed ;
159- base07 = builtins . substring 1 6 colors . on_primary_container ;
160- base08 = builtins . substring 1 6 colors . error ;
161- base09 = builtins . substring 1 6 colors . tertiary ;
162- base0A = builtins . substring 1 6 colors . secondary ;
163- base0B = builtins . substring 1 6 colors . primary ;
164- base0C = builtins . substring 1 6 colors . primary ;
165- base0D = builtins . substring 1 6 colors . primary_container ;
166- base0E = builtins . substring 1 6 colors . tertiary ;
167- base0F = builtins . substring 1 6 colors . error ;
202+ base00 = adjustLightness colors . background cfg . primaryScale . dark ;
203+ base01 = adjustLightness colors . surface_container cfg . primaryScale . dark ;
204+ base02 = adjustLightness colors . surface_container_highest cfg . primaryScale . dark ;
205+ base03 = adjustLightness colors . outline cfg . primaryScale . dark ;
206+ base04 = adjustLightness colors . on_surface_variant cfg . primaryScale . dark ;
207+ base05 = adjustLightness colors . on_surface cfg . primaryScale . dark ;
208+ base06 = adjustLightness colors . on_primary_fixed cfg . primaryScale . dark ;
209+ base07 = adjustLightness colors . on_primary_container cfg . primaryScale . dark ;
210+ base08 = adjustLightness colors . error cfg . primaryScale . dark ;
211+ base09 = adjustLightness colors . tertiary cfg . primaryScale . dark ;
212+ base0A = adjustLightness colors . secondary cfg . primaryScale . dark ;
213+ base0B = adjustLightness colors . primary cfg . primaryScale . dark ;
214+ base0C = adjustLightness colors . primary cfg . primaryScale . dark ;
215+ base0D = adjustLightness colors . primary_container cfg . primaryScale . dark ;
216+ base0E = adjustLightness colors . tertiary cfg . primaryScale . dark ;
217+ base0F = adjustLightness colors . error cfg . primaryScale . dark ;
168218 } ) ;
169219 } ;
170220
0 commit comments