From: Nick Bowler Date: Tue, 10 May 2022 03:35:57 +0000 (-0400) Subject: Automatically adjust colour scheme for "dark mode". X-Git-Url: https://git.draconx.ca/gitweb/homepage.git/commitdiff_plain/062c731462e3ec513b470308cc2dd475098ce231 Automatically adjust colour scheme for "dark mode". Playing around a bit, let's try to respect "dark" mode in firefox and support automatically switching colour scheme accordingly. We convert all colour references in the stylesheet to new SASS mixins that will generate rules to adapt to the correct colour scheme. The selection is done using CSS variables that should gracefully degrade to the original (light) colours. --- diff --git a/Rules b/Rules index 365e83a..b8538d8 100644 --- a/Rules +++ b/Rules @@ -210,7 +210,7 @@ compile '/images/*.jpg', rep: :info do end compile '/**/*.scss' do - filter :sass, syntax: :scss + filter :sass, syntax: :scss, load_paths: ["."] filter :css_source, uribase: \ "https://git.draconx.ca/gitweb/homepage.git/blob/" + @item[:gitrev] + ":" diff --git a/content/style.scss b/content/style.scss index d53717d..5f2ef96 100644 --- a/content/style.scss +++ b/content/style.scss @@ -17,22 +17,23 @@ * along with this program. If not, see . */ -// colour definitions -$backgroundcolour: #ffffff; -$foregroundcolour: #000000; +@import "lib/colourmap.scss"; -$linkdefaultcolour: #0000cd; -$linkactivecolour: #ff0000; -$linkvisitedcolour: #800080; +@include defcolours + ( $background: #ffffff #000000 + , $foreground: #000000 #ffffff -$ruledefaultcolour: #d3d3d3; -$rulestrongcolour: #696969; + , $linkdefault: #0000cd #a3aaff + , $linkactive: #ff0000 + , $linkvisited: #800080 #e493f7 + , $focusring: #628cb2 -$annotationcolour: #708090; + , $annotation: #708090 + , $tableshade: #f5f5f5 #101010 -$tableshadecolour: #f5f5f5; - -$focusringcolour: #628cb2; + , $ruledefault: #d3d3d3 #494949 + , $rulestrong: #696969 #939393 + ); @mixin header_size($maxwidth, $fontsize) { font-size: $fontsize; @@ -40,19 +41,28 @@ $focusringcolour: #628cb2; } body { - background-color: $backgroundcolour; - color: $foregroundcolour; font-family: sans-serif; margin: 1em; + + @include usecolours + ( $background-color: background + , $color: foreground + ); } -a:link { color: $linkdefaultcolour; border-color: $linkdefaultcolour; } -a:visited { color: $linkvisitedcolour; border-color: $linkvisitedcolour; } -a:active { color: $linkactivecolour; border-color: $linkactivecolour; } +a:link { + @include usecolours($color: linkdefault, $border-color: linkdefault); +} +a:visited { + @include usecolours($color: linkvisited, $border-color: linkvisited); +} +a:active { + @include usecolours($color: linkactive, $border-color: linkactive); +} @supports (outline-style: auto) { a:link { border-width: 0; } - a:focus { outline: auto $focusringcolour; } + a:focus { @include usecolour(outline, focusring, auto); } li, td, dt { &>a:link { border: solid 1px transparent; } } } @@ -88,7 +98,7 @@ p.img { } small { - color: $foregroundcolour; + @include usecolours($color: foreground); text-align: justify; @media (max-width: 24em) { text-align: left; } padding: 0.5ex; @@ -123,7 +133,7 @@ hr { clear: both; margin: 0.5em 0; border: 0; - border-top: 1px solid $ruledefaultcolour; + @include usecolour(border-top, ruledefault, 1px solid); } kbd { @@ -141,16 +151,17 @@ kbd { } .permalink { + @include usecolours($color: annotation); font-size: small; - color: $annotationcolour; a:link, a:visited { color: inherit; } + a:active { @include usecolours($color: linkactive); } @media not screen { visibility: hidden; } } // General table styles. table { - border: 1px solid $ruledefaultcolour; + @include usecolour(border-top, ruledefault, 1px solid); border-collapse: collapse; width: 100%; } @@ -171,18 +182,20 @@ td, th { margin: 0; } -thead>tr, tbody>tr { border: solid $ruledefaultcolour; } -th, thead>tr { border-bottom: 1px solid $rulestrongcolour; } -tbody+tbody { border-bottom: 1px solid $ruledefaultcolour; } +thead>tr, tbody>tr { @include usecolour(border, ruledefault, solid); } +th, thead>tr { @include usecolour(border-bottom, rulestrong, 1px solid); } +tbody+tbody { @include usecolour(border-bottom, ruledefault, 1px solid); } *>table, *>th { border: none; } thead>tr { border-width: 1px; } tbody>tr { border-width: 0 1px; } -td + td { box-shadow: -1px 0 $backgroundcolour; } +td + td { + @include usecolour(box-shadow, background, -1px 0); +} tbody>tr { - &:nth-of-type(even) { background-color: $tableshadecolour; } - &:last-child { border-bottom: solid 1px $ruledefaultcolour; } + &:nth-of-type(even) { @include usecolours($background-color: tableshade); } + &:last-child { @include usecolour(border-bottom, ruledefault, solid 1px); } } // Specific table styles @@ -313,10 +326,10 @@ $clickynames: name, date, size; #{"input.clicky-#{$col+$focuslabel}"}>span:first-child , #{"input.clicky-#{$col}-rev#{$focuslabel}"} .svg { - border-color: $foregroundcolour; + @include usecolours($border-color: foreground); @at-root { @supports (outline-style: auto) { & { + @include usecolour(outline, focusring, auto); border-color: transparent; - outline: auto $focusringcolour; }}} } } @@ -340,12 +353,12 @@ thead.clicky label { padding-right: 2px; } - &:active { color: $linkactivecolour; } + &:active { @include usecolours($color: linkactive); } &:first-child:active>span, &~label:active>.svg { - border-color: $linkactivecolour; + @include usecolours($border-color: linkactive); @at-root { @supports (outline-style: auto) { & { + @include usecolour(outline, focusring, auto); border-color: transparent; - outline: auto $focusringcolour; }}} } @@ -414,7 +427,7 @@ table.filelist { } } -#footer p { color: $annotationcolour; } +#footer p { @include usecolours($color: annotation); } #article-info p { font-style: italic; } .wbr:after { content: "\200b"; } @@ -440,3 +453,18 @@ ul.ordered > { #sitetitle * { float: none; } #footer { padding: 0 1em; } } + +// page-specific dark mode styles +@media (min-width: 35em) { + #page_weblog_responsive_tables { + @each $tN in t6 t7 t8 { + ##{$tN}>tbody>tr.#{$tN}-split { + @include usecolour_var_(border-bottom, ruledefault); + + &:nth-of-type(odd) ~ tr:nth-of-type(odd) { + @include usecolour_var_(background-color, tableshade); + } + } + } + } +} diff --git a/content/weblog/responsive-tables.md b/content/weblog/responsive-tables.md index 2063484..a668e16 100644 --- a/content/weblog/responsive-tables.md +++ b/content/weblog/responsive-tables.md @@ -272,12 +272,12 @@ are pretty easy to fix in the stylesheet. #t6>thead, #t6>tbody { display: grid; } #t6>tbody>tr.t6-split { border-bottom: 1px solid <%= - scss_get_var(:ruledefaultcolour) %>; } + scss_get_colour(:ruledefault) %>; } #t6>tbody>tr.t6-split:nth-of-type(odd) ~ tr:nth-of-type(even) { background-color: initial; } #t6>tbody>tr.t6-split:nth-of-type(odd) ~ tr:nth-of-type(odd) { - background-color: <%= scss_get_var(:tableshadecolour) %>; + background-color: <%= scss_get_colour(:tableshade) %>; } } } @@ -325,12 +325,12 @@ these techniques to [table 1](#t1). #t7>thead, #t7>tbody { display: grid; } #t7>tbody>tr.t7-split { border-bottom: 1px solid <%= - scss_get_var(:ruledefaultcolour) %>; } + scss_get_colour(:ruledefault) %>; } #t7>tbody>tr.t7-split:nth-of-type(odd) ~ tr:nth-of-type(even) { background-color: initial; } #t7>tbody>tr.t7-split:nth-of-type(odd) ~ tr:nth-of-type(odd) { - background-color: <%= scss_get_var(:tableshadecolour) %>; + background-color: <%= scss_get_colour(:tableshade) %>; } } } @@ -386,12 +386,12 @@ in a stylesheet. We will do it with more grids. #t8>thead, #t8>tbody { display: grid; } #t8>tbody>tr.t8-split { border-bottom: 1px solid <%= - scss_get_var(:ruledefaultcolour) %>; } + scss_get_colour(:ruledefault) %>; } #t8>tbody>tr.t8-split:nth-of-type(odd) ~ tr:nth-of-type(even) { background-color: initial; } #t8>tbody>tr.t8-split:nth-of-type(odd) ~ tr:nth-of-type(odd) { - background-color: <%= scss_get_var(:tableshadecolour) %>; + background-color: <%= scss_get_colour(:tableshade) %>; } } diff --git a/layouts/default.xml b/layouts/default.xml index 2e003ae..11aeec1 100644 --- a/layouts/default.xml +++ b/layouts/default.xml @@ -2,7 +2,7 @@