-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Add support for CSS variables using the PostCSS CSS Variables
package (issue 11462)
#11567
Conversation
2b1f65f
to
1205e04
Compare
From: Bot.io (Linux m4)ReceivedCommand cmd_preview from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.67.70.0:8877/f5070d8c5daf49d/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/f5070d8c5daf49d/output.txt Total script time: 1.77 mins Published |
Sign, it seems that IE11 cannot handle We could possibly use another PostCSS package to solve that, but then again maybe not since I just found postcss/postcss-calc#87 :-( |
… element to enable IE11 compatibility As gross as this hack is, it nonetheless seem necessary to allow using CSS variables; see also mozilla#11567 (comment)
704bcc7
to
84258f7
Compare
From: Bot.io (Linux m4)ReceivedCommand cmd_preview from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.67.70.0:8877/c176f1ec14d0963/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/c176f1ec14d0963/output.txt Total script time: 1.77 mins Published |
… element to enable IE11 compatibility As gross as this hack is, it nonetheless seem necessary to allow using CSS variables; see also mozilla#11567 (comment)
84258f7
to
b81054b
Compare
From: Bot.io (Linux m4)ReceivedCommand cmd_preview from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.67.70.0:8877/ab9cdcfbd5d2c0b/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/ab9cdcfbd5d2c0b/output.txt Total script time: 1.68 mins Published |
…ge (issue 11462) Having thought *briefly* about using `css-vars-ponyfill`, I'm no longer convinced that it'd be a good idea. The reason is that if we actually want to properly support CSS variables, then that functionality should be available in *all* of our CSS files. Note in particular the `pdf_viewer.css` file that's built as part of the `COMPONENTS` target, in which case I really cannot see how a rewrite-at-the-client solution would ever be guaranteed to always work correctly and without accidentally touching other CSS in the surrounding application. All-in-all, simply re-writing the CSS variables at build-time seems much easier and is thus the approach taken in this patch; courtesy of /~https://github.com/MadLittleMods/postcss-css-variables By using its `preserve` option, the built files will thus include *both* a fallback and a modern `var(...)` format[1]. As a proof-of-concept this patch removes a couple of manually added fallback values, and converts an additional sidebar related property to use a CSS variable. --- [1] Comparing the `master` branch with this patch, when using `gulp generic`, produces the following diff for the built `web/viewer.css` file: ```diff @@ -408,6 +408,7 @@ :root { --sidebar-width: 200px; + --sidebar-transition-duration: 200ms; } * { @@ -550,27 +551,28 @@ position: absolute; top: 32px; bottom: 0; - width: 200px; /* Here, and elsewhere below, keep the constant value for compatibility - with older browsers that lack support for CSS variables. */ + width: 200px; width: var(--sidebar-width); visibility: hidden; z-index: 100; border-top: 1px solid rgba(51, 51, 51, 1); -webkit-transition-duration: 200ms; transition-duration: 200ms; + -webkit-transition-duration: var(--sidebar-transition-duration); + transition-duration: var(--sidebar-transition-duration); -webkit-transition-timing-function: ease; transition-timing-function: ease; } html[dir='ltr'] #sidebarContainer { -webkit-transition-property: left; transition-property: left; - left: -200px; + left: calc(-1 * 200px); left: calc(-1 * var(--sidebar-width)); } html[dir='rtl'] #sidebarContainer { -webkit-transition-property: right; transition-property: right; - right: -200px; + right: calc(-1 * 200px); right: calc(-1 * var(--sidebar-width)); } @@ -640,6 +642,8 @@ #viewerContainer:not(.pdfPresentationMode) { -webkit-transition-duration: 200ms; transition-duration: 200ms; + -webkit-transition-duration: var(--sidebar-transition-duration); + transition-duration: var(--sidebar-transition-duration); -webkit-transition-timing-function: ease; transition-timing-function: ease; } ```
… element to enable IE11 compatibility As gross as this hack is, it nonetheless seem necessary to allow using CSS variables; see also mozilla#11567 (comment)
b81054b
to
1021425
Compare
From: Bot.io (Linux m4)ReceivedCommand cmd_preview from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.67.70.0:8877/7e46a92fbb7f6fb/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/7e46a92fbb7f6fb/output.txt Total script time: 1.70 mins Published |
This seems to work now, even in IE11, without anything being obviously broken :-) Once this's landed we should thus be free to use CSS variables to simplify/re-factor the existing rules (and obviously when adding new rules), however I don't intend to convert more rules in this PR since the changes are mostly for proof-of-concept reasons and to allow validation of the overall approach. |
Looks good! I'm glad that we can start using CSS variables properly now. |
Having thought briefly about using
css-vars-ponyfill
, I'm no longer convinced that it'd be a good idea. The reason is that if we actually want to properly support CSS variables, then that functionality should be available in all of our CSS files.Note in particular the
pdf_viewer.css
file that's built as part of theCOMPONENTS
target, in which case I really cannot see how a rewrite-at-the-client solution would ever be guaranteed to always work correctly and without accidentally touching other CSS in the surrounding application.All-in-all, simply re-writing the CSS variables at build-time seems much easier and is thus the approach taken in this patch; courtesy of /~https://github.com/MadLittleMods/postcss-css-variables
By using its
preserve
option, the built files will thus include both a fallback and a modernvar(...)
format[1]. As a proof-of-concept this patch removes a couple of manually added fallback values, and converts an additional sidebar related property to use a CSS variable.Fixes #11462
[1] Comparing the
master
branch with this patch, when usinggulp generic
, produces the following diff for the builtweb/viewer.css
file: