feat(theme): use native CSS for RTL instead of using rtlcss package#5034
Open
rami-elementor wants to merge 17 commits intovuejs:mainfrom
Open
feat(theme): use native CSS for RTL instead of using rtlcss package#5034rami-elementor wants to merge 17 commits intovuejs:mainfrom
rtlcss package#5034rami-elementor wants to merge 17 commits intovuejs:mainfrom
Conversation
commit: |
15a0278 to
09af6c7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Currently, VitePress is using
rtlcsspackage to manage styles based on writing-direction. It creates two sets of styles, for LTR and RTL styles, one for each direction. This is not necessary, with some adjustments we can support styling for both writing direction, natively.The simplest example for native RTL support is the text align:
With direction‐relative equivalents like
start/endinstead ofleft/right, we reduce the difference between LTR and RTL view. The browser decides how to align the text based on the writing direction.The end goal is to stop using the
rtlcsspackage. It will not only delegate the page direction management to the browser, but also improve frontend performance, optimize the CI/CD by removing uneasy steps, and reducing build time.PR Fucos
This PR focuses only in RTL support, which is a subset of the Logical Properties. It's not a full migration to logical properties.
The focus is on properties that directly handled by
rtlcss, likemargin-*,padding-*,border-*,insetandtext-align. It doesn't changewidth,heightand other properties which are not related to RTL.Additional Context
We use CSS logical properties and values to handle direction, but not all CSS properties have logical equivalents. In these cases we use the
--vp-direction-multiplierto help with the writing direction.This helps
rotateor translate on the X-axis to the correct directions based on the writing language.The element will be rotated by
45degin LTR, and-45degin RTL.Testing
I recommend using the "RTL toggle" chrome extension to track issues. It simply changes the
dir="ltr|rtl"attribute on the<html>element.Performance
Currently, the compiled CSS includes both LTR and RTL styles:
After migrating to native CSS, the compiled CSS is much smaller:
This change reduces the CSS file size by 4%. It also decreases "Unused CSS", You can see the "Coverage" panel in your Dev Tools to verify the results. Overall, it improves performance for both LTR and RTL users.
Docs Update
The docs mention some specificity issues:
When we fully migrate away from automated
rtlcss, this paragraph can be removed from the docs.