UNPKG

@carbon/utilities

Version:

Utilities and helpers to drive consistency across software products using the Carbon Design System

2 lines (1 loc) 593 B
const t=typeof document<"u";let o=t?document.documentElement.lang:"",i=!1,n=[],r=!1;function s(){t&&(i||(i=!0,queueMicrotask(()=>{i=!1;const e=document.documentElement.lang;if(e!==o){o=e;for(const u of n)u(e)}})))}function c(){if(!t||r)return;r=!0,new MutationObserver(s).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})}function a(){return t&&(document.documentElement.lang||window.navigator.language)||""}function l(e){return t?(r||c(),n.push(e),()=>{n=n.filter(u=>u!==e),n.length===0&&(r=!1)}):()=>{}}export{a as getDocumentLang,l as subscribeDocumentLangChange};