UNPKG

@nextcloud/vue

Version:
1 lines 2.26 kB
{"version":3,"file":"useIsMobile.cjs","sources":["../../src/composables/useIsMobile/index.js"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport { readonly, ref } from 'vue'\n\n/** The minimal width of the viewport for a desktop screen */\nexport const MOBILE_BREAKPOINT = 1024\n/** The minimal width of the viewport for a small mobile screen, a half of the minimal desktop */\nexport const MOBILE_SMALL_BREAKPOINT = MOBILE_BREAKPOINT / 2\n\nconst isLessThanBreakpoint = (breakpoint) => document.documentElement.clientWidth < breakpoint\n\n// Store the state of the viewport size in a module-scope to reuse between module's users\nconst isMobile = ref(isLessThanBreakpoint(MOBILE_BREAKPOINT))\nconst isSmallMobile = ref(isLessThanBreakpoint(MOBILE_SMALL_BREAKPOINT))\n\nwindow.addEventListener('resize', () => {\n\tisMobile.value = isLessThanBreakpoint(MOBILE_BREAKPOINT)\n\tisSmallMobile.value = isLessThanBreakpoint(MOBILE_SMALL_BREAKPOINT)\n}, { passive: true })\n\n/**\n * Use global isMobile state\n *\n * @return {import('vue').DeepReadonly<import('vue').Ref<boolean>>} Reactive flag for MOBILE_BREAKPOINT\n */\nexport function useIsMobile() {\n\treturn readonly(isMobile)\n}\n\n/**\n * Use global isSmallMobile state\n *\n * @return {import('vue').DeepReadonly<import('vue').Ref<boolean>>} Reactive flag for MOBILE_SMALL_BREAKPOINT\n */\nexport function useIsSmallMobile() {\n\treturn readonly(isSmallMobile)\n}\n\n/**\n * @deprecated Is to be removed in v9.0.0 with Vue 3 migration.\n * Use `composables/useIsMobile` instead.\n * Defined and exported only for isMobile mixin.\n */\nexport const isMobileState = readonly(isMobile)\n"],"names":["ref","readonly"],"mappings":";;;AAQY,MAAC,oBAAoB;AAErB,MAAC,0BAA0B,oBAAoB;AAE3D,MAAM,uBAAuB,CAAC,eAAe,SAAS,gBAAgB,cAAc;AAGpF,MAAM,WAAWA,IAAAA,IAAI,qBAAqB,iBAAiB,CAAC;AAC5D,MAAM,gBAAgBA,IAAAA,IAAI,qBAAqB,uBAAuB,CAAC;AAEvE,OAAO,iBAAiB,UAAU,MAAM;AACvC,WAAS,QAAQ,qBAAqB,iBAAiB;AACvD,gBAAc,QAAQ,qBAAqB,uBAAuB;AACnE,GAAG,EAAE,SAAS,KAAI,CAAE;AAOb,SAAS,cAAc;AAC7B,SAAOC,IAAAA,SAAS,QAAQ;AACzB;AAOO,SAAS,mBAAmB;AAClC,SAAOA,IAAAA,SAAS,aAAa;AAC9B;AAOY,MAAC,gBAAgBA,IAAAA,SAAS,QAAQ;;;;;;"}