UNPKG

7.79 kBSource Map (JSON)View Raw
1{"version":3,"file":"v-offline.min.js","sources":["../node_modules/vue-runtime-helpers/dist/normalize-component.mjs","../src/VOffline.vue","../src/install.ts"],"sourcesContent":["function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {\r\n if (typeof shadowMode !== 'boolean') {\r\n createInjectorSSR = createInjector;\r\n createInjector = shadowMode;\r\n shadowMode = false;\r\n }\r\n // Vue.extend constructor export interop.\r\n const options = typeof script === 'function' ? script.options : script;\r\n // render functions\r\n if (template && template.render) {\r\n options.render = template.render;\r\n options.staticRenderFns = template.staticRenderFns;\r\n options._compiled = true;\r\n // functional template\r\n if (isFunctionalTemplate) {\r\n options.functional = true;\r\n }\r\n }\r\n // scopedId\r\n if (scopeId) {\r\n options._scopeId = scopeId;\r\n }\r\n let hook;\r\n if (moduleIdentifier) {\r\n // server build\r\n hook = function (context) {\r\n // 2.3 injection\r\n context =\r\n context || // cached call\r\n (this.$vnode && this.$vnode.ssrContext) || // stateful\r\n (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional\r\n // 2.2 with runInNewContext: true\r\n if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {\r\n context = __VUE_SSR_CONTEXT__;\r\n }\r\n // inject component styles\r\n if (style) {\r\n style.call(this, createInjectorSSR(context));\r\n }\r\n // register component module identifier for async chunk inference\r\n if (context && context._registeredComponents) {\r\n context._registeredComponents.add(moduleIdentifier);\r\n }\r\n };\r\n // used by ssr in case component is cached and beforeCreate\r\n // never gets called\r\n options._ssrRegister = hook;\r\n }\r\n else if (style) {\r\n hook = shadowMode\r\n ? function (context) {\r\n style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));\r\n }\r\n : function (context) {\r\n style.call(this, createInjector(context));\r\n };\r\n }\r\n if (hook) {\r\n if (options.functional) {\r\n // register for functional component in vue file\r\n const originalRender = options.render;\r\n options.render = function renderWithStyleInjection(h, context) {\r\n hook.call(context);\r\n return originalRender(h, context);\r\n };\r\n }\r\n else {\r\n // inject component registration as beforeCreate hook\r\n const existing = options.beforeCreate;\r\n options.beforeCreate = existing ? [].concat(existing, hook) : [hook];\r\n }\r\n }\r\n return script;\r\n}\n\nexport default normalizeComponent;\n//# sourceMappingURL=normalize-component.mjs.map\n","<template>\n <div :class=\"wrapperClass\">\n <slot />\n </div>\n</template>\n\n<script lang=\"ts\">\n import Ping from 'ping.js';\n import {\n ref,\n Ref,\n computed,\n onBeforeUnmount,\n PropType,\n ComputedRef,\n SetupContext,\n defineComponent,\n } from '@vue/composition-api';\n import { VOfflineProps } from '../types';\n\n export default defineComponent({\n name: 'VOffline',\n props: {\n onlineClass: {\n type: String as PropType<string>,\n required: false,\n default: '',\n },\n offlineClass: {\n type: String as PropType<string>,\n required: false,\n default: '',\n },\n pingUrl: {\n type: String as PropType<string>,\n required: false,\n default: 'https://google.com',\n },\n },\n setup(props: VOfflineProps, { emit }: SetupContext) {\n // Local state\n const isOnline: Ref<boolean> = ref(navigator.onLine || false);\n const events: Ref<string[]> = ref(['online', 'offline', 'load']);\n const url: Ref<string> = ref(props.pingUrl || 'https://google.com');\n\n // Local computed\n const wrapperClass: ComputedRef<string> = computed(() => {\n if (isOnline.value) {\n return typeof props.onlineClass === 'string' ? props.onlineClass : '';\n } else {\n return typeof props.offlineClass === 'string'\n ? props.offlineClass\n : '';\n }\n });\n\n /**\n * Created lifecycle hook\n */\n events.value.forEach((event) => window.addEventListener(event, check));\n\n /**\n * Before unmount lifecycle hook\n */\n onBeforeUnmount(() => {\n // Cleanup of the event listeners\n events.value.forEach((event) =>\n window.removeEventListener(event, check),\n );\n });\n\n // Local functions\n /**\n * Pings the URL and emits an\n * detected online/offline event.\n *\n * @returns {Promise<void>}\n */\n async function check(): Promise<void> {\n const p = new Ping();\n try {\n const ping = await p.ping(url.value);\n if (ping || navigator.onLine) {\n isOnline.value = true;\n emit('detected-condition', isOnline.value);\n }\n } catch (error) {\n if (error || !navigator.onLine) {\n isOnline.value = false;\n emit('detected-condition', isOnline.value);\n }\n }\n }\n\n return {\n wrapperClass,\n };\n },\n });\n</script>\n","import VueCompositionApi from '@vue/composition-api';\nimport { VueConstructor } from 'vue';\nimport VOffline from './VOffline.vue';\n\nlet installed = false;\n\nconst install = {\n install(Vue: VueConstructor): void {\n if (installed) return;\n Vue.use(VueCompositionApi);\n Vue.component('VOffline', VOffline);\n installed = true;\n },\n};\n\nexport default install;\n"],"names":["normalizeComponent","template","style","script","scopeId","isFunctionalTemplate","moduleIdentifier","shadowMode","createInjector","createInjectorSSR","createInjectorShadow","options","hook","render","staticRenderFns","_compiled","functional","_scopeId","context","this","$vnode","ssrContext","parent","__VUE_SSR_CONTEXT__","call","_registeredComponents","add","_ssrRegister","$root","$options","shadowRoot","originalRender","h","existing","beforeCreate","concat"],"mappings":";;;;;;6bAAA,SAASA,EAAmBC,EAAUC,EAAOC,EAAQC,EAASC,EAAsBC,EAAoCC,EAAYC,EAAgBC,EAAmBC,GACzI,kBAAfH,IACPE,EAAoBD,EACpBA,EAAiBD,EACjBA,GAAa,GAGjB,MAAMI,EAA4B,mBAAXR,EAAwBA,EAAOQ,QAAUR,EAehE,IAAIS,EAmCJ,GAhDIX,GAAYA,EAASY,SACrBF,EAAQE,OAASZ,EAASY,OAC1BF,EAAQG,gBAAkBb,EAASa,gBACnCH,EAAQI,WAAY,EAEhBV,IACAM,EAAQK,YAAa,IAIzBZ,IACAO,EAAQM,SAAWb,GAGnBE,GAEAM,EAAO,SAAUM,IAEbA,EACIA,GACKC,KAAKC,QAAUD,KAAKC,OAAOC,YAC3BF,KAAKG,QAAUH,KAAKG,OAAOF,QAAUD,KAAKG,OAAOF,OAAOC,aAElB,oBAAxBE,sBACnBL,EAAUK,qBAGVrB,GACAA,EAAMsB,KAAKL,KAAMV,EAAkBS,IAGnCA,GAAWA,EAAQO,uBACnBP,EAAQO,sBAAsBC,IAAIpB,IAK1CK,EAAQgB,aAAef,GAElBV,IACLU,EAAOL,EACD,SAAUW,GACRhB,EAAMsB,KAAKL,KAAMT,EAAqBQ,EAASC,KAAKS,MAAMC,SAASC,cAErE,SAAUZ,GACRhB,EAAMsB,KAAKL,KAAMX,EAAeU,MAGxCN,EACA,GAAID,EAAQK,WAAY,CAEpB,MAAMe,EAAiBpB,EAAQE,OAC/BF,EAAQE,OAAS,SAAkCmB,EAAGd,GAElD,OADAN,EAAKY,KAAKN,GACHa,EAAeC,EAAGd,QAG5B,CAED,MAAMe,EAAWtB,EAAQuB,aACzBvB,EAAQuB,aAAeD,EAAW,GAAGE,OAAOF,EAAUrB,GAAQ,CAACA,GAGvE,OAAOT,ECtEX,0jCCEA"}
\No newline at end of file