Skip to content

Commit 08ca0f5

Browse files
committed
More improvements and fixes in the documentation
1 parent b742f90 commit 08ca0f5

File tree

2 files changed

+42
-84
lines changed

2 files changed

+42
-84
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [5.6.0] - 2024-12-13
44

55
- Add new directives to freeze rules and declarations `/*rtl:freeze*/`, `/*rtl:begin:freeze*/` and `/*rtl:end:freeze*/`
6+
- Remove references to the legacy package
67

78
## [5.5.1] - 2024-11-24
89

README.md

Lines changed: 41 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,19 @@ Install
2424
#### npm
2525

2626
```bash
27-
## Latest version (postcss@^8.0.0)
2827
npm install postcss-rtlcss --save-dev
29-
30-
## Latest legacy version (postcss@^7.0.0)
31-
npm install postcss-rtlcss@legacy --save-dev
3228
```
3329

3430
#### pnpm
3531

3632
```bash
37-
## Latest version (postcss@^8.0.0)
3833
pnpm add -D postcss-rtlcss
39-
40-
## Latest legacy version (postcss@^7.0.0)
41-
pnpm add -D postcss-rtlcss@legacy
4234
```
4335

4436
#### yarn
4537

4638
```bash
47-
## Latest version (postcss@^8.0.0)
4839
yarn add postcss-rtlcss -D
49-
50-
## Latest legacy version (postcss@^7.0.0)
51-
yarn add postcss-rtlcss@legacy -D
5240
```
5341

5442
Basic usage
@@ -69,11 +57,6 @@ const result = postcss([
6957
const rtlCSS = result.css;
7058
```
7159

72-
##### commonJS with the versions 1.x.x - 2.x.x
73-
```javascript
74-
const { postcssRTLCSS, Mode, Source, Autorename } = require('postcss-rtlcss');
75-
```
76-
7760
#### Usage with ES6 modules
7861

7962
```javascript
@@ -89,12 +72,6 @@ const result = postcss([
8972
const rtlCSS = result.css;
9073
```
9174

92-
##### ES6 modules with the versions 1.x.x - 2.x.x
93-
94-
```javascript
95-
import { postcssRTLCSS, Mode, Source, Autorename } from 'postcss-rtlcss';
96-
```
97-
9875
#### Usage in Webpack with postcss-loader
9976

10077
```javascript
@@ -146,7 +123,7 @@ Examples
146123

147124
#### Output using the combined mode (default and recommended)
148125

149-
This is the recommended method, it will generate more CSS code but each direction will have their specific CSS declarations and there is no need of overriding properties.
126+
This is the recommended method, it will generate more CSS code because each direction will have their specific prefixed rules but it is the safest option.
150127

151128
```css
152129
.test1, .test2 {
@@ -188,7 +165,7 @@ This is the recommended method, it will generate more CSS code but each directio
188165
#### Output using the override mode
189166

190167
>[!IMPORTANT]
191-
>This method is not recommended, check below why
168+
>This method is not recommended, [check below why](#disadvantages-of-the-two-methods-to-override)
192169
193170
This is one of the alternative methods to override. It will generate less code because it lets the main rule intact most of the time and generates shorter specific rules to override the properties that are affected by the direction of the text.
194171

@@ -227,7 +204,7 @@ This is one of the alternative methods to override. It will generate less code b
227204
#### Output using the diff mode
228205

229206
>[!IMPORTANT]
230-
>This method is not recommended, check below why
207+
>This method is not recommended, [check below why](#disadvantages-of-the-two-methods-to-override)
231208
232209
This is the second alternative method to override. It generates the minimum amount of code because it only outputs the rules that have been flipped and without prefixing them. The intention of this method is to generate a separate stylesheet file that will be loaded on top of the original one to override those rules that need to be flipped in certain direction.
233210

@@ -245,13 +222,7 @@ This is the second alternative method to override. It generates the minimum amou
245222
}
246223
```
247224

248-
>[!IMPORTANT]
249-
>But the two methods to override have disadvantages:
250-
251-
<details><summary>Disadvantages of the override methods</summary>
252-
<p>
253-
254-
The methods to override are discouraged because:
225+
#### Disadvantages of the two methods to override
255226

256227
1. Some directives as `/*rtl:freeze*/`, `/*rtl:begin:freeze*/` and `/*rtl:end:freeze*/` do not work with these methods
257228
2. They can override a property that is coming from another class if multiple classes are used at the same time. Take a look at the next `HTML` and `CSS` codes:
@@ -366,10 +337,7 @@ And using the `diff` method the generated code will be:
366337
}
367338
```
368339

369-
</p>
370-
</details>
371-
372-
Options
340+
Plugin Options
373341
---
374342

375343
All the options are optional, and a default value will be used if any of them is omitted or the type or format of them is wrong
@@ -380,19 +348,19 @@ All the options are optional, and a default value will be used if any of them is
380348
| [ltrPrefix](#ltrprefix-and-rtlprefix) | `string` or `string[]` | `[dir="ltr"]` | Prefix to use in the left-to-right CSS rules |
381349
| [rtlPrefix](#ltrprefix-and-rtlprefix) | `string` or `string[]` | `[dir="rtl"]` | Prefix to use in the right-to-left CSS rules |
382350
| [bothPrefix](#bothprefix) | `string` or `string[]` | `[dir]` | Prefix to create a new rule that affects both directions when the specificity of the ltr or rtl rules will override its declarations |
383-
| [prefixSelectorTransformer](#prefixselectortransformer) | `function` | `null` | Transform function to have more control over the selectors prefixing logic |
351+
| [prefixSelectorTransformer](#prefixselectortransformer) | `function` | `null` | Transform function to have more control over the selectors prefixing logic |
384352
| [safeBothPrefix](#safebothprefix) | `boolean` | `false` | Add the `bothPrefix` to those declarations that can be affected by the direction to avoid them being overridden by specificity |
385-
| [ignorePrefixedRules](#ignoreprefixedrules) | `boolean` | true | Ignores rules that have been prefixed with some of the prefixes contained in `ltrPrefix`, `rtlPrefix`, or `bothPrefix` |
353+
| [ignorePrefixedRules](#ignoreprefixedrules) | `boolean` | `true` | Ignores rules that have been prefixed with some of the prefixes contained in `ltrPrefix`, `rtlPrefix`, or `bothPrefix` |
386354
| [source](#source) | `Source (string)` | `Source.ltr` | The direction from which the final CSS will be generated |
387-
| [processUrls](#processurls) | `boolean` | `false` | Change the strings in URLs using the string map |
355+
| [processUrls](#processurls) | `boolean` | `false` | Change the strings in URLs using the string map |
388356
| [processRuleNames](#processrulenames) | `boolean` | `false` | Swap two rules containing no directional properties if they match any entry in `stringMap` when the direction changes |
389357
| [processKeyFrames](#processkeyframes) | `boolean` | `false` | Flip keyframe animations |
390358
| [processEnv](#processenv) | `boolean` | `true` | When processEnv is false, it prevents flipping agent-defined environment variables (`safe-area-inset-left` and `safe-area-inset-right`) |
391359
| [useCalc](#usecalc) | `boolean` | `false` | Flips `background-position-x` and `transform-origin` properties if they are expressed in length units using [calc](https://developer.mozilla.org/en-US/docs/Web/CSS/calc) |
392-
| [stringMap](#stringmap) | `PluginStringMap[]` | Check below | An array of strings maps that will be used to make the replacements of the declarations' URLs and to match the names of the rules if `processRuleNames` is `true` |
360+
| [stringMap](#stringmap) | `PluginStringMap[]` | [Check below](#stringmap) | An array of strings maps that will be used to make the replacements of the declarations' URLs and to match the names of the rules if `processRuleNames` is `true` |
393361
| [greedy](#greedy) | `boolean` | `false` | When greedy is `true`, the matches of `stringMap` will not take into account word boundaries |
394-
| [aliases](#aliases) | `Record<string, string>` | `{}` | A strings map to treat some declarations as others |
395-
| [processDeclarationPlugins](#processdeclarationplugins) | `DeclarationPlugin[]` | `[]` | Plugins applied when processing CSS declarations |
362+
| [aliases](#aliases) | `Record<string, string>` | `{}` | A strings map to treat some declarations as others |
363+
| [processDeclarationPlugins](#processdeclarationplugins) | `DeclarationPlugin[]` | `[]` | Plugins applied when processing CSS declarations |
396364

397365
---
398366

@@ -571,7 +539,7 @@ This function will be used to transform the selectors and prefixing them at our
571539

572540
>[!NOTE]
573541
>* If the function doesn‘t return a string, the default prefixing logic will be used.
574-
>* If this function is used, be aware that rules using `html`, `:root` or `:::view-transition` will follow the custom prefixing logic. You should cover these cases.
542+
>* If this function is used, be aware that rules using `html`, `:root` or `::view-transition` will follow the custom prefixing logic. You should cover these cases.
575543
576544
##### input
577545

@@ -1298,9 +1266,6 @@ const options = {
12981266

12991267
This property consists of a string map to treat some declarations as others, very useful to flip the values of [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties).
13001268

1301-
>[!NOTE]
1302-
>This property is not available in the legacy version of the package
1303-
13041269
##### input
13051270

13061271
```css
@@ -1412,24 +1377,24 @@ Control directives are placed between rules or declarations. They can target a s
14121377
>[!IMPORTANT]
14131378
>Block directives (the ones that start with `begin` and end with `end`) should be placed outside rules to apply the directive to multiple rules or inside a rule to apply the directive to multiple declarations. You should not place the begin of a directive outside a rule and the end inside one (or vice versa) or you will get undesired results.
14141379
1415-
| Directive | Description |
1416-
| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
1417-
| [/\*rtl:ignore\*/](#rtlignore) | Ignores processing of the following rule or declaration |
1418-
| [/\*rtl:begin:ignore\*/](#rtlbeginignore-and-rtlendignore) | Starts an ignoring block |
1419-
| [/\*rtl:end:ignore\*/](#rtlbeginignore-and-rtlendignore) | Ends an ignoring block |
1420-
| [/\*rtl:freeze\*/](#rtlfreeze) | Freezes the rule or declaration in the current direction but does nothing with the counterpart direction if there are flippable declarations |
1421-
| [/\*rtl:begin:freeze\*/](#rtlbeginfreeze-and-rtlendfreeze) | Starts a freeze block |
1422-
| [/\*rtl:end:freeze\*/](#rtlbeginfreeze-and-rtlendfreeze) | Ends a freeze block |
1423-
| [/\*rtl:urls\*/](#rtlurls) | This directive set the `processUrls` option to `true` in the next declaration or in the declarations of the next rule no mattering the value of the global `processUrls` option |
1424-
| [/\*rtl:begin:urls\*/](#rtlbeginrules-and-rtlendrules) | Starts a `processUrls` block block |
1425-
| [/\*rtl:end:urls\*/](#rtlbeginrules-and-rtlendrules) | Ends a `processUrls` block block |
1426-
| [/\*rtl:rules\*/](#rtlrules) | This directive set the `processRuleNames` option to `true` in the next rule no mattering the value of the global `processRuleNames` option |
1427-
| [/\*rtl:begin:rules\*/](#rtlbeginrules-and-rtlendrules) | Starts a `processRuleNames` block block |
1428-
| [/\*rtl:end:rules\*/](#rtlbeginrules-and-rtlendrules) | Ends a `processRuleNames` block block |
1429-
| [/\*rtl:source:{source}\*/](#rtlsourcesource)| Set the source of a rule or a declaration no mattering the value of the `source` property |
1430-
| [/\*rtl:begin:source:{source}\*/](#rtlbeginsourcesource-and-rtlendsource) | Starts a source block |
1431-
| [/\*rtl:end:source\*/](#rtlbeginsourcesource-and-rtlendsource) | Ends a source block |
1432-
| [/\*rtl:raw:{CSS}\*/](#rtlrawcss) | Parses the `CSS` parameter and inserts it in its place. Depending on the `source` parameter the parsed `CSS` will be treated as `rtl` or `ltr` |
1380+
| Directive | Description |
1381+
| -------------------------------------------------------------- | ------------------------------------------------------- |
1382+
| [/\*rtl:ignore\*/](#rtlignore) | Ignores processing of the following rule or declaration |
1383+
| [/\*rtl:begin:ignore\*/](#rtlbeginignore-and-rtlendignore) | Starts an ignoring block |
1384+
| [/\*rtl:end:ignore\*/](#rtlbeginignore-and-rtlendignore) | Ends an ignoring block |
1385+
| [/\*rtl:freeze\*/](#rtlfreeze) | Freezes the rule or declaration in the current direction but does nothing with the counterpart direction if there are flippable declarations |
1386+
| [/\*rtl:begin:freeze\*/](#rtlbeginfreeze-and-rtlendfreeze) | Starts a freeze block |
1387+
| [/\*rtl:end:freeze\*/](#rtlbeginfreeze-and-rtlendfreeze) | Ends a freeze block |
1388+
| [/\*rtl:urls\*/](#rtlurls) | This directive set the `processUrls` option to `true` in the next declaration or in the declarations of the next rule no mattering the value of the global `processUrls` option |
1389+
| [/\*rtl:begin:urls\*/](#rtlbeginrules-and-rtlendrules) | Starts a `processUrls` block block |
1390+
| [/\*rtl:end:urls\*/](#rtlbeginrules-and-rtlendrules) | Ends a `processUrls` block block |
1391+
| [/\*rtl:rules\*/](#rtlrules) | This directive set the `processRuleNames` option to `true` in the next rule no mattering the value of the global `processRuleNames` option |
1392+
| [/\*rtl:begin:rules\*/](#rtlbeginrules-and-rtlendrules) | Starts a `processRuleNames` block block |
1393+
| [/\*rtl:end:rules\*/](#rtlbeginrules-and-rtlendrules) | Ends a `processRuleNames` block block |
1394+
| [/\*rtl:source:{source}\*/](#rtlsourcesource) | Set the source of a rule or a declaration no mattering the value of the `source` property |
1395+
| [/\*rtl:begin:source:{source}\*/](#rtlbeginsourcesource-and-rtlendsource) | Starts a source block |
1396+
| [/\*rtl:end:source\*/](#rtlbeginsourcesource-and-rtlendsource) | Ends a source block |
1397+
| [/\*rtl:raw:{CSS}\*/](#rtlrawcss) | Parses the `CSS` parameter and inserts it in its place. Depending on the `source` parameter the parsed `CSS` will be treated as `rtl` or `ltr` |
14331398

14341399
---
14351400

@@ -1562,13 +1527,9 @@ Ignoring multiple declarations:
15621527
## /\*rtl:freeze\*/
15631528

15641529
>[!IMPORTANT]
1565-
>1. This directive only works in `combined` mode. If you use it in `override` or `diff` mode it will be ignored.
1566-
>2. If you use this directive with declarations that are not affected by page direction, it is recommended that you set the [safeBothPrefix](#safebothprefix) option in `true`.
1567-
1568-
>[!NOTE]
1569-
>This directive is not available in the legacy version of tha package
1530+
>This directive only works in `combined` mode. If you use it in `override` or `diff` modes it will be ignored.
15701531
1571-
This directive freezes the rule or declaration in the current direction but does nothing with the counterpart direction if there are flippable declarations. When used with a rule, it will freeze it in the current direction even if it is doesn't contain flippable declarations. When it is used in a declration, it will freeze the declaration in the current direction even if it is not flippable.
1532+
This directive freezes the rule or declaration in the current direction but does nothing with the counterpart direction. When used with a rule, it will freeze it in the current direction even if it is doesn't contain flippable declarations. When it is used in a declration, it will freeze the declaration in the current direction even if it is not flippable.
15721533

15731534
##### input
15741535

@@ -1614,13 +1575,9 @@ This directive freezes the rule or declaration in the current direction but does
16141575
## /\*rtl:begin:freeze\*/ and /\*rtl:end:freeze\*/
16151576

16161577
>[!IMPORTANT]
1617-
>1. This directive only works in `combined` mode. If you use it in `override` or `diff` mode it will be ignored.
1618-
>2. If you use these directives with declarations that are not affected by page direction, it is recommended that you set the [safeBothPrefix](#safebothprefix) option in `true`.
1619-
1620-
>[!NOTE]
1621-
>These directives are not available in the legacy version of tha package
1578+
>This directive only works in `combined` mode. If you use it in `override` or `diff` modes it will be ignored.
16221579
1623-
These directives should be used together, they will provide the beginning and the end for freezing rules or declarations. The rules or delclarations between these blocks, will be frozen in the current direction even if there are no flippable declarations involved.
1580+
These directives should be used together, they will provide the beginning and the end for freezing rules or declarations. The rules or declarations between these blocks, will be frozen in the current direction even if there are no flippable declarations involved.
16241581

16251582
Freezing multiple rules:
16261583

@@ -2046,13 +2003,13 @@ Value Directives
20462003

20472004
Value directives are placed anywhere inside the declaration value. They target the containing declaration node.
20482005

2049-
| Directive | Description |
2050-
| ------------------------ | -------------------------------------------------------------------------------- |
2051-
| [/\*rtl:ignore\*/](#rtlignore-1) | Ignores processing of the declaration |
2052-
| [/\*rtl:append{value}\*/](#rtlappendvalue) | Appends `{value}` to the end of the declaration value |
2053-
| [/\*rtl:insert:{value}\*/](#rtlinsertvalue) | Inserts `{value}` to where the directive is located inside the declaration value |
2054-
| [/\*rtl:prepend:{value}\*/](#rtlprependvalue)| Prepends `{value}` to the begining of the declaration value |
2055-
| [/\*rtl:{value}\*/](#rtlvalue) | Replaces the declaration value with `{value}` |
2006+
| Directive | Description |
2007+
| --------------------------------------------- | -------------------------------------------------------------------------------- |
2008+
| [/\*rtl:ignore\*/](#rtlignore-1) | Ignores processing of the declaration |
2009+
| [/\*rtl:append{value}\*/](#rtlappendvalue) | Appends `{value}` to the end of the declaration value |
2010+
| [/\*rtl:insert:{value}\*/](#rtlinsertvalue) | Inserts `{value}` to where the directive is located inside the declaration value |
2011+
| [/\*rtl:prepend:{value}\*/](#rtlprependvalue) | Prepends `{value}` to the begining of the declaration value |
2012+
| [/\*rtl:{value}\*/](#rtlvalue) | Replaces the declaration value with `{value}` |
20562013

20572014
---
20582015

0 commit comments

Comments
 (0)