Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit d4b09d4

Browse files
committed
Update Plugin: Support presumed "dir" option
1 parent a76e3f8 commit d4b09d4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ module.exports = postcss.plugin('postcss-dir-pseudo-class', (opts) => (root) =>
3333
// conditionally prepend a combinator before inserting the [dir] attribute
3434
const first = selector.nodes[0];
3535
const firstIsSpaceCombinator = first && 'combinator' === first.type && ' ' === first.value;
36+
const firstIsRoot = first && 'pseudo' === first.type && ':root' === first.value;
3637

37-
if (first && !firstIsSpaceCombinator) {
38+
if (first && !firstIsRoot && !firstIsSpaceCombinator) {
3839
selector.prepend(
3940
selectorParser.combinator({
4041
value: ' '
@@ -45,9 +46,16 @@ module.exports = postcss.plugin('postcss-dir-pseudo-class', (opts) => (root) =>
4546
// value of the :dir pseudo-class
4647
const value = node.nodes.toString();
4748

48-
// prepend the dir attribute
49+
// whether that value matches the presumed direction
50+
const isdir = opts && Object(opts).dir === value;
51+
4952
selector.prepend(
50-
selectorParser.attribute({
53+
// prepend :root if the direction is presumed
54+
isdir ? selectorParser.pseudo({
55+
value: ':root'
56+
})
57+
// otherwise, prepend the dir attribute
58+
: selectorParser.attribute({
5159
attribute: 'dir',
5260
operator: '=',
5361
value: `"${ value }"`

0 commit comments

Comments
 (0)