Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getRTL(theme: { rtl?: boolean } = {}): boolean {
if (theme.rtl !== undefined) {
return theme.rtl;
}
if (_isRTL === undefined) {
// Fabric supports persisting the RTL setting between page refreshes via session storage
let savedRTL = getItem(RTL_LOCAL_STORAGE_KEY);
if (savedRTL !== null) {
_isRTL = savedRTL === '1';
setRTL(_isRTL);
}
let doc = getDocument();
if (_isRTL === undefined && doc) {
_isRTL = ((doc.body && doc.body.getAttribute('dir')) || doc.documentElement.getAttribute('dir')) === 'rtl';
mergeStylesSetRTL(_isRTL);
}
}
return !!_isRTL;
}
export function setRTL(isRTL: boolean, persistSetting: boolean = false): void {
let doc = getDocument();
if (doc) {
doc.documentElement.setAttribute('dir', isRTL ? 'rtl' : 'ltr');
}
if (persistSetting) {
setItem(RTL_LOCAL_STORAGE_KEY, isRTL ? '1' : '0');
}
_isRTL = isRTL;
mergeStylesSetRTL(_isRTL);
}