Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace dir-dependent margin/margin-left/margin-right with logical properties #14670

Merged
merged 1 commit into from
Mar 19, 2022

Conversation

Snuffleupagus
Copy link
Collaborator

Please note: This is another step in what will, time permitting, become a series of patches to simplify/modernize the viewer CSS.

Rather than having to manually specify ltr/rtl-specific margin-values in the CSS, we can use logical margin instead (and similar for some related left/right occurrences).
These logical properties depend on, among other things, the direction of the HTML document which we always specify in the viewer.

Given that most of these logical CSS properties are fairly new, and that cross-browser support is thus somewhat limited (see below), we need to use a couple of PostCSS plugins (see below) in order to support this in the GENERIC viewer.


@Snuffleupagus
Copy link
Collaborator Author

For the GENERIC viewer, the contents of the built viewer.css changes as follows with this patch:

--- C:\Users\Jonas\Desktop\viewer.css
+++ C:\Users\Jonas\Git\pdf.js\build\generic\web\viewer.css
@@ -1162,18 +1162,27 @@
     0 0 1px rgba(0, 0, 0, 0.1);
 }
 
-html[dir="ltr"] #toolbarSidebar .toolbarButton {
+[dir="ltr"] #toolbarSidebar .toolbarButton {
   margin-right: 2px !important;
 }
-html[dir="rtl"] #toolbarSidebar .toolbarButton {
+
+[dir="rtl"] #toolbarSidebar .toolbarButton {
   margin-left: 2px !important;
 }
 
-html[dir="ltr"] #toolbarSidebarRight .toolbarButton {
+#toolbarSidebar .toolbarButton {
+  -webkit-margin-end: 2px !important;
+          margin-inline-end: 2px !important;
+}
+[dir="ltr"] #toolbarSidebarRight .toolbarButton {
   margin-right: 3px !important;
 }
-html[dir="rtl"] #toolbarSidebarRight .toolbarButton {
+[dir="rtl"] #toolbarSidebarRight .toolbarButton {
   margin-left: 3px !important;
+}
+#toolbarSidebarRight .toolbarButton {
+  -webkit-margin-end: 3px !important;
+          margin-inline-end: 3px !important;
 }
 
 #sidebarResizer {
@@ -1325,16 +1334,19 @@
   right: 64px;
 }
 
+[dir="ltr"] .findbar .splitToolbarButton {
+  margin-left: 0;
+  margin-right: 5px;
+}
+
+[dir="rtl"] .findbar .splitToolbarButton {
+  margin-right: 0;
+  margin-left: 5px;
+}
+
 .findbar .splitToolbarButton {
   margin-top: 3px;
-}
-html[dir="ltr"] .findbar .splitToolbarButton {
-  margin-left: 0;
-  margin-right: 5px;
-}
-html[dir="rtl"] .findbar .splitToolbarButton {
-  margin-left: 5px;
-  margin-right: 0;
+  margin-inline: 0 5px;
 }
 
 .findbar .splitToolbarButton > .toolbarButton {
@@ -1446,7 +1458,7 @@
 .doorHangerRight:after,
 .doorHangerRight:before {
   bottom: 100%;
-  border: solid rgba(0, 0, 0, 0);
+  border: 8px solid rgba(0, 0, 0, 0);
   content: " ";
   height: 0;
   width: 0;
@@ -1454,14 +1466,40 @@
   pointer-events: none;
   opacity: var(--doorhanger-triangle-opacity-whcm);
 }
-.doorHanger:after,
+[dir="ltr"] .doorHanger:after {
+  left: 10px;
+}
+[dir="rtl"] .doorHanger:after {
+  right: 10px;
+}
+[dir="ltr"] .doorHanger:after {
+  margin-left: -8px;
+}
+[dir="rtl"] .doorHanger:after {
+  margin-right: -8px;
+}
+.doorHanger:after {
+  inset-inline-start: 10px;
+  -webkit-margin-start: -8px;
+          margin-inline-start: -8px;
+  border-bottom-color: var(--toolbar-bg-color);
+}
+[dir="ltr"] .doorHangerRight:after {
+  right: 10px;
+}
+[dir="rtl"] .doorHangerRight:after {
+  left: 10px;
+}
+[dir="ltr"] .doorHangerRight:after {
+  margin-right: -8px;
+}
+[dir="rtl"] .doorHangerRight:after {
+  margin-left: -8px;
+}
 .doorHangerRight:after {
-  border-width: 8px;
-}
-.doorHanger:after {
-  border-bottom-color: var(--toolbar-bg-color);
-}
-.doorHangerRight:after {
+  inset-inline-end: 10px;
+  -webkit-margin-end: -8px;
+          margin-inline-end: -8px;
   border-bottom-color: var(--doorhanger-bg-color);
 }
 .doorHanger:before,
@@ -1469,29 +1507,39 @@
   border-bottom-color: var(--doorhanger-border-color);
   border-width: 9px;
 }
-
-html[dir="ltr"] .doorHanger:after,
-html[dir="rtl"] .doorHangerRight:after {
+[dir="ltr"] .doorHanger:before {
   left: 10px;
-  margin-left: -8px;
-}
-
-html[dir="ltr"] .doorHanger:before,
-html[dir="rtl"] .doorHangerRight:before {
+}
+[dir="rtl"] .doorHanger:before {
+  right: 10px;
+}
+[dir="ltr"] .doorHanger:before {
+  margin-left: -9px;
+}
+[dir="rtl"] .doorHanger:before {
+  margin-right: -9px;
+}
+.doorHanger:before {
+  inset-inline-start: 10px;
+  -webkit-margin-start: -9px;
+          margin-inline-start: -9px;
+}
+[dir="ltr"] .doorHangerRight:before {
+  right: 10px;
+}
+[dir="rtl"] .doorHangerRight:before {
   left: 10px;
+}
+[dir="ltr"] .doorHangerRight:before {
+  margin-right: -9px;
+}
+[dir="rtl"] .doorHangerRight:before {
   margin-left: -9px;
 }
-
-html[dir="rtl"] .doorHanger:after,
-html[dir="ltr"] .doorHangerRight:after {
-  right: 10px;
-  margin-right: -8px;
-}
-
-html[dir="rtl"] .doorHanger:before,
-html[dir="ltr"] .doorHangerRight:before {
-  right: 10px;
-  margin-right: -9px;
+.doorHangerRight:before {
+  inset-inline-end: 10px;
+  -webkit-margin-end: -9px;
+          margin-inline-end: -9px;
 }
 
 #findResultsCount {
@@ -1607,9 +1655,7 @@
   position: relative;
 }
 html[dir="ltr"] .splitToolbarButton > .toolbarButton:first-child,
-html[dir="rtl"] .splitToolbarButton > .toolbarButton:last-child {
-  margin: 0;
-}
+html[dir="rtl"] .splitToolbarButton > .toolbarButton:last-child,
 html[dir="ltr"] .splitToolbarButton > .toolbarButton:last-child,
 html[dir="rtl"] .splitToolbarButton > .toolbarButton:first-child {
   margin: 0;
@@ -1655,15 +1701,29 @@
   box-sizing: border-box;
 }
 
-html[dir="ltr"] #toolbarViewerLeft > .toolbarButton:first-child,
-html[dir="rtl"] #toolbarViewerRight > .toolbarButton:last-child {
+[dir="ltr"] #toolbarViewerLeft > .toolbarButton:first-child {
   margin-left: 2px;
 }
 
-html[dir="ltr"] #toolbarViewerRight > .toolbarButton:last-child,
-html[dir="rtl"] #toolbarViewerLeft > .toolbarButton:first-child {
+[dir="rtl"] #toolbarViewerLeft > .toolbarButton:first-child {
   margin-right: 2px;
 }
+
+#toolbarViewerLeft > .toolbarButton:first-child {
+  -webkit-margin-start: 2px;
+          margin-inline-start: 2px;
+}
+[dir="ltr"] #toolbarViewerRight > .toolbarButton:last-child {
+  margin-right: 2px;
+}
+[dir="rtl"] #toolbarViewerRight > .toolbarButton:last-child {
+  margin-left: 2px;
+}
+#toolbarViewerRight > .toolbarButton:last-child {
+  -webkit-margin-end: 2px;
+          margin-inline-end: 2px;
+}
+
 .toolbarButton:hover,
 .toolbarButton:focus-visible {
   background-color: var(--button-hover-color);
@@ -2048,12 +2108,6 @@
   margin: 5px 2px;
   width: 1px;
   background-color: var(--separator-color);
-}
-html[dir="ltr"] .verticalToolbarSeparator {
-  margin-left: 2px;
-}
-html[dir="rtl"] .verticalToolbarSeparator {
-  margin-right: 2px;
 }
 
 .horizontalToolbarSeparator {
@@ -2080,18 +2134,21 @@
   outline-style: none;
 }
 
+[dir="ltr"] .toolbarField[type="checkbox"] {
+  margin-left: 7px;
+}
+
+[dir="rtl"] .toolbarField[type="checkbox"] {
+  margin-right: 7px;
+}
+
 .toolbarField[type="checkbox"] {
   opacity: 0;
   position: absolute !important;
   left: 0;
-}
-
-html[dir="ltr"] .toolbarField[type="checkbox"] {
-  margin: 10px 0 3px 7px;
-}
-
-html[dir="rtl"] .toolbarField[type="checkbox"] {
-  margin: 10px 7px 3px 0;
+  margin: 10px 0 3px;
+  -webkit-margin-start: 7px;
+          margin-inline-start: 7px;
 }
 
 .toolbarField.pageNumber {
@@ -2164,7 +2221,6 @@
 #thumbnailView > a:last-of-type > .thumbnail {
   margin-bottom: 10px;
 }
-
 #thumbnailView > a:last-of-type > .thumbnail:not([data-loaded]) {
   margin-bottom: 9px;
 }
@@ -2224,14 +2280,20 @@
           user-select: none;
 }
 
-html[dir="ltr"] .treeWithDeepNesting > .treeItem,
-html[dir="ltr"] .treeItem > .treeItems {
+[dir="ltr"] .treeWithDeepNesting > .treeItem,[dir="ltr"] 
+.treeItem > .treeItems {
   margin-left: 20px;
 }
 
-html[dir="rtl"] .treeWithDeepNesting > .treeItem,
-html[dir="rtl"] .treeItem > .treeItems {
+[dir="rtl"] .treeWithDeepNesting > .treeItem,[dir="rtl"] 
+.treeItem > .treeItems {
   margin-right: 20px;
+}
+
+.treeWithDeepNesting > .treeItem,
+.treeItem > .treeItems {
+  -webkit-margin-start: 20px;
+          margin-inline-start: 20px;
 }
 
 .treeItem > a {

@Snuffleupagus Snuffleupagus marked this pull request as draft March 13, 2022 19:44
@Snuffleupagus Snuffleupagus marked this pull request as ready for review March 13, 2022 20:22
@Snuffleupagus Snuffleupagus force-pushed the postcss-logical branch 2 times, most recently from fe459e0 to 6fd3338 Compare March 16, 2022 21:50
@Snuffleupagus
Copy link
Collaborator Author

/botio-linux preview

@mozilla mozilla deleted a comment from pdfjsbot Mar 16, 2022
@mozilla mozilla deleted a comment from pdfjsbot Mar 16, 2022
@mozilla mozilla deleted a comment from pdfjsbot Mar 17, 2022
@mozilla mozilla deleted a comment from pdfjsbot Mar 17, 2022
@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_preview from @Snuffleupagus received. Current queue size: 1

Live output at: http://54.241.84.105:8877/4599990d906c922/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/4599990d906c922/output.txt

Total script time: 2.54 mins

Published

…gical properties

*Please note:* This is another step in what will, time permitting, become a series of patches to simplify/modernize the viewer CSS.

Rather than having to manually specify ltr/rtl-specific margin-values in the CSS, we can use logical margin instead (and similar for some related left/right occurrences).
These logical properties depend on, among other things, the direction of the HTML document which we *always* specify in the viewer.

Given that most of these logical CSS properties are fairly new, and that cross-browser support is thus somewhat limited (see below), we need to use a couple of PostCSS plugins (see below) in order to support this in the GENERIC viewer.

 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-end#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-start#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/CSS/inset-inline-end#browser_compatibility

---

 - https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-logical
 - https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-dir-pseudo-class
@timvandermeij timvandermeij merged commit 079dea2 into mozilla:master Mar 19, 2022
@timvandermeij
Copy link
Contributor

Thank you for doing this!

@Snuffleupagus Snuffleupagus deleted the postcss-logical branch March 19, 2022 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants