dark-mode-css ( classes -- classes' )


Vocabulary
help.html

Inputs
classesan object


Outputs
classes'an object


Definition


: dark-mode-css ( classes -- classes' )
{
""
"/* Dark mode */"
"@media (prefers-color-scheme:dark) {"
} swap [
R/ {[^}]+}/ [
"{" ?head drop "}" ?tail drop ";" split
[ [ blank? ] trim ] map harvest [ ";" append ] map
[ R/ (#[0-9a-fA-F]+|white|black);/ re-contains? ]
filter [
R/ (#[0-9a-fA-F]+|white|black);/ [
>string H{
{ "#e3e2db;" "#444444;" }
{ "transparent;" "transparent;" }
{ "#d5d5d5;" "#666;" }
{ "white;" "#202124;" }
{ "black;" "white;" }
{ "#333333;" "#d5d5d5;" }
{ "#2a5db0;" "#8ab4f8;" }
{ "#373e48;" "#ffffff;" }
{ "#8b4500;" "orange;" }
{ "#000000;" "#bdc1c6;" }
} ?at [
but-last parse-color inverse-color
color>hex ";" append
] unless
] re-replace-with
] map " " join "{ " " }" surround
] re-replace-with " " prepend dup "{ }" subseq-of?
[ drop f ] when
] map harvest append "}" suffix ;