Commit 0cf562a1 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Update highlights CSS to prepare for clustered-highlight styling

Refactor `highlights.scss` to configure highlight style and subsequently apply styles. Add CSS variables for use for dynamic styling of highlight clusters.

Update some comment wording in `gulpfile` for clarity.
parent f8f24706
...@@ -36,15 +36,12 @@ gulp.task('build-sidebar-tailwind-css', () => ...@@ -36,15 +36,12 @@ gulp.task('build-sidebar-tailwind-css', () =>
) )
); );
// These CSS source files should not use Tailwind, as they are used in
// third-party contexts.
// TODO: Remove `tailwindConfig` after updating `sass` task in `frontend-build`.
// Setting it is necessary currently to suppress a build warning.
gulp.task('build-standalone-css', () => gulp.task('build-standalone-css', () =>
buildCSS( buildCSS(
[ [
// other styles used by annotator (standalone) // styles processed by tailwind, used by annotator
'./src/styles/annotator/highlights.scss', './src/styles/annotator/highlights.scss',
// other styles used by annotator (standalone)
'./src/styles/annotator/pdfjs-overrides.scss', './src/styles/annotator/pdfjs-overrides.scss',
// Vendor // Vendor
......
$color-highlight: rgba(255, 255, 60, 0.4); :root {
$color-highlight-second: rgba(206, 206, 60, 0.4); // Default highlight styling configuration
$color-highlight-focused: rgba(156, 230, 255, 0.5); --hypothesis-highlight-color: rgba(255, 255, 60, 0.4);
--hypothesis-highlight-focused-color: rgba(156, 230, 255, 0.5);
// Hide content from sighted users but make it visible to screen readers. --hypothesis-highlight-blend-mode: normal;
// --hypothesis-highlight-decoration: none;
// Resources:
// - https://webaim.org/techniques/css/invisiblecontent/ (see "CSS clip") --hypothesis-highlight-second-color: rgba(206, 206, 60, 0.4);
// - https://cloudfour.com/thinks/see-no-evil-hidden-content-and-accessibility/#showing-additional-content-for-screen-readers --hypothesis-highlight-third-color: transparent;
// - https://tailwindcss.com/docs/screen-readers#screen-reader-only-elements Tailwind's `sr-only` class
@mixin screen-reader-only {
// Take the content out of the normal layout flow.
position: absolute;
width: 1px;
height: 1px;
white-space: nowrap;
// Visually hide the content and prevent it from interfering with mouse/touch
// text selection by clipping it to an empty box. Compared to moving content with
// `top`/`left` this is less likely to cause the browser to scroll to a
// different part of the page when the hidden text has screen-reader focus.
clip: rect(0 0 0 0);
overflow: hidden;
} }
// SVG highlights when the "Show Highlights" toggle is turned off. // Configure highlight styling.
// Map `--hypothesis-*` root values to local `--highlight-*` values
.hypothesis-svg-highlight { .hypothesis-svg-highlight {
fill: transparent; --highlight-color: var(--hypothesis-highlight-color);
--highlight-color-focused: var(--hypothesis-highlight-focused-color);
} }
// `hypothesis-highlights-always-on` is a class that is toggled on the root .hypothesis-highlight {
// of the annotated document when highlights are enabled/disabled. --highlight-color: var(--hypothesis-highlight-color);
.hypothesis-highlights-always-on { --highlight-blend-mode: var(--hypothesis-highlight-blend-mode);
.hypothesis-svg-highlight { --highlight-decoration: var(--hypothesis-highlight-decoration);
fill: $color-highlight; --highlight-color-focused: var(--hypothesis-highlight-focused-color);
&.is-opaque { & .hypothesis-highlight {
fill: yellow; --highlight-color: var(--hypothesis-highlight-second-color);
}
&.is-focused { .hypothesis-highlight {
fill: $color-highlight-focused; // Highlights more than two levels deep are transparent by default.
--highlight-color: var(--hypothesis-highlight-third-color);
} }
} }
}
.hypothesis-highlight { // Apply highlight styling.
background-color: $color-highlight;
// Highlights are non-visible when .hypothesis-highlight-always-on class not present.
.hypothesis-highlight {
background-color: transparent;
// For PDFs, we still create highlight elements to wrap the text but the // For PDFs, we still create highlight elements to wrap the text but the
// highlight effect is created by another element. // highlight effect is created by another element.
&.is-transparent { &.is-transparent {
background-color: transparent; background-color: transparent !important;
} }
}
.hypothesis-svg-highlight {
fill: transparent;
}
// Apply styling using `--highlight-` values when highlights are visible
.hypothesis-highlights-always-on .hypothesis-svg-highlight {
fill: var(--highlight-color);
&.is-opaque {
fill: yellow;
}
&.is-focused {
fill: var(--highlight-color-focused);
}
}
.hypothesis-highlights-always-on .hypothesis-highlight {
background-color: var(--highlight-color);
text-decoration: var(--highlight-decoration);
mix-blend-mode: var(--highlight-blend-mode);
cursor: pointer; cursor: pointer;
// Make highlights visible to screen readers. // Make highlights visible to screen readers.
// See also - https://developer.paciellogroup.com/blog/2017/12/short-note-on-making-your-mark-more-accessible/. // See also - https://developer.paciellogroup.com/blog/2017/12/short-note-on-making-your-mark-more-accessible/.
&::before { &::before {
@include screen-reader-only; @apply sr-only;
// nb. The leading/trailing spaces are intended to ensure the text is treated // nb. The leading/trailing spaces are intended to ensure the text is treated
// as separate words by assistive technologies from the content before/after it. // as separate words by assistive technologies from the content before/after it.
content: ' annotation start '; content: ' annotation start ';
} }
&::after { &::after {
@include screen-reader-only; @apply sr-only;
content: ' annotation end '; content: ' annotation end ';
} }
}
// Give a highlight inside a larger highlight a different color to stand out. // Apply focused-highlight styling
& .hypothesis-highlight {
background-color: $color-highlight-second;
&.is-transparent {
background-color: transparent;
}
// Limit the number of different highlight shades by making highlights
// that are 3+ levels deep transparent.
//
// This was historically done to improve readability in PDFs [1], but that
// is no longer an issue as in PDFs highlights are created by drawing
// SVGs on top of the <canvas>.
//
// [1] https://github.com/hypothesis/client/issues/1995.
& .hypothesis-highlight {
background-color: transparent;
}
}
.hypothesis-highlights-always-on
.hypothesis-highlight.hypothesis-highlight-focused {
// When an annotation card is hovered in the sidebar, the corresponding // When an annotation card is hovered in the sidebar, the corresponding
// highlights are shown with a "focused" color. // highlights are shown with a "focused" color.
&.hypothesis-highlight-focused { &.hypothesis-highlight-focused {
background-color: $color-highlight-focused !important; mix-blend-mode: normal !important;
background-color: var(--highlight-color-focused) !important;
text-decoration: none;
.hypothesis-highlight { .hypothesis-highlight {
background-color: transparent !important; background-color: transparent !important;
} }
} }
}
} }
// Placeholder element to which annotations for off-screen content in PDFs // Placeholder element to which annotations for off-screen content in PDFs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment