feat(theme): use native CSS for RTL instead of using rtlcss package
#5034
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 like
margin-*,padding-*,border-*,insetandtext-align.Only properties that directly handled by
rtlcss.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
The compiled CSS includes both LTR and RTL styles, as follows:
By migrating to native CSS solution, the compiled CSS is as follows:
This change reduces the CSS file size by 4%. The performance improvement decreases "Unused CSS". You can see the "Coverage" panel in you Dev Tools to verify to results.