UNPKG

9.14 kBSource Map (JSON)View Raw
1{"version":3,"file":"vue-identify-network.js","sources":["../src/VueIdentifyNetwork.vue","../node_modules/vue-runtime-helpers/dist/normalize-component.mjs","../src/install.ts"],"sourcesContent":["<template>\n <div>\n <div v-if=\"type === 'Unknown'\" :class=\"unknownClass\">\n <slot name=\"unknown\" />\n </div>\n <div v-if=\"type === '2g'\" :class=\"slowClass\">\n <slot name=\"slow\" />\n </div>\n <div v-if=\"type !== '2g' && type !== 'Unknown'\" :class=\"fastClass\">\n <slot name=\"fast\" />\n </div>\n </div>\n</template>\n\n<script lang=\"ts\">\n import {\n defineComponent,\n onBeforeUnmount,\n onMounted,\n ref,\n } from '@vue/composition-api';\n import type { Ref, SetupContext, PropType } from '@vue/composition-api';\n import type { NetworkType, Evented } from '../types';\n\n export default defineComponent({\n name: 'VueIdentifyNetwork',\n props: {\n unknownClass: {\n type: String as PropType<string | null>,\n required: false,\n default: null,\n },\n slowClass: {\n type: String as PropType<string | null>,\n required: false,\n default: null,\n },\n fastClass: {\n type: String as PropType<string | null>,\n required: false,\n default: null,\n },\n },\n emits: ['network-type', 'network-speed'],\n setup(_, { emit }: SetupContext) {\n const type: Ref<NetworkType> = ref(null);\n const downLink: Ref<'Unknown' | number> = ref('Unknown');\n const vendor: Ref<string> = ref(\n typeof window === 'undefined' ? 'Unknown' : navigator.vendor,\n );\n\n onMounted(() => {\n if (vendor.value.includes('Google') && type.value !== 'Unknown') {\n type.value = navigator.connection.effectiveType;\n downLink.value = navigator.connection.downlink;\n } else {\n type.value = 'Unknown';\n downLink.value = 'Unknown';\n }\n emit('network-type', type.value);\n emit('network-speed', downLink.value);\n navigator.connection.addEventListener('change', updateConnection);\n });\n\n onBeforeUnmount(() => {\n navigator.connection.removeEventListener('change', updateConnection);\n });\n\n /**\n * Updates the type & downLink info\n *\n * @param {Evented} e - The type & downlink info\n */\n function updateConnection(e: Evented): void {\n type.value = e.currentTarget && e.currentTarget.effectiveType;\n downLink.value = e.currentTarget && e.currentTarget.downlink;\n emit('network-type', type.value);\n emit('network-speed', downLink.value);\n }\n\n return {\n type,\n };\n },\n });\n</script>\n","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","import VueCompositionApi from '@vue/composition-api';\nimport { VueConstructor } from 'vue';\nimport VueIdentifyNetwork from './VueIdentifyNetwork.vue';\n\nlet installed = false;\n\nconst install = {\n install(Vue: VueConstructor): void {\n if (installed) return;\n Vue.use(VueCompositionApi);\n Vue.component('VueIdentifyNetwork', VueIdentifyNetwork);\n installed = true;\n },\n};\n\nexport default install;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAwBA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA;;ECpFA,SAAS,kBAAkB,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,oBAAoB,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,oBAAoB,EAAE;EAC7L,IAAI,IAAI,OAAO,UAAU,KAAK,SAAS,EAAE;EACzC,QAAQ,iBAAiB,GAAG,cAAc,CAAC;EAC3C,QAAQ,cAAc,GAAG,UAAU,CAAC;EACpC,QAAQ,UAAU,GAAG,KAAK,CAAC;EAC3B,KAAK;EACL;EACA,IAAI,MAAM,OAAO,GAAG,OAAO,MAAM,KAAK,UAAU,GAAG,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;EAC3E;EACA,IAAI,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,EAAE;EACr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