Skip to content

Commit d721ff5

Browse files
committed
Remove the remaining dir-dependent CSS rules
After the recent round of patches, I figured that we'd gone as far as possible in replacing `dir`-dependent CSS rules for the viewer. However, it occurred that me that we could actually use a bit of CSS-trickery to get rid of the remaining ones. More specifically, this was done by defining a CSS variable whose value depends on the document direction and then using that variable together with `calc()` in the affected rules. *Please note:* I suppose that this could perhaps be seen as a bit too "magical", hence I understand if this patch is ultimately rejected, however this is probably the only simple way to get rid of the remaining `dir`-dependent CSS rules.
1 parent f017f29 commit d721ff5

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

web/viewer.css

+14-29
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@import url(pdf_viewer.css);
1717

1818
:root {
19+
--dir-factor: 1;
1920
--sidebar-width: 200px;
2021
--sidebar-transition-duration: 200ms;
2122
--sidebar-transition-timing-function: ease;
@@ -104,6 +105,10 @@
104105
--secondaryToolbarButton-documentProperties-icon: url(images/secondaryToolbarButton-documentProperties.svg);
105106
}
106107

108+
:root:dir(rtl) {
109+
--dir-factor: -1;
110+
}
111+
107112
@media (prefers-color-scheme: dark) {
108113
:root {
109114
--main-color: rgba(249, 249, 250, 1);
@@ -287,14 +292,13 @@ html[dir="rtl"] #outerContainer.sidebarOpen #sidebarContainer {
287292
position: absolute;
288293
width: 100%;
289294
background-color: rgba(0, 0, 0, 0.1);
295+
box-shadow: inset calc(-1px * var(--dir-factor)) 0 0 rgba(0, 0, 0, 0.25);
290296
}
291297
html[dir="ltr"] #sidebarContent {
292298
left: 0;
293-
box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.25);
294299
}
295300
html[dir="rtl"] #sidebarContent {
296301
right: 0;
297-
box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.25);
298302
}
299303

300304
#viewerContainer {
@@ -345,14 +349,8 @@ html[dir="rtl"]
345349
width: 100%;
346350
height: 32px;
347351
background-color: var(--sidebar-toolbar-bg-color);
348-
}
349-
html[dir="ltr"] #toolbarSidebar {
350-
box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.25), 0 1px 0 rgba(0, 0, 0, 0.15),
351-
0 0 1px rgba(0, 0, 0, 0.1);
352-
}
353-
html[dir="rtl"] #toolbarSidebar {
354-
box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.25), 0 1px 0 rgba(0, 0, 0, 0.15),
355-
0 0 1px rgba(0, 0, 0, 0.1);
352+
box-shadow: inset calc(-1px * var(--dir-factor)) 0 0 rgba(0, 0, 0, 0.25),
353+
0 1px 0 rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1);
356354
}
357355

358356
#toolbarSidebar .toolbarButton {
@@ -572,10 +570,7 @@ html[dir="rtl"] #findInput {
572570
#findInput[data-status="pending"] {
573571
background-image: var(--loading-icon);
574572
background-repeat: no-repeat;
575-
background-position: 98%;
576-
}
577-
html[dir="rtl"] #findInput[data-status="pending"] {
578-
background-position: 3px;
573+
background-position: calc(50% + 48% * var(--dir-factor));
579574
}
580575
#findInput[data-status="notFound"] {
581576
background-color: rgba(255, 102, 102, 1);
@@ -923,16 +918,12 @@ html[dir="rtl"] .secondaryToolbarButton::before {
923918

924919
.toolbarButton#sidebarToggle::before {
925920
mask-image: var(--toolbarButton-sidebarToggle-icon);
926-
}
927-
html[dir="rtl"] .toolbarButton#sidebarToggle::before {
928-
transform: scaleX(-1);
921+
transform: scaleX(var(--dir-factor));
929922
}
930923

931924
.toolbarButton#secondaryToolbarToggle::before {
932925
mask-image: var(--toolbarButton-secondaryToolbarToggle-icon);
933-
}
934-
html[dir="rtl"] .toolbarButton#secondaryToolbarToggle::before {
935-
transform: scaleX(-1);
926+
transform: scaleX(var(--dir-factor));
936927
}
937928

938929
.toolbarButton.findPrevious::before {
@@ -1000,9 +991,7 @@ html[dir="rtl"] .toolbarButton#secondaryToolbarToggle::before {
1000991

1001992
#viewOutline.toolbarButton::before {
1002993
mask-image: var(--toolbarButton-viewOutline-icon);
1003-
}
1004-
html[dir="rtl"] #viewOutline.toolbarButton::before {
1005-
transform: scaleX(-1);
994+
transform: scaleX(var(--dir-factor));
1006995
}
1007996

1008997
#viewAttachments.toolbarButton::before {
@@ -1015,9 +1004,7 @@ html[dir="rtl"] #viewOutline.toolbarButton::before {
10151004

10161005
#currentOutlineItem.toolbarButton::before {
10171006
mask-image: var(--toolbarButton-currentOutlineItem-icon);
1018-
}
1019-
html[dir="rtl"] #currentOutlineItem.toolbarButton::before {
1020-
transform: scaleX(-1);
1007+
transform: scaleX(var(--dir-factor));
10211008
}
10221009

10231010
#viewFind.toolbarButton::before {
@@ -1317,9 +1304,7 @@ a:focus > .thumbnail > .thumbnailSelectionRing,
13171304
}
13181305
.treeItemToggler.treeItemsHidden::before {
13191306
mask-image: var(--treeitem-collapsed-icon);
1320-
}
1321-
html[dir="rtl"] .treeItemToggler.treeItemsHidden::before {
1322-
transform: scaleX(-1);
1307+
transform: scaleX(var(--dir-factor));
13231308
}
13241309
.treeItemToggler.treeItemsHidden ~ .treeItems {
13251310
display: none;

0 commit comments

Comments
 (0)