diff --git a/assets/scss/code.scss b/assets/scss/code.scss index 0f0f1d8..1f48096 100644 --- a/assets/scss/code.scss +++ b/assets/scss/code.scss @@ -1,21 +1,5 @@ @import "variables.scss"; -$code-color-lineno: grey; - -:root { - --code-color-keyword: black; - --code-color-type: black; - --code-color-comment: grey; -} - -@media (prefers-color-scheme: dark) { - :root { - --code-color-keyword: #{darken(white, 40%)}; - --code-color-type: #{darken(white, 40%)}; - --code-color-comment: grey; - } -} - .highlight-label { padding: 0.25rem 0.5rem 0.25rem 0.5rem; border: $code-border; @@ -32,7 +16,7 @@ $code-color-lineno: grey; code { font-family: $font-code; - background-color: var(--code-color); + @include var(background-color, code-color); border: $code-border; padding: 0 0.25rem 0 0.25rem; } @@ -48,7 +32,7 @@ pre code { .lntable { border-spacing: 0; padding: 0.5rem 0 0.5rem 0; - background-color: var(--code-color); + @include var(background-color, code-color); border-radius: 0; border: $code-border; display: block; @@ -80,7 +64,7 @@ pre code { .lnt { display: block; padding: 0 1rem 0 1rem; - color: $code-color-lineno; + color: $code-lineno-color; } .hl { @@ -95,14 +79,14 @@ pre code { .kr, .k { font-weight: bold; - color: var(--code-color-keyword); + @include var(color, code-keyword-color); } .kt { font-weight: bold; - color: var(--code-color-type); + @include var(color, code-type-color); } .c, .c1 { - color: var(--code-color-comment); + color: $code-comment-color; } diff --git a/assets/scss/margin.scss b/assets/scss/margin.scss index a626928..981c593 100644 --- a/assets/scss/margin.scss +++ b/assets/scss/margin.scss @@ -1,10 +1,6 @@ @import "variables.scss"; @import "mixins.scss"; -$margin-width: 30rem; -$margin-inner-offset: 0.5rem; -$margin-outer-offset: 1rem; - @mixin below-two-margins { @media screen and (max-width: $container-width-threshold + diff --git a/assets/scss/modes.scss b/assets/scss/modes.scss new file mode 100644 index 0000000..b6adcd6 --- /dev/null +++ b/assets/scss/modes.scss @@ -0,0 +1,21 @@ +:root { + @each $varName, $varDefault in $css-vars { + --#{$varName}: #{$varDefault}; + } +} + +@media (prefers-color-scheme: dark) { + :root { + --background-color: #{$background-color-dark}; + --text-color: white; + + --warning-background-color: #{$warning-background-color-dark}; + --warning-border-color: #{$warning-border-color-dark}; + + --target-background-color: #{$target-background-color-dark}; + + --code-color: #{$code-color-dark}; + --code-keyword-color: #{$code-token-color-dark}; + --code-type-color: #{$code-token-color-dark}; + } +} diff --git a/assets/scss/sidenotes.scss b/assets/scss/sidenotes.scss index 7939998..5bcc2ba 100644 --- a/assets/scss/sidenotes.scss +++ b/assets/scss/sidenotes.scss @@ -2,9 +2,6 @@ @import "mixins.scss"; @import "margin.scss"; -$sidenote-padding: 1rem; -$sidenote-highlight-border-width: .2rem; - .sidenote { &:hover { .sidenote-label { diff --git a/assets/scss/style.scss b/assets/scss/style.scss index b22cf9b..820f0f2 100755 --- a/assets/scss/style.scss +++ b/assets/scss/style.scss @@ -1,10 +1,11 @@ @import "variables.scss"; @import "mixins.scss"; @import "toc.scss"; +@import "modes.scss"; body { - background-color: var(--background-color); - color: var(--text-color); + @include var(background-color, background-color); + @include var(color, text-color); font-family: $font-body; font-size: 1.0rem; line-height: 1.5; @@ -24,7 +25,7 @@ h1, h2, h3, h4, h5, h6 { text-align: center; &:target { - background-color: var(--target-background-color); + @include var(background-color, target-background-color); border-radius: 1rem; } @@ -90,7 +91,7 @@ nav { a { padding: 0.25rem 0.75rem 0.25rem .75rem; text-decoration: none; - color: var(--text-color); + @include var(color, text-color); display: inline-block; border-bottom: none; white-space: nowrap; @@ -130,7 +131,7 @@ h6 { } a { - color: var(--text-color); + @include var(color, text-color); text-decoration: none; border-bottom: .2rem solid $primary-color; transition: color 0.25s; @@ -272,8 +273,8 @@ figure { .warning { @include bordered-block; padding: 0.5rem; - background-color: var(--warning-background-color); - border-color: var(--warning-border-color); + @include var(background-color, warning-background-color); + @include var(border-color, warning-border-color); } .feather { diff --git a/assets/scss/toc.scss b/assets/scss/toc.scss index 70ba4c7..38f48ae 100644 --- a/assets/scss/toc.scss +++ b/assets/scss/toc.scss @@ -2,8 +2,6 @@ @import "mixins.scss"; @import "margin.scss"; -$toc-border-color: $code-border-color; - .table-of-contents { @include margin-content; @include margin-content-left; @@ -45,7 +43,7 @@ $toc-border-color: $code-border-color; div.wrapper { @include bordered-block; padding: 1rem; - background-color: var(--code-color); + @include var(background-color, code-color); border-color: $toc-border-color; box-sizing: border-box; max-width: 100%; diff --git a/assets/scss/variables.scss b/assets/scss/variables.scss index 0241e03..fd4c91f 100644 --- a/assets/scss/variables.scss +++ b/assets/scss/variables.scss @@ -1,15 +1,13 @@ $container-width: 45rem; $container-min-padding: 1rem; $container-width-threshold: $container-width + 2 * $container-min-padding; -$standard-border-width: .075rem; $primary-color: #36e281; $border-color: #bfbfbf; $background-color: white; $background-color-dark: #1b1d1f; -$code-color: #f0f0f0; -$code-color-dark: lighten($background-color-dark, 10%); -$code-border-color: darken($code-color, 10%); +$standard-border-width: .075rem; +$standard-border: $standard-border-width solid $border-color; $font-heading: "Lora", serif; $font-body: "Raleway", serif; @@ -23,25 +21,40 @@ $warning-border-color-dark: $warning-background-color; $target-background-color: lighten(yellow, 30%); $target-background-color-dark: #55511c; -$standard-border: $standard-border-width solid $border-color; +$code-color: #f0f0f0; +$code-color-dark: lighten($background-color-dark, 10%); +$code-token-color: black; +$code-token-color-dark: darken(white, 40%); +$code-border-color: darken($code-color, 10%); +$code-lineno-color: grey; +$code-comment-color: grey; $code-border: $standard-border-width solid $code-border-color; -:root { - --background-color: #{$background-color}; - --text-color: black; - --code-color: #{$code-color}; - --warning-background-color: #{$warning-background-color}; - --warning-border-color: #{$warning-border-color}; - --target-background-color: #{$target-background-color}; -} +$sidenote-padding: 1rem; +$sidenote-highlight-border-width: .2rem; -@media (prefers-color-scheme: dark) { - :root { - --background-color: #{$background-color-dark}; - --text-color: white; - --code-color: #{$code-color-dark}; - --warning-background-color: #{$warning-background-color-dark}; - --warning-border-color: #{$warning-border-color-dark}; - --target-background-color: #{$target-background-color-dark}; - } +$margin-width: 30rem; +$margin-inner-offset: 0.5rem; +$margin-outer-offset: 1rem; + +$toc-border-color: $code-border-color; + +// Default values for CSS variables for fallback. +$css-vars: ( + background-color: $background-color, + text-color: black, + + warning-background-color: $warning-background-color, + warning-border-color: $warning-border-color, + + target-background-color: $target-background-color, + + code-color: $code-color, + code-keyword-color: $code-token-color, + code-type-color: $code-token-color, +); + +@mixin var($property, $varName) { + #{$property}: map-get($css-vars, $varName); + #{$property}: var(--#{$varName}); }