Skip to content

Refactor logical properties to use :dir/:lang#131

Merged
devongovett merged 4 commits intomasterfrom
logical-refactor
Apr 5, 2022
Merged

Refactor logical properties to use :dir/:lang#131
devongovett merged 4 commits intomasterfrom
logical-refactor

Conversation

@devongovett
Copy link
Member

The previous approach to compiling logical properties used CSS variables with some clever tricks to define conditional styles for ltr and rtl. However, it had an issue where CSS variables that are invalid cause the property using them to be reset to their initial value rather than the cascaded value. This is the invalid at computed value time part of the spec.

This changes our approach to instead use the :dir selector instead. However, this is not supported by any browsers other than Firefox, so we fall back to :lang using a hard-coded list of RTL languages. This isn't perfect, but it's possibly the best we can do. Using an attribute selector (e.g. [dir="ltr"]) doesn't work right either because it affects nested elements too (e.g. rtl inside ltr inside rtl). :lang is inherited correctly, just like :dir, and is much more widely supported.

In addition to downleveling :dir to :lang, we also downlevel :lang when it is passed a list of languages rather than a single one. Support for multiple languages was added in Selectors Level 4, and is currently only supported in WebKit. For other browsers, we use :is with multiple :lang selectors inside, or :not for the opposite case.

We also now downlevel :is to the older :-webkit-any and :-moz-any pseudo classes. However, these only support simple selectors (no combinators), so if a combinator is seen, we bail out. Fixes #19.

…into logical-refactor

# Conflicts:
#	selectors/builder.rs
#	selectors/matching.rs
#	selectors/parser.rs
#	src/context.rs
#	src/lib.rs
#	src/logical.rs
#	src/properties/border.rs
#	src/properties/border_radius.rs
#	src/properties/mod.rs
#	src/rules/mod.rs
#	src/selector.rs
#	src/stylesheet.rs
#	src/vendor_prefix.rs
@devongovett devongovett merged commit b6a4744 into master Apr 5, 2022
@devongovett devongovett deleted the logical-refactor branch April 5, 2022 02:28
@bakura10
Copy link

Hi :),

It seems that when using target>0.5%, the following CSS is generated:

image

text-align: start/end are supported from Safari 3 according to CanIUse, so this should likely not be needed here. Is there a way to keep the simple start/end or at least having a setting here?

@bakura10
Copy link

bakura10 commented May 3, 2022

EDIT: apparently I was too broad with >0.5%, and this compiled for browser we do not target. I changed it to "safari 13" and the markup is now much more simple :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Downlevel :is

2 participants