@mui/stylis-plugin-rtl
Version:
A plugin for Material UI that provides RTL (right-to-left) support.
58 lines (53 loc) • 2.35 kB
JavaScript
/**
* @mui/stylis-plugin-rtl v7.2.0
*
* @license MIT
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _cssjanus = _interopRequireDefault(require("cssjanus"));
var _stylis = require("stylis");
/* eslint-disable default-case, no-return-assign, curly, prefer-template, @typescript-eslint/no-unused-vars */
/**
* Copied from https://github.com/styled-components/stylis-plugin-rtl/blob/main/src/stylis-rtl.ts
* with a modification at line 67 to handle layer rules.
*/
// @ts-nocheck
function stringifyPreserveComments(element, index, children) {
switch (element.type) {
case _stylis.IMPORT:
case _stylis.DECLARATION:
case _stylis.COMMENT:
return element.return = element.return || element.value;
case _stylis.RULESET:
{
element.value = Array.isArray(element.props) ? element.props.join(',') : element.props;
if (Array.isArray(element.children)) {
element.children.forEach(x => {
if (x.type === _stylis.COMMENT) x.children = x.value;
});
}
}
}
const serializedChildren = (0, _stylis.serialize)(Array.prototype.concat(element.children), stringifyPreserveComments);
return (0, _stylis.strlen)(serializedChildren) ? element.return = element.value + '{' + serializedChildren + '}' : '';
}
function stylisRTLPlugin(element, index, children, callback) {
if (element.type === _stylis.KEYFRAMES || element.type === _stylis.SUPPORTS || element.type === _stylis.RULESET && (!element.parent || element.parent.type === _stylis.MEDIA || element.parent.type === _stylis.RULESET || element.parent.type === _stylis.LAYER)) {
const stringified = _cssjanus.default.transform(stringifyPreserveComments(element, index, children));
element.children = stringified ? (0, _stylis.compile)(stringified)[0].children : [];
element.return = '';
}
}
// stable identifier that will not be dropped by minification unless the whole module
// is unused
Object.defineProperty(stylisRTLPlugin, 'name', {
value: 'stylisRTLPlugin'
});
var _default = exports.default = stylisRTLPlugin;