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C,CAAC,CAAC,KAAK,CAAC,CAAC;KAChE;IAED,IAAI,cAAc,EAAE;QAClB,wBAAO,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;KACnD;IAED,MAAM,GAAG,KAAK,CAAC;IACf,qBAAiB,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAZD,wBAYC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,GAAW,EAAE,KAA6B;IAA7B,sBAAA,EAAA,UAA6B;IAC1E,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;QACjB,IAAI,GAAG,KAAK,mBAAQ,CAAC,IAAI,EAAE;YACzB,GAAG,GAAG,mBAAQ,CAAC,KAAK,CAAC;SACtB;aAAM,IAAI,GAAG,KAAK,mBAAQ,CAAC,KAAK,EAAE;YACjC,GAAG,GAAG,mBAAQ,CAAC,IAAI,CAAC;SACrB;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAVD,8CAUC","sourcesContent":["import { KeyCodes } from './KeyCodes';\nimport { getDocument } from './dom/getDocument';\nimport { getItem, setItem } from './sessionStorage';\nimport { setRTL as mergeStylesSetRTL } from '@uifabric/merge-styles';\n\nconst RTL_LOCAL_STORAGE_KEY = 'isRTL';\n\n// Default to undefined so that we initialize on first read.\nlet _isRTL: boolean | undefined;\n\n/**\n * Gets the rtl state of the page (returns true if in rtl.)\n */\nexport function getRTL(theme: { rtl?: boolean } = {}): boolean {\n if (theme.rtl !== undefined) {\n return theme.rtl;\n }\n if (_isRTL === undefined) {\n // Fabric supports persisting the RTL setting between page refreshes via session storage\n let savedRTL = getItem(RTL_LOCAL_STORAGE_KEY);\n if (savedRTL !== null) {\n _isRTL = savedRTL === '1';\n setRTL(_isRTL);\n }\n\n let doc = getDocument();\n if (_isRTL === undefined && doc) {\n _isRTL = ((doc.body && doc.body.getAttribute('dir')) || doc.documentElement.getAttribute('dir')) === 'rtl';\n mergeStylesSetRTL(_isRTL);\n }\n }\n\n return !!_isRTL;\n}\n\n/**\n * Sets the rtl state of the page (by adjusting the dir attribute of the html element.)\n */\nexport function setRTL(isRTL: boolean, persistSetting: boolean = false): void {\n let doc = getDocument();\n if (doc) {\n doc.documentElement.setAttribute('dir', isRTL ? 'rtl' : 'ltr');\n }\n\n if (persistSetting) {\n setItem(RTL_LOCAL_STORAGE_KEY, isRTL ? '1' : '0');\n }\n\n _isRTL = isRTL;\n mergeStylesSetRTL(_isRTL);\n}\n\n/**\n * Returns the given key, but flips right/left arrows if necessary.\n */\nexport function getRTLSafeKeyCode(key: number, theme: { rtl?: boolean } = {}): number {\n if (getRTL(theme)) {\n if (key === KeyCodes.left) {\n key = KeyCodes.right;\n } else if (key === KeyCodes.right) {\n key = KeyCodes.left;\n }\n }\n\n return key;\n}\n"]} |