wikimedia / node-cssjanus

↔️ Convert CSS between left-to-right and right-to-left. Mirror of https://gerrit.wikimedia.org/g/mediawiki/libs/node-cssjanus/. Contribute via https://www.mediawiki.org/wiki/Developer_account.
https://cssjanus.github.io
Apache License 2.0
204 stars 48 forks source link
css cssjanus javascript stylesheets swap

npm Tested with QUnit

CSSJanus

Convert CSS stylesheets between left-to-right and right-to-left.

Based the original Google project.

See Interactive demo.

Install

npm install cssjanus

Usage

var cssjanus = require( 'cssjanus' );
var rtlCss = cssjanus.transform( ltrCss );
transform( string css [, Object options ] ) : string

Parameters:

Preventing flipping

If a rule is not meant to be flipped by CSSJanus, use a /* @noflip */ comment to protect the rule.

.rule1 {
  /* Will be converted to margin-right */
  margin-left: 1em;
}
/* @noflip */
.rule2 {
  /* Will be preserved as margin-left */
  margin-left: 1em;
}

CSS Logical

We encourage and recommend use of CSS logical properties for the subset of CSS features where a native direction-aware version of a CSS property exists (be sure to check browser support for specific properties). You can, for example, set properties like margin-inline-start instead of margin-left, which the browser flips based on content direction, and work seamlessly alongside other CSS properties that CSSJanus flips instead.

Note that CSS logical properties flip based on nearest content direction and content language, whereas CSSJanus is generally configured to flip by user language and UI direction.

Integrations

Who uses CSSJanus?

See also

Contribute