Skip to content

Commit 2fa3d11

Browse files
authored
Use !important for all Readium CSS variables (#334)
1 parent b1b19e0 commit 2fa3d11

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

readium/navigator/src/main/assets/_scripts/src/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ export function setProperty(key, value) {
292292
removeProperty(key);
293293
} else {
294294
var root = document.documentElement;
295+
// The `!important` annotation is added with `setProperty()` because if it's part of the
296+
// `value`, it will be ignored by the Web View.
295297
root.style.setProperty(key, value, "important");
296298
}
297299
}

readium/navigator/src/main/assets/readium/scripts/readium-fixed.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readium/navigator/src/main/assets/readium/scripts/readium-reflowable.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readium/navigator/src/main/java/org/readium/r2/navigator/epub/css/Properties.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ interface Properties : Cssable {
2828
}
2929

3030
return props
31-
.map { (key, value) -> "$key: $value" }
32-
.joinToString(";\n") + ";\n"
31+
.map { (key, value) -> "$key: $value !important;" }
32+
.joinToString("\n") + "\n"
3333
}
3434
}
3535

readium/navigator/src/test/java/org/readium/r2/navigator/epub/css/PropertiesTest.kt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ class PropertiesTest {
261261
fun `Generate minimal inline CSS properties`() {
262262
assertEquals(
263263
"""
264-
--USER__view: readium-scroll-on;
265-
--USER__colCount: auto;
264+
--USER__view: readium-scroll-on !important;
265+
--USER__colCount: auto !important;
266266
267267
""".trimIndent(),
268268
UserProperties(
@@ -276,28 +276,28 @@ class PropertiesTest {
276276
fun `Generate full inline CSS properties`() {
277277
assertEquals(
278278
"""
279-
--USER__view: readium-scroll-on;
280-
--USER__colCount: auto;
281-
--USER__pageMargins: 1.2;
282-
--USER__appearance: readium-night-on;
283-
--USER__darkenImages: readium-darken-on;
284-
--USER__invertImages: readium-invert-on;
285-
--USER__textColor: #FF0000;
286-
--USER__backgroundColor: #00FF00;
287-
--USER__fontOverride: readium-font-on;
288-
--USER__fontFamily: "Times New", "Comic Sans";
289-
--USER__fontSize: 2.3vmax;
290-
--USER__advancedSettings: readium-advanced-on;
291-
--USER__typeScale: 3.4;
292-
--USER__textAlign: justify;
293-
--USER__lineHeight: 4.5pt;
294-
--USER__paraSpacing: 5.6pt;
295-
--USER__paraIndent: 6.7rem;
296-
--USER__wordSpacing: 7.8rem;
297-
--USER__letterSpacing: 8.9rem;
298-
--USER__bodyHyphens: auto;
299-
--USER__ligatures: common-ligatures;
300-
--USER__a11yNormalize: readium-a11y-on;
279+
--USER__view: readium-scroll-on !important;
280+
--USER__colCount: auto !important;
281+
--USER__pageMargins: 1.2 !important;
282+
--USER__appearance: readium-night-on !important;
283+
--USER__darkenImages: readium-darken-on !important;
284+
--USER__invertImages: readium-invert-on !important;
285+
--USER__textColor: #FF0000 !important;
286+
--USER__backgroundColor: #00FF00 !important;
287+
--USER__fontOverride: readium-font-on !important;
288+
--USER__fontFamily: "Times New", "Comic Sans" !important;
289+
--USER__fontSize: 2.3vmax !important;
290+
--USER__advancedSettings: readium-advanced-on !important;
291+
--USER__typeScale: 3.4 !important;
292+
--USER__textAlign: justify !important;
293+
--USER__lineHeight: 4.5pt !important;
294+
--USER__paraSpacing: 5.6pt !important;
295+
--USER__paraIndent: 6.7rem !important;
296+
--USER__wordSpacing: 7.8rem !important;
297+
--USER__letterSpacing: 8.9rem !important;
298+
--USER__bodyHyphens: auto !important;
299+
--USER__ligatures: common-ligatures !important;
300+
--USER__a11yNormalize: readium-a11y-on !important;
301301
302302
""".trimIndent(),
303303
UserProperties(

0 commit comments

Comments
 (0)