UNPKG

chayns-components

Version:

A set of beautiful React components for developing chayns® applications.

49 lines (46 loc) 1.88 kB
"use strict"; exports.__esModule = true; exports.default = void 0; var _isServer = require("./isServer"); const ORIENTATION_PORTRAIT = 0; const ORIENTATION_LANDSCAPE = 1; const HTML = (0, _isServer.isServer)() ? undefined : document.documentElement; class OrientationHelper { constructor() { var _window$chayns, _window$chayns2; this.update = () => { const orientation = this.getOrientation(); if (orientation === ORIENTATION_LANDSCAPE) { HTML.classList.add('chayns--landscape'); HTML.classList.remove('chayns--portrait'); } else { HTML.classList.add('chayns--portrait'); HTML.classList.remove('chayns--landscape'); } }; if (!(0, _isServer.isServer)() && ((_window$chayns = window.chayns) !== null && _window$chayns !== void 0 && _window$chayns.env.isMobile || (_window$chayns2 = window.chayns) !== null && _window$chayns2 !== void 0 && _window$chayns2.env.isApp)) { window.addEventListener('orientationchange', this.update); this.update(); } } // eslint-disable-next-line class-methods-use-this getOrientation() { if (window.screen && window.screen.orientation && (window.screen.orientation.angle || window.screen.orientation.angle === 0)) { const angle = window.screen.orientation.angle % 360; if (angle === 90 || angle === 270 || angle === -90) { return ORIENTATION_LANDSCAPE; } return ORIENTATION_PORTRAIT; } if (window.orientation || window.orientation === 0) { return window.orientation === -90 || window.orientation === 90 ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT; } if (window.innerHeight > window.innerWidth) { return ORIENTATION_LANDSCAPE; } return ORIENTATION_PORTRAIT; } } var _default = new OrientationHelper(); exports.default = _default; //# sourceMappingURL=OrientationHelper.js.map