svelte-viewport-info
Version:
informs about viewport size and orientation
3 lines (2 loc) • 2.41 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self,function(){var n=e.Viewport,a=e.Viewport=t();a.noConflict=function(){return e.Viewport=n,a}}())}(this,(function(){"use strict";var e=window.matchMedia||window.webkitMatchmedia||window.mozMatchmedia||window.oMatchmedia;function t(t){return null!=e&&e(t).matches}function n(){return"interactive"===document.readyState||"complete"===document.readyState}var a=0,i=0;function o(){a=Math.max(document.documentElement.clientWidth||0,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight||0,window.innerHeight||0)}o();var r=void 0,d=void 0;function c(){var e,o;switch("orientation"in window.Screen&&(e=window.screen.orientation.type),e){case"portrait-primary":case"portrait-secondary":r="portrait",d=e;break;case"landscape-primary":case"landscape-secondary":r="landscape",d=e;break;default:switch(!0){case t("(orientation:portrait)"):r="portrait";break;case t("(orientation:landscape)"):case a>i:r="landscape";break;default:r="portrait"}d=void 0}if(n()){switch(document.body.classList.remove("Portrait","Landscape","Portrait-primary","Portrait-secondary","Landscape-primary","Landscape-secondary"),r){case"portrait":document.body.classList.add("Portrait");break;case"landscape":document.body.classList.add("Landscape")}if(null!=d){document.body.classList.add((o=d)[0].toUpperCase()+o.slice(1))}}}c(),n()||window.addEventListener("DOMContentLoaded",c);var s,u=a,l=i,p=r,m=d;function w(){u=a,l=i,p=r,m=d}function f(){n()&&(u===a&&l===i||document.body.dispatchEvent(new Event("viewportchanged",{bubbles:!0,cancelable:!0})),p===r&&m===d||document.body.dispatchEvent(new Event("orientationchangeend",{bubbles:!0,cancelable:!0})))}var h=0,v=10;function b(){clearInterval(s),s=void 0,h=0}function y(){o(),c(),null!=s&&(b(),f(),w()),u===a&&l===i?s=setInterval((function(){o(),u===a&&l===i&&(h+=1)<=v||(b(),c(),f(),w())}),100):(f(),w())}return window.addEventListener("orientationchange",(function(){setTimeout(y,10)})),window.addEventListener("resize",y),"orientation"in screen&&screen.orientation.addEventListener("change",(function(){setTimeout(y,10)})),{get Width(){return a},get Height(){return i},get Orientation(){return r},get detailledOrientation(){return d}}}));
//# sourceMappingURL=svelte-viewport-info.umd.js.map