Skip to content

Commit b0029d7

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 feea2b7 commit b0029d7

File tree

1 file changed

+14
-33
lines changed

1 file changed

+14
-33
lines changed

web/viewer.css

+14-33
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);
@@ -283,12 +288,7 @@ html[dir="rtl"] #sidebarContainer {
283288
position: absolute;
284289
width: 100%;
285290
background-color: rgba(0, 0, 0, 0.1);
286-
}
287-
html[dir="ltr"] #sidebarContent {
288-
box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.25);
289-
}
290-
html[dir="rtl"] #sidebarContent {
291-
box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.25);
291+
box-shadow: inset calc(-1px * var(--dir-factor)) 0 0 rgba(0, 0, 0, 0.25);
292292
}
293293

294294
#viewerContainer {
@@ -331,14 +331,8 @@ html[dir="rtl"] #sidebarContent {
331331
width: 100%;
332332
height: 32px;
333333
background-color: var(--sidebar-toolbar-bg-color);
334-
}
335-
html[dir="ltr"] #toolbarSidebar {
336-
box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.25), 0 1px 0 rgba(0, 0, 0, 0.15),
337-
0 0 1px rgba(0, 0, 0, 0.1);
338-
}
339-
html[dir="rtl"] #toolbarSidebar {
340-
box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.25), 0 1px 0 rgba(0, 0, 0, 0.15),
341-
0 0 1px rgba(0, 0, 0, 0.1);
334+
box-shadow: inset calc(-1px * var(--dir-factor)) 0 0 rgba(0, 0, 0, 0.25),
335+
0 1px 0 rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1);
342336
}
343337

344338
#toolbarSidebar .toolbarButton {
@@ -536,10 +530,7 @@ html[dir="rtl"] #findInput {
536530
#findInput[data-status="pending"] {
537531
background-image: var(--loading-icon);
538532
background-repeat: no-repeat;
539-
background-position: 98%;
540-
}
541-
html[dir="rtl"] #findInput[data-status="pending"] {
542-
background-position: 3px;
533+
background-position: calc(50% + 48% * var(--dir-factor));
543534
}
544535
#findInput[data-status="notFound"] {
545536
background-color: rgba(255, 102, 102, 1);
@@ -871,16 +862,12 @@ html[dir="rtl"] #findInput[data-status="pending"] {
871862

872863
.toolbarButton#sidebarToggle::before {
873864
mask-image: var(--toolbarButton-sidebarToggle-icon);
874-
}
875-
html[dir="rtl"] .toolbarButton#sidebarToggle::before {
876-
transform: scaleX(-1);
865+
transform: scaleX(var(--dir-factor));
877866
}
878867

879868
.toolbarButton#secondaryToolbarToggle::before {
880869
mask-image: var(--toolbarButton-secondaryToolbarToggle-icon);
881-
}
882-
html[dir="rtl"] .toolbarButton#secondaryToolbarToggle::before {
883-
transform: scaleX(-1);
870+
transform: scaleX(var(--dir-factor));
884871
}
885872

886873
.toolbarButton.findPrevious::before {
@@ -948,9 +935,7 @@ html[dir="rtl"] .toolbarButton#secondaryToolbarToggle::before {
948935

949936
#viewOutline.toolbarButton::before {
950937
mask-image: var(--toolbarButton-viewOutline-icon);
951-
}
952-
html[dir="rtl"] #viewOutline.toolbarButton::before {
953-
transform: scaleX(-1);
938+
transform: scaleX(var(--dir-factor));
954939
}
955940

956941
#viewAttachments.toolbarButton::before {
@@ -963,9 +948,7 @@ html[dir="rtl"] #viewOutline.toolbarButton::before {
963948

964949
#currentOutlineItem.toolbarButton::before {
965950
mask-image: var(--toolbarButton-currentOutlineItem-icon);
966-
}
967-
html[dir="rtl"] #currentOutlineItem.toolbarButton::before {
968-
transform: scaleX(-1);
951+
transform: scaleX(var(--dir-factor));
969952
}
970953

971954
#viewFind.toolbarButton::before {
@@ -1260,9 +1243,7 @@ a:focus > .thumbnail > .thumbnailSelectionRing,
12601243
}
12611244
.treeItemToggler.treeItemsHidden::before {
12621245
mask-image: var(--treeitem-collapsed-icon);
1263-
}
1264-
html[dir="rtl"] .treeItemToggler.treeItemsHidden::before {
1265-
transform: scaleX(-1);
1246+
transform: scaleX(var(--dir-factor));
12661247
}
12671248
.treeItemToggler.treeItemsHidden ~ .treeItems {
12681249
display: none;

0 commit comments

Comments
 (0)