phanpy/src/utils/is-rtl.js

28 lines
686 B
JavaScript
Raw Normal View History

2024-08-04 07:32:30 +02:00
let IS_RTL = false;
// Use MutationObserver to detect RTL
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'attributes') {
2024-08-09 10:19:23 +02:00
const { dir } = mutation.target;
if (dir === 'rtl') {
2024-08-04 07:32:30 +02:00
IS_RTL = true;
} else {
IS_RTL = false;
}
2024-08-09 10:19:23 +02:00
console.log({ IS_RTL });
2024-08-04 07:32:30 +02:00
// Fire custom event 'dirchange' on document
// document.dispatchEvent(new Event('dirchange'));
}
});
});
observer.observe(document.documentElement, {
attributes: true,
attributeFilter: ['dir'],
});
export default function isRTL() {
return IS_RTL;
// return document.documentElement.dir === 'rtl';
}