1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | Object.defineProperty(exports, '__esModule', { value: true });
|
11 |
|
12 | var VueCompositionApi = require('@vue/composition-api');
|
13 |
|
14 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
15 |
|
16 | var VueCompositionApi__default = _interopDefaultLegacy(VueCompositionApi);
|
17 |
|
18 | var script = VueCompositionApi.defineComponent({
|
19 | name: 'VueIdentifyNetwork',
|
20 | props: {
|
21 | unknownClass: {
|
22 | type: String ,
|
23 | required: false,
|
24 | default: null,
|
25 | },
|
26 | slowClass: {
|
27 | type: String ,
|
28 | required: false,
|
29 | default: null,
|
30 | },
|
31 | fastClass: {
|
32 | type: String ,
|
33 | required: false,
|
34 | default: null,
|
35 | },
|
36 | },
|
37 | emits: ['network-type', 'network-speed'],
|
38 | setup(_, { emit }) {
|
39 | const type = VueCompositionApi.ref(null);
|
40 | const downLink = VueCompositionApi.ref('Unknown');
|
41 | const vendor = VueCompositionApi.ref(
|
42 | typeof window === 'undefined' ? 'Unknown' : navigator.vendor,
|
43 | );
|
44 |
|
45 | VueCompositionApi.onMounted(() => {
|
46 | if (vendor.value.includes('Google') && type.value !== 'Unknown') {
|
47 | type.value = navigator.connection.effectiveType;
|
48 | downLink.value = navigator.connection.downlink;
|
49 | } else {
|
50 | type.value = 'Unknown';
|
51 | downLink.value = 'Unknown';
|
52 | }
|
53 | emit('network-type', type.value);
|
54 | emit('network-speed', downLink.value);
|
55 | navigator.connection.addEventListener('change', updateConnection);
|
56 | });
|
57 |
|
58 | VueCompositionApi.onBeforeUnmount(() => {
|
59 | navigator.connection.removeEventListener('change', updateConnection);
|
60 | });
|
61 |
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 | function updateConnection(e) {
|
68 | type.value = e.currentTarget && e.currentTarget.effectiveType;
|
69 | downLink.value = e.currentTarget && e.currentTarget.downlink;
|
70 | emit('network-type', type.value);
|
71 | emit('network-speed', downLink.value);
|
72 | }
|
73 |
|
74 | return {
|
75 | type,
|
76 | };
|
77 | },
|
78 | });
|
79 |
|
80 | function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
|
81 | if (typeof shadowMode !== 'boolean') {
|
82 | createInjectorSSR = createInjector;
|
83 | createInjector = shadowMode;
|
84 | shadowMode = false;
|
85 | }
|
86 |
|
87 | const options = typeof script === 'function' ? script.options : script;
|
88 |
|
89 | if (template && template.render) {
|
90 | options.render = template.render;
|
91 | options.staticRenderFns = template.staticRenderFns;
|
92 | options._compiled = true;
|
93 |
|
94 | if (isFunctionalTemplate) {
|
95 | options.functional = true;
|
96 | }
|
97 | }
|
98 |
|
99 | if (scopeId) {
|
100 | options._scopeId = scopeId;
|
101 | }
|
102 | let hook;
|
103 | if (moduleIdentifier) {
|
104 |
|
105 | hook = function (context) {
|
106 |
|
107 | context =
|
108 | context ||
|
109 | (this.$vnode && this.$vnode.ssrContext) ||
|
110 | (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext);
|
111 |
|
112 | if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
|
113 | context = __VUE_SSR_CONTEXT__;
|
114 | }
|
115 |
|
116 | if (style) {
|
117 | style.call(this, createInjectorSSR(context));
|
118 | }
|
119 |
|
120 | if (context && context._registeredComponents) {
|
121 | context._registeredComponents.add(moduleIdentifier);
|
122 | }
|
123 | };
|
124 |
|
125 |
|
126 | options._ssrRegister = hook;
|
127 | }
|
128 | else if (style) {
|
129 | hook = shadowMode
|
130 | ? function (context) {
|
131 | style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
|
132 | }
|
133 | : function (context) {
|
134 | style.call(this, createInjector(context));
|
135 | };
|
136 | }
|
137 | if (hook) {
|
138 | if (options.functional) {
|
139 |
|
140 | const originalRender = options.render;
|
141 | options.render = function renderWithStyleInjection(h, context) {
|
142 | hook.call(context);
|
143 | return originalRender(h, context);
|
144 | };
|
145 | }
|
146 | else {
|
147 |
|
148 | const existing = options.beforeCreate;
|
149 | options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
|
150 | }
|
151 | }
|
152 | return script;
|
153 | }
|
154 |
|
155 |
|
156 | const __vue_script__ = script;
|
157 |
|
158 |
|
159 | var __vue_render__ = function () {
|
160 | var _vm = this;
|
161 | var _h = _vm.$createElement;
|
162 | var _c = _vm._self._c || _h;
|
163 | return _c("div", [
|
164 | _vm.type === "Unknown"
|
165 | ? _c("div", { class: _vm.unknownClass }, [_vm._t("unknown")], 2)
|
166 | : _vm._e(),
|
167 | _vm._v(" "),
|
168 | _vm.type === "2g"
|
169 | ? _c("div", { class: _vm.slowClass }, [_vm._t("slow")], 2)
|
170 | : _vm._e(),
|
171 | _vm._v(" "),
|
172 | _vm.type !== "2g" && _vm.type !== "Unknown"
|
173 | ? _c("div", { class: _vm.fastClass }, [_vm._t("fast")], 2)
|
174 | : _vm._e(),
|
175 | ])
|
176 | };
|
177 | var __vue_staticRenderFns__ = [];
|
178 | __vue_render__._withStripped = true;
|
179 |
|
180 |
|
181 | const __vue_inject_styles__ = undefined;
|
182 |
|
183 | const __vue_scope_id__ = undefined;
|
184 |
|
185 | const __vue_module_identifier__ = undefined;
|
186 |
|
187 | const __vue_is_functional_template__ = false;
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 | const __vue_component__ = normalizeComponent(
|
197 | { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
|
198 | __vue_inject_styles__,
|
199 | __vue_script__,
|
200 | __vue_scope_id__,
|
201 | __vue_is_functional_template__,
|
202 | __vue_module_identifier__,
|
203 | false,
|
204 | undefined,
|
205 | undefined,
|
206 | undefined
|
207 | );
|
208 |
|
209 | var VueIdentifyNetwork = __vue_component__;
|
210 |
|
211 | let installed = false;
|
212 |
|
213 | const install = {
|
214 | install(Vue) {
|
215 | if (installed) return;
|
216 | Vue.use(VueCompositionApi__default['default']);
|
217 | Vue.component('VueIdentifyNetwork', VueIdentifyNetwork);
|
218 | installed = true;
|
219 | },
|
220 | };
|
221 |
|
222 | var install$1 = install;
|
223 |
|
224 | exports.VueIdentifyNetwork = VueIdentifyNetwork;
|
225 | exports['default'] = install$1;
|
226 |
|