From 37c976499ead51c1d88e8e8213366240a72adebc Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Wed, 2 Aug 2023 05:18:35 +0800 Subject: [PATCH] perf(ui): improve web accessibility (#447) - Make color and contrast meets WCAG 2 AA and above - Fixes `aria-label` on button "copy link" in posts --- _includes/post-sharing.html | 8 ++-- _javascript/modules/components/clipboard.js | 10 ++++- _sass/addon/commons.scss | 18 +++++---- _sass/addon/module.scss | 7 +++- _sass/addon/syntax.scss | 1 + _sass/colors/dark-syntax.scss | 36 ++++++++--------- _sass/colors/dark-typography.scss | 10 ++--- _sass/colors/light-syntax.scss | 45 +++++++++++---------- _sass/colors/light-typography.scss | 14 +++---- _sass/layout/post.scss | 31 +++++++------- 10 files changed, 96 insertions(+), 84 deletions(-) diff --git a/_includes/post-sharing.html b/_includes/post-sharing.html index f607ba2..4085270 100644 --- a/_includes/post-sharing.html +++ b/_includes/post-sharing.html @@ -22,14 +22,16 @@ {% endfor %} - - + + diff --git a/_javascript/modules/components/clipboard.js b/_javascript/modules/components/clipboard.js index f803843..f4634cf 100644 --- a/_javascript/modules/components/clipboard.js +++ b/_javascript/modules/components/clipboard.js @@ -99,7 +99,9 @@ export function initClipboard() { /* --- Post link sharing --- */ - $('#copy-link').on('click', (e) => { + const btnCopyLink = $('#copy-link'); + + btnCopyLink.on('click', (e) => { let target = $(e.target); if (isLocked(target)) { @@ -120,4 +122,10 @@ export function initClipboard() { }, TIMEOUT); }); }); + + btnCopyLink.on('mouseleave', function (e) { + const target = $(e.target); + target.tooltip('hide'); + console.log('mouse leave...'); + }); } diff --git a/_sass/addon/commons.scss b/_sass/addon/commons.scss index 86b4899..fd2dfde 100644 --- a/_sass/addon/commons.scss +++ b/_sass/addon/commons.scss @@ -176,6 +176,8 @@ footer { font-size: 0.8rem; background-color: var(--main-bg); + @extend %text-color; + div.d-flex { height: $footer-height; line-height: 1.2rem; @@ -185,7 +187,7 @@ footer { } a { - @extend %text-color; + @extend %text-highlight; &:hover { @extend %link-hover; @@ -243,7 +245,6 @@ i { .post-tag { line-height: 1.05rem; font-size: 0.85rem; - border: 1px solid var(--btn-border-color); border-radius: 0.8rem; padding: 0.3rem 0.5rem; margin: 0 0.35rem 0.5rem 0; @@ -494,9 +495,10 @@ i { display: inline-block; min-width: 2rem; text-align: center; - border-radius: 0.3rem; + border-radius: 0.5rem; + border: 1px solid var(--btn-border-color); padding: 0 0.4rem; - color: inherit; + color: var(--text-muted-color); line-height: 1.3rem; &:not(:last-child) { @@ -745,19 +747,20 @@ $btn-mb: 0.5rem; font-size: 1.75rem; line-height: 1.2; letter-spacing: 0.25px; - color: rgba(134, 133, 133, 0.99); margin-top: 1.25rem; margin-bottom: 0.5rem; a { @extend %clickable-transition; @extend %sidebar-link-hover; + + color: var(--site-title-color); } } .site-subtitle { font-size: 95%; - color: var(--sidebar-muted-color); + color: var(--site-subtitle-color); margin-top: 0.25rem; word-spacing: 1px; -webkit-user-select: none; @@ -915,7 +918,7 @@ $btn-mb: 0.5rem; #breadcrumb { font-size: 1rem; - color: gray; + color: var(--text-muted-color); padding-left: 0.5rem; a:hover { @@ -1102,7 +1105,6 @@ $btn-mb: 0.5rem; /* --- main wrapper --- */ #main-wrapper { - background-color: var(--main-bg); position: relative; min-height: calc(100vh - $footer-height-mobile); diff --git a/_sass/addon/module.scss b/_sass/addon/module.scss index 10e0d69..a7e5e06 100644 --- a/_sass/addon/module.scss +++ b/_sass/addon/module.scss @@ -107,7 +107,7 @@ } %sidebar-links { - color: rgba(117, 117, 117, 0.9); + color: var(--sidebar-muted-color); -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; @@ -122,6 +122,11 @@ -webkit-box-orient: vertical; } +%text-highlight { + color: inherit; + font-weight: 600; +} + /* ---------- scss mixin --------- */ @mixin mt-mb($value) { diff --git a/_sass/addon/syntax.scss b/_sass/addon/syntax.scss index df756a7..182b95f 100644 --- a/_sass/addon/syntax.scss +++ b/_sass/addon/syntax.scss @@ -63,6 +63,7 @@ html { font-size: $code-font-size; line-height: 1.4rem; word-wrap: normal; /* Fixed Safari overflow-x */ + color: var(--code-snippets-color); } table { diff --git a/_sass/colors/dark-syntax.scss b/_sass/colors/dark-syntax.scss index 36e9651..f14c520 100644 --- a/_sass/colors/dark-syntax.scss +++ b/_sass/colors/dark-syntax.scss @@ -5,44 +5,40 @@ @mixin dark-syntax { --language-border-color: rgba(84, 83, 83, 0.27); --highlight-bg-color: #252525; - --highlighter-rouge-color: #de6b18; - --highlight-lineno-color: #6c6c6d; + --highlighter-rouge-color: #ff6e4e; + --highlight-lineno-color: #666666; --inline-code-bg: #272822; --code-header-text-color: #6a6a6a; --code-header-muted-color: rgb(60, 60, 60); --code-header-icon-color: rgb(86, 86, 86); --clipboard-checked-color: #2bcc2b; - --filepath-text-color: #bdbdbd; - - /* override Bootstrap */ - pre { - color: #bfbfbf; - } + --filepath-text-color: #cacaca; + --code-snippets-color: #c2c2c2; .highlight .gp { - color: #818c96; + color: #87939d; } /* syntax highlight colors from https://raw.githubusercontent.com/jwarby/pygments-css/master/monokai.css */ .highlight pre { background-color: var(--highlight-bg-color); } .highlight .hll { background-color: var(--highlight-bg-color); } - .highlight .c { color: #75715e; } /* Comment */ + .highlight .c { color: #938d75; } /* Comment */ .highlight .err { color: #960050; background-color: #1e0010; } /* Error */ .highlight .k { color: #66d9ef; } /* Keyword */ .highlight .l { color: #ae81ff; } /* Literal */ .highlight .n { color: #f8f8f2; } /* Name */ - .highlight .o { color: #f92672; } /* Operator */ + .highlight .o { color: #ff329c; } /* Operator */ .highlight .p { color: #f8f8f2; } /* Punctuation */ - .highlight .cm { color: #75715e; } /* Comment.Multiline */ - .highlight .cp { color: #75715e; } /* Comment.Preproc */ - .highlight .c1 { color: #75715e; } /* Comment.Single */ - .highlight .cs { color: #75715e; } /* Comment.Special */ + .highlight .cm { color: #938d75; } /* Comment.Multiline */ + .highlight .cp { color: #938d75; } /* Comment.Preproc */ + .highlight .c1 { color: #938d75; } /* Comment.Single */ + .highlight .cs { color: #938d75; } /* Comment.Special */ .highlight .ge { color: inherit; font-style: italic; } /* Generic.Emph */ .highlight .gs { font-weight: bold; } /* Generic.Strong */ .highlight .kc { color: #66d9ef; } /* Keyword.Constant */ .highlight .kd { color: #66d9ef; } /* Keyword.Declaration */ - .highlight .kn { color: #f92672; } /* Keyword.Namespace */ + .highlight .kn { color: #ff329c; } /* Keyword.Namespace */ .highlight .kp { color: #66d9ef; } /* Keyword.Pseudo */ .highlight .kr { color: #66d9ef; } /* Keyword.Reserved */ .highlight .kt { color: #66d9ef; } /* Keyword.Type */ @@ -61,9 +57,9 @@ .highlight .nn { color: #f8f8f2; } /* Name.Namespace */ .highlight .nx { color: #a6e22e; } /* Name.Other */ .highlight .py { color: #f8f8f2; } /* Name.Property */ - .highlight .nt { color: #f92672; } /* Name.Tag */ + .highlight .nt { color: #ff329c; } /* Name.Tag */ .highlight .nv { color: #f8f8f2; } /* Name.Variable */ - .highlight .ow { color: #f92672; } /* Operator.Word */ + .highlight .ow { color: #ff329c; } /* Operator.Word */ .highlight .w { color: #f8f8f2; } /* Text.Whitespace */ .highlight .mf { color: #ae81ff; } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff; } /* Literal.Number.Hex */ @@ -85,7 +81,7 @@ .highlight .vg { color: #f8f8f2; } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2; } /* Name.Variable.Instance */ .highlight .il { color: #ae81ff; } /* Literal.Number.Integer.Long */ - .highlight .gu { color: #75715e; } /* Generic.Subheading & Diff Unified/Comment? */ - .highlight .gd { color: #f92672; background-color: #561c08; } /* Generic.Deleted & Diff Deleted */ + .highlight .gu { color: #938d75; } /* Generic.Subheading & Diff Unified/Comment? */ + .highlight .gd { color: #ff329c; background-color: #561c08; } /* Generic.Deleted & Diff Deleted */ .highlight .gi { color: #a6e22e; background-color: #0b5858; } /* Generic.Inserted & Diff Inserted */ } diff --git a/_sass/colors/dark-typography.scss b/_sass/colors/dark-typography.scss index 310828e..715fbd9 100644 --- a/_sass/colors/dark-typography.scss +++ b/_sass/colors/dark-typography.scss @@ -10,10 +10,11 @@ /* Common color */ --text-color: rgb(175, 176, 177); - --text-muted-color: rgb(107, 116, 124); + --text-muted-color: rgb(125, 136, 146); --heading-color: #cccccc; + --label-color: #a4a4c2; --blockquote-border-color: rgb(66, 66, 66); - --blockquote-text-color: rgb(117, 117, 117); + --blockquote-text-color: #868686; --link-color: rgb(138, 180, 248); --link-underline-color: rgb(82, 108, 150); --button-bg: rgb(39, 40, 43); @@ -22,7 +23,6 @@ --btn-backtotop-border-color: var(--btn-border-color); --btn-box-shadow: var(--main-bg); --card-header-bg: rgb(48, 48, 48); - --label-color: rgb(108, 117, 125); --checkbox-color: rgb(118, 120, 121); --checkbox-checked-color: var(--link-color); --img-bg: radial-gradient(circle, rgb(22, 22, 24) 0%, rgb(32, 32, 32) 100%); @@ -34,6 +34,8 @@ ); /* Sidebar */ + --site-title-color: #717070; + --site-subtitle-color: #6d6c6b; --sidebar-bg: radial-gradient(circle, #242424 0%, #1d1f27 100%); --sidebar-muted-color: #6d6c6b; --sidebar-active-color: rgb(255, 255, 255, 0.95); @@ -58,7 +60,6 @@ /* Posts */ --toc-highlight: rgb(116, 178, 243); - --tag-bg: rgb(41, 40, 40); --tag-hover: rgb(43, 56, 62); --tb-odd-bg: rgba(42, 47, 53, 0.52); /* odd rows of the posts' table */ --tb-even-bg: rgb(31, 31, 34); /* even rows of the posts' table */ @@ -66,7 +67,6 @@ --footnote-target-bg: rgb(63, 81, 181); --btn-share-color: #6c757d; --btn-share-hover-color: #bfc1ca; - --relate-post-date: var(--text-muted-color); --card-bg: #1e1e1e; --card-hovor-bg: #464d51; --card-shadow: rgb(21, 21, 21, 0.72) 0 6px 18px 0, diff --git a/_sass/colors/light-syntax.scss b/_sass/colors/light-syntax.scss index 040a5f5..e966312 100644 --- a/_sass/colors/light-syntax.scss +++ b/_sass/colors/light-syntax.scss @@ -3,22 +3,22 @@ */ @mixin light-syntax { - /* see: */ + /* based on: */ .highlight .hll { background-color: #ffffcc; } - .highlight .c { color: #999988; font-style: italic; } /* Comment */ + .highlight .c { color: #717165; font-style: italic; } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2; } /* Error */ .highlight .k { color: #000000; font-weight: bold; } /* Keyword */ .highlight .o { color: #000000; font-weight: bold; } /* Operator */ - .highlight .cm { color: #999988; font-style: italic; } /* Comment.Multiline */ - .highlight .cp { color: #999999; font-weight: bold; font-style: italic; } /* Comment.Preproc */ - .highlight .c1 { color: #999988; font-style: italic; } /* Comment.Single */ - .highlight .cs { color: #999999; font-weight: bold; font-style: italic; } /* Comment.Special */ + .highlight .cm { color: #717165; font-style: italic; } /* Comment.Multiline */ + .highlight .cp { color: #707070; font-style: italic; } /* Comment.Preproc */ + .highlight .c1 { color: #717165; font-style: italic; } /* Comment.Single */ + .highlight .cs { color: #707070; font-weight: bold; font-style: italic; } /* Comment.Special */ .highlight .gd { color: #d01040; background-color: #ffdddd; } /* Generic.Deleted */ .highlight .ge { color: #000000; font-style: italic; } /* Generic.Emph */ .highlight .gr { color: #aa0000; } /* Generic.Error */ - .highlight .gh { color: #999999; } /* Generic.Heading */ - .highlight .gi { color: #008080; background-color: #ddffdd; } /* Generic.Inserted */ - .highlight .go { color: #888888; } /* Generic.Output */ + .highlight .gh { color: #707070; } /* Generic.Heading */ + .highlight .gi { color: #005e5e; background-color: #ddffdd; } /* Generic.Inserted */ + .highlight .go { color: #707070; } /* Generic.Output */ .highlight .gp { color: #555555; } /* Generic.Prompt */ .highlight .gs { font-weight: bold; } /* Generic.Strong */ .highlight .gu { color: #aaaaaa; } /* Generic.Subheading */ @@ -31,10 +31,10 @@ .highlight .kt { color: #445588; font-weight: bold; } /* Keyword.Type */ .highlight .m { color: #009999; } /* Literal.Number */ .highlight .s { color: #d01040; } /* Literal.String */ - .highlight .na { color: #008080; } /* Name.Attribute */ - .highlight .nb { color: #0086b3; } /* Name.Builtin */ + .highlight .na { color: #005e5e; } /* Name.Attribute */ + .highlight .nb { color: #0078a1; } /* Name.Builtin */ .highlight .nc { color: #445588; font-weight: bold; } /* Name.Class */ - .highlight .no { color: #008080; } /* Name.Constant */ + .highlight .no { color: #005e5e; } /* Name.Constant */ .highlight .nd { color: #3c5d5d; font-weight: bold; } /* Name.Decorator */ .highlight .ni { color: #800080; } /* Name.Entity */ .highlight .ne { color: #990000; font-weight: bold; } /* Name.Exception */ @@ -42,7 +42,7 @@ .highlight .nl { color: #990000; font-weight: bold; } /* Name.Label */ .highlight .nn { color: #555555; } /* Name.Namespace */ .highlight .nt { color: #000080; } /* Name.Tag */ - .highlight .nv { color: #008080; } /* Name.Variable */ + .highlight .nv { color: #005e5e; } /* Name.Variable */ .highlight .ow { color: #000000; font-weight: bold; } /* Operator.Word */ .highlight .w { color: #bbbbbb; } /* Text.Whitespace */ .highlight .mf { color: #009999; } /* Literal.Number.Float */ @@ -60,22 +60,23 @@ .highlight .sr { color: #009926; } /* Literal.String.Regex */ .highlight .s1 { color: #d01040; } /* Literal.String.Single */ .highlight .ss { color: #990073; } /* Literal.String.Symbol */ - .highlight .bp { color: #999999; } /* Name.Builtin.Pseudo */ - .highlight .vc { color: #008080; } /* Name.Variable.Class */ - .highlight .vg { color: #008080; } /* Name.Variable.Global */ - .highlight .vi { color: #008080; } /* Name.Variable.Instance */ + .highlight .bp { color: #707070; } /* Name.Builtin.Pseudo */ + .highlight .vc { color: #005e5e; } /* Name.Variable.Class */ + .highlight .vg { color: #005e5e; } /* Name.Variable.Global */ + .highlight .vi { color: #005e5e; } /* Name.Variable.Instance */ .highlight .il { color: #009999; } /* Literal.Number.Integer.Long */ /* --- custom light colors --- */ --language-border-color: rgba(172, 169, 169, 0.2); - --highlight-bg-color: #f7f7f7; + --highlight-bg-color: #fcfcfc; --highlighter-rouge-color: #3f596f; - --highlight-lineno-color: #c2c6cc; + --highlight-lineno-color: #959595; --inline-code-bg: #f6f6f7; - --code-header-text-color: #a3a3b1; - --code-header-muted-color: #ebebeb; - --code-header-icon-color: #d1d1d1; + --code-header-text-color: #a3a3a3; + --code-header-muted-color: #e2e1e1; + --code-header-icon-color: #c9c8c8; --clipboard-checked-color: #43c743; + --code-snippets-color: #b01662; [class^='prompt-'] { --inline-code-bg: #fbfafa; diff --git a/_sass/colors/light-typography.scss b/_sass/colors/light-typography.scss index 9fc8162..07c31db 100644 --- a/_sass/colors/light-typography.scss +++ b/_sass/colors/light-typography.scss @@ -10,10 +10,11 @@ /* Common color */ --text-color: #34343c; - --text-muted-color: #8e8e8e; + --text-muted-color: #757575; --heading-color: black; + --label-color: #4d4d5b; --blockquote-border-color: #eeeeee; - --blockquote-text-color: #9a9a9a; + --blockquote-text-color: #757575; --link-color: #0153ab; --link-underline-color: #dee2e6; --button-bg: #ffffff; @@ -36,8 +37,10 @@ ); /* Sidebar */ + --site-title-color: rgb(113, 113, 113); + --site-subtitle-color: #717171; --sidebar-bg: #f6f8fa; - --sidebar-muted-color: #a2a19f; + --sidebar-muted-color: #545454; --sidebar-active-color: #1d1d1d; --sidebar-hover-bg: rgb(223, 233, 241, 0.64); --sidebar-btn-bg: white; @@ -60,16 +63,13 @@ --btn-text-color: #676666; /* Posts */ - --toc-highlight: #563d7c; + --toc-highlight: #47566c; --btn-share-hover-color: var(--link-color); --card-bg: white; --card-hovor-bg: #e2e2e2; --card-shadow: rgb(104, 104, 104, 0.05) 0 2px 6px 0, rgba(211, 209, 209, 0.15) 0 0 0 1px; - --label-color: #616161; - --relate-post-date: rgba(30, 55, 70, 0.4); --footnote-target-bg: lightcyan; - --tag-bg: rgba(0, 0, 0, 0.075); --tag-border: #dee2e6; --tag-shadow: var(--btn-border-color); --tag-hover: rgb(222, 226, 230); diff --git a/_sass/layout/post.scss b/_sass/layout/post.scss index 3d01b4d..15ea607 100644 --- a/_sass/layout/post.scss +++ b/_sass/layout/post.scss @@ -52,10 +52,10 @@ h1 + .post-meta { } em { - @extend %text-color; + color: var(--text-color); a { - @extend %text-color; + color: inherit; } } } @@ -73,7 +73,7 @@ h1 + .post-meta { line-height: 1.2rem; > a { - color: var(--text-color); + @extend %text-highlight; &:hover { @extend %link-hover; @@ -99,17 +99,20 @@ h1 + .post-meta { .share-icons { font-size: 1.2rem; - > i { - position: relative; - bottom: 1px; - - @extend %cursor-pointer; - - &:hover { + > *:hover { + i { @extend %btn-share-hovor; } } + button { + position: relative; + bottom: 2px; + padding: 0; + + @extend %cursor-pointer; + } + a { &:not(:last-child) { margin-right: 0.25rem; @@ -117,10 +120,6 @@ h1 + .post-meta { &:hover { text-decoration: none; - - > i { - @extend %btn-share-hovor; - } } } @@ -157,8 +156,6 @@ h1 + .post-meta { line-height: 2rem; .post-tag { - background: var(--tag-bg); - &:hover { @extend %link-hover; @extend %tag-hover; @@ -334,7 +331,7 @@ h1 + .post-meta { em { @extend %normal-font-style; - color: var(--relate-post-date); + color: var(--text-muted-color); } p {