/
main.ts
43 lines (33 loc) · 959 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import * as rtl from 'rtl-css-js';
const convert = rtl['default'] || rtl;
export interface JssRTLOptions {
enabled?: boolean;
opt?: 'in' | 'out';
}
export default function jssRTL({ enabled = true, opt = 'out' }: JssRTLOptions = {}) {
return {
onProcessStyle(style: any, rule: any, sheet: any) {
if (rule.type === 'font-face') {
return style;
}
if (!enabled) {
if (typeof style.flip === 'boolean') {
delete style.flip;
}
return style;
}
let flip = opt === 'out'; // If it's set to opt-out, then it should flip by default
if (typeof sheet.options.flip === 'boolean') {
flip = sheet.options.flip;
}
if (typeof style.flip === 'boolean') {
flip = style.flip;
delete style.flip;
}
if (!flip) {
return style;
}
return convert(typeof rule.toJSON === 'function' ? rule.toJSON() : style);
},
};
}