@evidentpoint/readium-css
Version:
A set of reference stylesheets for EPUB Reading Systems
679 lines (504 loc) • 21.4 kB
CSS
/* Readium CSS
Config module
A file allowing implementers to customize flags for reading modes,
user settings, etc.
Repo: https://github.com/readium/readium-css */
/* Custom medias
Syntax: @custom-media --variable (prop: value) */
/* Responsive columns
The minimum width for which responsive columns (2 -> 1 and vice versa,
depending on the current font-size) must be enabled */
/* Mobile columns
The minimum and maximum width for mobile devices.
We’re forcing the landscape orientation by default,
and must still investigate large tablets (iPad Pro, Surface Pro 3, etc.). */
/* Custom selectors
Syntax: @custom-selector :--variable selector
The selectors you will use for flags/switches
You can alternatively use classes or custom data-* attributes */
/* User view = paged | scrolled */
/* Font-family override */
/* Advanced settings */
/* Reading Modes */
/* Filters (images) */
/* Accessibility normalization */
/* Accessibility font. You can add selectors, using “, ” as a separator, if you have multiple fonts */
/* Direction i.e. ltr and rtl */
/* Readium CSS
Pagination module
A set of styles to paginate ePublications
Repo: https://github.com/readium/readium-css */
/* Config */
/* Columns are responsive by default, even if column-width is set in pixels,
which means two-page spread will switch to single page depending on current font-size.
If you want more control, I’m afraid you’ll have to update colWidth/colGap dynamically,
which is how a significant amount of RS do at the moment. */
/* Default for smartphone portrait (small screens) */
:root {
/* Your columns’ width floor */
--RS__colWidth: 45em; /* The width at which we’ll switch to 2 columns by default. PS: you can’t set it in rem */
/* Ideal number of columns (depending on columns’ width floor) */
--RS__colCount: 1;
/* Gap between columns (in pixels so that it won’t resize with font-size) */
--RS__colGap: 0;
/* Optimal line-length (rem will take :root font-size into account, whatever the body’s font-size) */
--RS__maxLineLength: 40rem;
/* Default page horizontal margins (in pixels so that it won’t resize with font-size) */
--RS__pageGutter: 20px; /* See if colGap and pageGutter can be the same var */
}
/* Reset page margins for Forward compatibility */
@page {
margin: 0 ;
}
/* :root selector has same specificity as a class i.e. 0010
We might have to change that to html / context
-> https://css-tricks.com/almanac/selectors/r/root/ */
:root {
/* In case you use left position to scroll, can be removed if using transform: translateX() */
position: relative;
-webkit-column-width: var(--RS__colWidth);
-moz-column-width: var(--RS__colWidth);
column-width: var(--RS__colWidth);
/* Init pagination */
/* TODO: document columns’ logic cos it might feel weird at first */
-webkit-column-count: var(--RS__colCount);
-moz-column-count: var(--RS__colCount);
column-count: var(--RS__colCount);
-webkit-column-gap: var(--RS__colGap);
-moz-column-gap: var(--RS__colGap);
column-gap: var(--RS__colGap);
/* Default is balance and we want columns to be filled entirely (100vh) */
-moz-column-fill: auto;
column-fill: auto;
width: 100%;
height: 100vh;
max-width: 100%;
max-height: 100vh;
min-width: 100%;
min-height: 100vh;
padding: 0 ;
margin: 0 ;
/* Column size will depend on this if we want to make it responsive */
font-size: 100% ;
-webkit-text-size-adjust: 100%;
/* Switch to newer box model (not inherited by authors’ styles) */
box-sizing: border-box;
/* Fix bug for older Chrome */
-webkit-perspective: 1;
/* Prevents options pop-up when long tap in webkit */
-webkit-touch-callout: none;
}
body {
/* overflow: hidden; bugfix: contents won’t paginate in Firefox and one sample in Safari */
width: 100%;
/* Limit line-length but we have to reset when 2 columns and control the viewport.
By using max-width + margin auto, margins will shrink when font-size increases,
which is what would be expected in terms of typography. */
max-width: var(--RS__maxLineLength) ;
padding: 0 var(--RS__pageGutter) ;
margin: 0 auto ;
/* We need a minimum padding on body so that descandants/ascendants in italic/script are not cut-off.
Drawback: we have to use border-box so that it doesn’t screw the box model,
which means it impacts colWidth and max-width */
box-sizing: border-box;
}
/* We’ll now redefine margins and columns depending on the minimum width available
The goal is having the simplest model possible and avoid targeting devices */
/* Smartphone landscape */
@media screen and (min-width: 35em) {
:root {
--RS__pageGutter: 30px;
}
}
/* Tablet portrait */
@media screen and (min-width: 45em) {
:root {
--RS__pageGutter: 40px;
}
}
/* Desktop + tablet large */
/* We get the previous settings, we just change the margins */
@media screen and (min-width: 75em) {
:root {
--RS__pageGutter: 50px;
}
}
/* At this point (80em or so), constraining line length must be done at the web view/iframe level, or by limiting the size of :root itself */
/* Responsive columns */
@media screen and (min-width: 60em), screen and (min-device-width: 36em) and (max-device-width: 47em) and (orientation: landscape) {
:root {
/* The size at which we want 2 columns to switch to 1 (depending on font-size) */
--RS__colWidth: 20em; /* 20 * 16 = 320px but 20 * 28 = 560px so it will switch to 1 col @ 175% font-size (user-setting) on an iPad */
/* We constrain to 2 columns so that we can never get 3 or 4, etc. */
--RS__colCount: 2;
--RS__maxLineLength: 39.99rem; /* If we don’t use this, colNumber user setting won’t work in Safari… */
}
}
/* Readium CSS
Scroll module
A set of styles to scroll ePublications
This module overrides pagination
Repo: https://github.com/readium/readium-css */
:root[style*="readium-scroll-on"] {
/* Reset columns, auto + auto = columns can’t be created */
-webkit-columns: auto auto ;
-moz-columns: auto auto ;
columns: auto auto ;
width: auto ;
height: auto ;
max-width: none ;
max-height: none ;
/* Reset html size so that the user can scroll */
min-width: 0 ;
min-height: 0 ;
}
/* Make sure line-length is limited in all configs */
:root[style*="readium-scroll-on"] body {
--RS__maxLineLength: 40rem ;
}
/* Readium CSS
Default highlights
A stylesheet for user highlights
Repo: https://github.com/readium/readium-css */
/* User Highlights */
.readiumCSS-yellow-highlight {
background-color: rgba(255, 255, 0, 0.5);
}
.readiumCSS-green-highlight {
background-color: rgba(0, 255, 0, 0.5);
}
.readiumCSS-orange-highlight {
background-color: rgba(255, 165, 0, 0.5);
}
.readiumCSS-pink-highlight {
background-color: rgba(255, 105, 180, 0.5);
}
/* Media overlays */
.readiumCSS-mo-active-default {
color: black ;
background-color: yellow ;
}
/* Readium CSS
Night mode
A preset theme for night mode
Repo: https://github.com/readium/readium-css */
/* CONFIG */
/* [style*="--USER__appearance"] can be used to increase specificity but performance hit */
:root[style*="readium-night-on"] {
--RS__backgroundColor: #000000;
--RS__textColor: #FEFEFE;
--RS__linkColor: #63caff;
--RS__visitedColor: #0099E5;
/* This can be customized but initial will re-use default value of the browser */
--RS__selectionBackgroundColor: #b4d8fe;
--RS__selectionTextColor: inherit;
}
/* we don’t need to redeclare bg-color and color for :root since we will inherit and update from day/default mode */
:root[style*="readium-night-on"] *:not(a) {
color: inherit ;
background-color: transparent ;
border-color: currentColor ;
}
:root[style*="readium-night-on"] svg text {
fill: currentColor ;
stroke: none ;
}
:root[style*="readium-night-on"] a:link,
:root[style*="readium-night-on"] a:link * {
color: var(--RS__linkColor) ;
}
:root[style*="readium-night-on"] a:visited,
:root[style*="readium-night-on"] a:visited * {
color: var(--RS__visitedColor) ;
}
:root[style*="readium-night-on"] img[class*="gaiji"],
:root[style*="readium-night-on"] *[epub\:type~="titlepage"] img:only-child {
-webkit-filter: invert(100%);
filter: invert(100%);
}
/* Darken all images on user’s demand */
:root[style*="readium-night-on"][style*="readium-darken-on"] img {
-webkit-filter: brightness(80%);
filter: brightness(80%);
}
/* Invert all images on user’s demand */
:root[style*="readium-night-on"][style*="readium-invert-on"] img {
-webkit-filter: invert(100%);
filter: invert(100%);
}
/* Darken and invert on user’s demand */
:root[style*="readium-night-on"][style*="readium-darken-on"][style*="readium-invert-on"] img {
-webkit-filter: brightness(80%) invert(100%);
filter: brightness(80%) invert(100%);
}
/* Readium CSS
Sepia mode
A preset theme for sepia mode
Repo: https://github.com/readium/readium-css */
/* CONFIG */
:root[style*="readium-sepia-on"] {
--RS__backgroundColor: #faf4e8;
--RS__textColor: #121212;
--RS__linkColor: #0000EE;
--RS__visitedColor: #551A8B;
/* This can be customized but initial will re-use default value of the browser */
--RS__selectionBackgroundColor: #b4d8fe;
--RS__selectionTextColor: inherit;
--RS__maxLineLength: 40.01rem; /* Forcing a reflow in Blink/Webkit so that blend mode can work */
}
/* we don’t need to redeclare bg-color and color for :root since we will inherit and update from day/default mode */
:root[style*="readium-sepia-on"] body {
/* Should be transparent but Chrome bug https://bugs.chromium.org/p/chromium/issues/detail?id=711955&q=mix-blend-mode&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified */
color: inherit;
background-color: var(--RS__backgroundColor);
}
:root[style*="readium-sepia-on"] a:link,
:root[style*="readium-sepia-on"] a:link * {
color: var(--RS__linkColor);
}
:root[style*="readium-sepia-on"] a:visited,
:root[style*="readium-sepia-on"] a:visited * {
color: var(--RS__visitedColor);
}
:root[style*="readium-sepia-on"] svg,
:root[style*="readium-sepia-on"] img {
/* Make sure the proper bg-color is used for the blend mode */
background-color: transparent ;
mix-blend-mode: multiply;
}
/* Readium CSS
OS Accessibility Modes
A stylesheet to deal with OS accessibility settings
Repo: https://github.com/readium/readium-css */
/* Windows high contrast colors are mapped to CSS system color keywords
See http://www.gwhitworth.com/blog/2017/04/how-to-use-ms-high-contrast */
@media screen and (-ms-high-contrast: active) {
:root {
color: windowText ;
background-color: window ;
}
/* The following selectors are super funky but it makes sure everything is inherited, this is indeed critical for this mode */
:root :not(#\#):not(#\#):not(#\#),
:root :not(#\#):not(#\#):not(#\#) :not(#\#):not(#\#):not(#\#)
:root :not(#\#):not(#\#):not(#\#) :not(#\#):not(#\#):not(#\#) :not(#\#):not(#\#):not(#\#) {
color: inherit ;
background-color: inherit ;
}
.readiumCSS-mo-active-default {
color: highlightText ;
background-color: highlight ;
}
/* For links, hyperlink keyword is automatically set */
/* Should we also set user highlights? */
}
@media screen and (-ms-high-contrast: white-on-black) {
:root[style*="readium-night-on"] img[class*="gaiji"],
:root[style*="readium-night-on"] *[epub\:type~="titlepage"] img:only-child {
-webkit-filter: none ;
filter: none ;
}
:root[style*="readium-night-on"][style*="readium-invert-on"] img {
-webkit-filter: none ;
filter: none ;
}
:root[style*="readium-night-on"][style*="readium-darken-on"][style*="readium-invert-on"] img {
-webkit-filter: brightness(80%);
filter: brightness(80%);
}
}
/* Will be true on recent versions of iOS and MacOS if inverted setting enabled by the user */
@media screen and (inverted-colors) {
:root[style*="readium-night-on"] img[class*="gaiji"],
:root[style*="readium-night-on"] *[epub\:type~="titlepage"] img:only-child {
-webkit-filter: none ;
filter: none ;
}
:root[style*="readium-night-on"][style*="readium-invert-on"] img {
-webkit-filter: none ;
filter: none ;
}
:root[style*="readium-night-on"][style*="readium-darken-on"][style*="readium-invert-on"] img {
-webkit-filter: brightness(80%);
filter: brightness(80%);
}
}
@media screen and (monochrome) {
/* Grayscale (Implemented in Safari, what about eInk?) */
/* Must deal with anything color (contrast) so must be managed at the night/sepia/theme level :( */
}
@media screen and (prefers-reduced-motion) {
/* If reduced motion is set on MacOS, in case we have animation/transition */
}
/* Readium CSS
Columns number pref
A submodule managing columns number for user settings
Part of “Chrome Advanced” class – no flag required.
Repo: https://github.com/readium/readium-css */
/* Number of columns = 1 | 2 */
/* We still need to see if we allow users to force number of columns for all configs, currently it behaves as an "auto" setting */
/* apply col setting except for mobile portrait */
@media screen and (min-width: 60em), screen and (min-device-width: 36em) and (max-device-width: 47em) and (orientation: landscape) {
:root[style*="--USER__colCount: 1"],
:root[style*="--USER__colCount:1"],
:root[style*="--USER__colCount: 2"],
:root[style*="--USER__colCount:2"] {
-webkit-column-count: var(--USER__colCount);
-moz-column-count: var(--USER__colCount);
column-count: var(--USER__colCount);
}
/* If one column, make sure we limit line-length */
:root[style*="--USER__colCount: 1"],
:root[style*="--USER__colCount:1"] {
--RS__maxLineLength: 40rem ; /* This is the only way for the user setting to work in webkit… */
--RS__colWidth: 100vw;
}
/* If smartphone landscape, and 2 columns, col width the same as iPad landscape + desktop */
:root[style*="--USER__colCount: 2"],
:root[style*="--USER__colCount:2"] {
--RS__colWidth: auto; /* User explicitely tells he/she wants 2 columns, we reset floor value */
}
}
/* Readium CSS
Page margins pref
A submodule managing page margins for user settings
Part of “Chrome Advanced” class – no flag required.
Repo: https://github.com/readium/readium-css */
/* Page Margins: the user margin is a factor of the page gutter e.g. 0.5, 0.75, 1, 1.25, 1.5, etc. */
:root[style*="--USER__pageMargins"] body {
padding: 0 calc(var(--RS__pageGutter) * var(--USER__pageMargins)) ;
}
/* Readium CSS
Custom colors pref
A submodule managing custom colors for user settings
Part of “Chrome Advanced” class – no flag required.
Repo: https://github.com/readium/readium-css */
:root[style*="--USER__backgroundColor"] {
background-color: var(--USER__backgroundColor) ;
}
:root[style*="--USER__backgroundColor"] * {
background-color: transparent ;
}
:root[style*="--USER__textColor"] {
color: var(--USER__textColor) ;
}
:root[style*="--USER__textColor"] *:not(h1):not(h2):not(h3):not(h4):not(h5):not(h6):not(pre) {
color: inherit ;
}
/* Readium CSS
Font Family pref
A submodule managing font-family for user settings
Part of “User Overrides” class – “font override” flag required.
Repo: https://github.com/readium/readium-css */
:root[style*="readium-font-on"][style*="--USER__fontFamily"] {
font-family: var(--USER__fontFamily) ;
}
:root[style*="readium-font-on"][style*="--USER__fontFamily"] body,
:root[style*="readium-font-on"][style*="--USER__fontFamily"] p,
:root[style*="readium-font-on"][style*="--USER__fontFamily"] li,
:root[style*="readium-font-on"][style*="--USER__fontFamily"] div,
:root[style*="readium-font-on"][style*="--USER__fontFamily"] dt,
:root[style*="readium-font-on"][style*="--USER__fontFamily"] dd {
font-family: inherit ;
}
:root[style*="readium-font-on"][style*="--USER__fontFamily"] i:not([lang]),
:root[style*="readium-font-on"][style*="--USER__fontFamily"] i:not([xml\:lang]),
:root[style*="readium-font-on"][style*="--USER__fontFamily"] em:not([lang]),
:root[style*="readium-font-on"][style*="--USER__fontFamily"] em:not([xml\:lang]),
:root[style*="readium-font-on"][style*="--USER__fontFamily"] cite:not([lang]),
:root[style*="readium-font-on"][style*="--USER__fontFamily"] cite:not([xml\:lang]),
:root[style*="readium-font-on"][style*="--USER__fontFamily"] b:not([lang]),
:root[style*="readium-font-on"][style*="--USER__fontFamily"] b:not([xml\:lang]),
:root[style*="readium-font-on"][style*="--USER__fontFamily"] strong:not([lang]),
:root[style*="readium-font-on"][style*="--USER__fontFamily"] strong:not([xml\:lang]),
:root[style*="readium-font-on"][style*="--USER__fontFamily"] span:not([lang]),
:root[style*="readium-font-on"][style*="--USER__fontFamily"] span:not([xml\:lang]) {
font-family: inherit ;
}
/* Readium CSS
Font size pref
A submodule managing font-size for user settings
Part of “User Overrides” class – no flag required.
Repo: https://github.com/readium/readium-css */
:root[style*="--USER__fontSize"] {
font-size: var(--USER__fontSize) ;
}
/* Readium CSS
Line height pref
A submodule managing line-height for user settings
Part of “User Overrides Advanced” class – “advanced settings” flag required.
Repo: https://github.com/readium/readium-css */
:root[style*="readium-advanced-on"][style*="--USER__lineHeight"] {
line-height: var(--USER__lineHeight) ;
}
:root[style*="readium-advanced-on"][style*="--USER__lineHeight"] body,
:root[style*="readium-advanced-on"][style*="--USER__lineHeight"] p,
:root[style*="readium-advanced-on"][style*="--USER__lineHeight"] li,
:root[style*="readium-advanced-on"][style*="--USER__lineHeight"] div {
line-height: inherit;
}
/* Readium CSS
Para spacing pref
A submodule managing paragraphs’ top and bottom margins for user settings
Part of “User Overrides Advanced” class – “advanced settings” flag required.
Repo: https://github.com/readium/readium-css */
:root[style*="readium-advanced-on"][style*="--USER__paraSpacing"] p {
margin-top: var(--USER__paraSpacing) ;
margin-bottom: var(--USER__paraSpacing) ;
}
/* Readium CSS
Font size normalize
A stylesheet to normalize font-size
Repo: https://github.com/readium/readium-css */
/* STYLES */
/* :root is used so that you can quickly add a class or attribute if you prefer e.g. `:root[data-rs-normalize]` */
/* We create a default so that you don’t need to explicitly set one in the DOM.
Once the “Publisher’s styles” checkbox is unchecked, the normalize is applied automatically */
:root[style*="readium-advanced-on"] {
--USER__typeScale: 1.2; /* This is the default type scale you’ll find in most publications */
}
:root[style*="readium-advanced-on"] p,
:root[style*="readium-advanced-on"] li,
:root[style*="readium-advanced-on"] div,
:root[style*="readium-advanced-on"] pre,
:root[style*="readium-advanced-on"] dd {
font-size: 1rem ;
}
:root[style*="readium-advanced-on"] h1 {
/* Fallback if browser doesn’t support vars */
font-size: 1.75rem ;
font-size: calc(((1rem * var(--USER__typeScale)) * var(--USER__typeScale)) * var(--USER__typeScale)) ;
}
:root[style*="readium-advanced-on"] h2 {
/* Fallback if browser doesn’t support vars */
font-size: 1.5rem ;
font-size: calc((1rem * var(--USER__typeScale)) * var(--USER__typeScale)) ;
}
:root[style*="readium-advanced-on"] h3 {
/* Fallback if browser doesn’t support vars */
font-size: 1.25rem ;
font-size: calc(1rem * var(--USER__typeScale)) ;
}
:root[style*="readium-advanced-on"] h4,
:root[style*="readium-advanced-on"] h5,
:root[style*="readium-advanced-on"] h6 {
font-size: 1rem ;
}
:root[style*="readium-advanced-on"] small {
font-size: smaller ;
}
:root[style*="readium-advanced-on"] sub,
:root[style*="readium-advanced-on"] sup {
font-size: 67.5% ;
}
/* The following styles kick in if you define the typeScale variable in the DOM.
No need to repeat declarations which don’t make use of the variable */
:root[style*="readium-advanced-on"][style*="--USER__typeScale"] h1 {
font-size: calc(((1rem * var(--USER__typeScale)) * var(--USER__typeScale)) * var(--USER__typeScale)) ;
}
:root[style*="readium-advanced-on"][style*="--USER__typeScale"] h2 {
font-size: calc((1rem * var(--USER__typeScale)) * var(--USER__typeScale)) ;
}
:root[style*="readium-advanced-on"][style*="--USER__typeScale"] h3 {
font-size: calc(1rem * var(--USER__typeScale)) ;
}
/*# sourceMappingURL=ReadiumCSS-after.css.map */