@vueuse/integrations 6.4.1 → 6.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.mjs CHANGED
@@ -1,428 +1,402 @@
1
- import { shallowRef, ref, unref, watch, computed, isRef, watchEffect } from 'vue-demi';
1
+ import { shallowRef, ref, watch, computed, isRef, watchEffect } from 'vue-demi';
2
2
  import axios from 'axios';
3
- import { tryOnScopeDispose, createEventHook, isNumber, isClient } from '@vueuse/shared';
3
+ import { tryOnScopeDispose, isNumber, isClient } from '@vueuse/shared';
4
4
  import Cookie from 'universal-cookie';
5
5
  import { createDrauu } from 'drauu';
6
+ import { createEventHook, unrefElement, tryOnScopeDispose as tryOnScopeDispose$1 } from '@vueuse/core';
6
7
  import { createFocusTrap } from 'focus-trap';
7
8
  import jwt_decode from 'jwt-decode';
8
9
  import nprogress from 'nprogress';
9
10
  import QRCode from 'qrcode';
10
11
 
11
- /**
12
- * Wrapper for axios.
13
- *
14
- * @see https://vueuse.org/useAxios
15
- * @param url
16
- * @param config
17
- */
18
- function useAxios(url, ...args) {
19
- let config = {};
20
- let instance = axios;
21
- if (args.length > 0) {
22
- /**
23
- * Unable to use `instanceof` here becuase of (https://github.com/axios/axios/issues/737)
24
- * so instead we are checking if there is a `requset` on the object to see if it is an
25
- * axios instance
26
- */
27
- if ('request' in args[0])
28
- instance = args[0];
29
- else
30
- config = args[0];
31
- }
32
- if (args.length > 1) {
33
- if ('request' in args[1])
34
- instance = args[1];
35
- }
36
- const response = shallowRef();
37
- const data = shallowRef();
38
- const isFinished = ref(false);
39
- const isLoading = ref(true);
40
- const aborted = ref(false);
41
- const error = shallowRef();
42
- const cancelToken = axios.CancelToken.source();
43
- const abort = (message) => {
44
- if (isFinished.value || !isLoading.value)
45
- return;
46
- cancelToken.cancel(message);
47
- aborted.value = true;
48
- isLoading.value = false;
49
- isFinished.value = false;
50
- };
51
- instance(url, Object.assign(Object.assign({}, config), { cancelToken: cancelToken.token }))
52
- .then((r) => {
53
- response.value = r;
54
- data.value = r.data;
55
- })
56
- .catch((e) => {
57
- error.value = e;
58
- })
59
- .finally(() => {
60
- isLoading.value = false;
61
- isFinished.value = true;
62
- });
63
- return {
64
- response,
65
- data,
66
- error,
67
- finished: isFinished,
68
- loading: isLoading,
69
- isFinished,
70
- isLoading,
71
- cancel: abort,
72
- canceled: aborted,
73
- aborted,
74
- abort,
75
- };
12
+ var __defProp$3 = Object.defineProperty;
13
+ var __defProps$1 = Object.defineProperties;
14
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
15
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
16
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
17
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
18
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
19
+ var __spreadValues$3 = (a, b) => {
20
+ for (var prop in b || (b = {}))
21
+ if (__hasOwnProp$3.call(b, prop))
22
+ __defNormalProp$3(a, prop, b[prop]);
23
+ if (__getOwnPropSymbols$3)
24
+ for (var prop of __getOwnPropSymbols$3(b)) {
25
+ if (__propIsEnum$3.call(b, prop))
26
+ __defNormalProp$3(a, prop, b[prop]);
27
+ }
28
+ return a;
29
+ };
30
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
31
+ function useAxios(url, ...args) {
32
+ let config = {};
33
+ let instance = axios;
34
+ if (args.length > 0) {
35
+ if ("request" in args[0])
36
+ instance = args[0];
37
+ else
38
+ config = args[0];
39
+ }
40
+ if (args.length > 1) {
41
+ if ("request" in args[1])
42
+ instance = args[1];
43
+ }
44
+ const response = shallowRef();
45
+ const data = shallowRef();
46
+ const isFinished = ref(false);
47
+ const isLoading = ref(true);
48
+ const aborted = ref(false);
49
+ const error = shallowRef();
50
+ const cancelToken = axios.CancelToken.source();
51
+ const abort = (message) => {
52
+ if (isFinished.value || !isLoading.value)
53
+ return;
54
+ cancelToken.cancel(message);
55
+ aborted.value = true;
56
+ isLoading.value = false;
57
+ isFinished.value = false;
58
+ };
59
+ instance(url, __spreadProps$1(__spreadValues$3({}, config), { cancelToken: cancelToken.token })).then((r) => {
60
+ response.value = r;
61
+ data.value = r.data;
62
+ }).catch((e) => {
63
+ error.value = e;
64
+ }).finally(() => {
65
+ isLoading.value = false;
66
+ isFinished.value = true;
67
+ });
68
+ return {
69
+ response,
70
+ data,
71
+ error,
72
+ finished: isFinished,
73
+ loading: isLoading,
74
+ isFinished,
75
+ isLoading,
76
+ cancel: abort,
77
+ canceled: aborted,
78
+ aborted,
79
+ abort
80
+ };
76
81
  }
77
82
 
78
- /**
79
- * Creates a new {@link useCookies} function
80
- * @param {Object} req - incoming http request (for SSR)
81
- * @see https://github.com/reactivestack/cookies/tree/master/packages/universal-cookie universal-cookie
82
- * @description Creates universal-cookie instance using request (default is window.document.cookie) and returns {@link useCookies} function with provided universal-cookie instance
83
- */
84
- function createCookies(req) {
85
- const universalCookie = new Cookie(req ? req.headers.cookie : null);
86
- return (dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}) => useCookies(dependencies, { doNotParse, autoUpdateDependencies }, universalCookie);
87
- }
88
- /**
89
- * Reactive methods to work with cookies (use {@link createCookies} method instead if you are using SSR)
90
- * @param {string[]|null|undefined} dependencies - array of watching cookie's names. Pass empty array if don't want to watch cookies changes.
91
- * @param {Object} options
92
- * @param {boolean} options.doNotParse - don't try parse value as JSON
93
- * @param {boolean} options.autoUpdateDependencies - automatically update watching dependencies
94
- * @param {Object} cookies - universal-cookie instance
95
- */
96
- function useCookies(dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}, cookies = new Cookie()) {
97
- const watchingDependencies = autoUpdateDependencies ? [...dependencies || []] : dependencies;
98
- let previousCookies = cookies.getAll({ doNotParse: true });
99
- /**
100
- * Adds reactivity to get/getAll methods
101
- */
102
- const touches = ref(0);
103
- const onChange = () => {
104
- const newCookies = cookies.getAll({ doNotParse: true });
105
- if (shouldUpdate(watchingDependencies || null, newCookies, previousCookies))
106
- touches.value++;
107
- previousCookies = newCookies;
108
- };
109
- cookies.addChangeListener(onChange);
110
- tryOnScopeDispose(() => {
111
- cookies.removeChangeListener(onChange);
112
- });
113
- return {
114
- /**
115
- * Reactive get cookie by name. If **autoUpdateDependencies = true** then it will update watching dependencies
116
- */
117
- get: (...args) => {
118
- /**
119
- * Auto update watching dependencies if needed
120
- */
121
- if (autoUpdateDependencies && watchingDependencies && !watchingDependencies.includes(args[0]))
122
- watchingDependencies.push(args[0]);
123
- // eslint-disable-next-line no-unused-expressions
124
- touches.value; // adds reactivity to method
125
- return cookies.get(args[0], Object.assign({ doNotParse }, args[1]));
126
- },
127
- /**
128
- * Reactive get all cookies
129
- */
130
- getAll: (...args) => {
131
- // eslint-disable-next-line no-unused-expressions
132
- touches.value; // adds reactivity to method
133
- return cookies.getAll(Object.assign({ doNotParse }, args[0]));
134
- },
135
- set: (...args) => cookies.set(...args),
136
- remove: (...args) => cookies.remove(...args),
137
- addChangeListener: (...args) => cookies.addChangeListener(...args),
138
- removeChangeListener: (...args) => cookies.removeChangeListener(...args),
139
- };
140
- }
141
- function shouldUpdate(dependencies, newCookies, oldCookies) {
142
- if (!dependencies)
143
- return true;
144
- for (const dependency of dependencies) {
145
- if (newCookies[dependency] !== oldCookies[dependency])
146
- return true;
147
- }
148
- return false;
83
+ var __defProp$2 = Object.defineProperty;
84
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
85
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
86
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
87
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
88
+ var __spreadValues$2 = (a, b) => {
89
+ for (var prop in b || (b = {}))
90
+ if (__hasOwnProp$2.call(b, prop))
91
+ __defNormalProp$2(a, prop, b[prop]);
92
+ if (__getOwnPropSymbols$2)
93
+ for (var prop of __getOwnPropSymbols$2(b)) {
94
+ if (__propIsEnum$2.call(b, prop))
95
+ __defNormalProp$2(a, prop, b[prop]);
96
+ }
97
+ return a;
98
+ };
99
+ function createCookies(req) {
100
+ const universalCookie = new Cookie(req ? req.headers.cookie : null);
101
+ return (dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}) => useCookies(dependencies, { doNotParse, autoUpdateDependencies }, universalCookie);
149
102
  }
150
-
151
- /**
152
- * Get the dom element of a ref of element or Vue component instance
153
- *
154
- * @param elRef
155
- */
156
- function unrefElement(elRef) {
157
- var _a, _b;
158
- const plain = unref(elRef);
159
- return (_b = (_a = plain) === null || _a === void 0 ? void 0 : _a.$el) !== null && _b !== void 0 ? _b : plain;
103
+ function useCookies(dependencies, { doNotParse = false, autoUpdateDependencies = false } = {}, cookies = new Cookie()) {
104
+ const watchingDependencies = autoUpdateDependencies ? [...dependencies || []] : dependencies;
105
+ let previousCookies = cookies.getAll({ doNotParse: true });
106
+ const touches = ref(0);
107
+ const onChange = () => {
108
+ const newCookies = cookies.getAll({ doNotParse: true });
109
+ if (shouldUpdate(watchingDependencies || null, newCookies, previousCookies))
110
+ touches.value++;
111
+ previousCookies = newCookies;
112
+ };
113
+ cookies.addChangeListener(onChange);
114
+ tryOnScopeDispose(() => {
115
+ cookies.removeChangeListener(onChange);
116
+ });
117
+ return {
118
+ get: (...args) => {
119
+ if (autoUpdateDependencies && watchingDependencies && !watchingDependencies.includes(args[0]))
120
+ watchingDependencies.push(args[0]);
121
+ touches.value;
122
+ return cookies.get(args[0], __spreadValues$2({ doNotParse }, args[1]));
123
+ },
124
+ getAll: (...args) => {
125
+ touches.value;
126
+ return cookies.getAll(__spreadValues$2({ doNotParse }, args[0]));
127
+ },
128
+ set: (...args) => cookies.set(...args),
129
+ remove: (...args) => cookies.remove(...args),
130
+ addChangeListener: (...args) => cookies.addChangeListener(...args),
131
+ removeChangeListener: (...args) => cookies.removeChangeListener(...args)
132
+ };
160
133
  }
161
-
162
- /*! *****************************************************************************
163
- Copyright (c) Microsoft Corporation.
164
-
165
- Permission to use, copy, modify, and/or distribute this software for any
166
- purpose with or without fee is hereby granted.
167
-
168
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
169
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
170
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
171
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
172
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
173
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
174
- PERFORMANCE OF THIS SOFTWARE.
175
- ***************************************************************************** */
176
-
177
- function __rest(s, e) {
178
- var t = {};
179
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
180
- t[p] = s[p];
181
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
182
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
183
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
184
- t[p[i]] = s[p[i]];
185
- }
186
- return t;
134
+ function shouldUpdate(dependencies, newCookies, oldCookies) {
135
+ if (!dependencies)
136
+ return true;
137
+ for (const dependency of dependencies) {
138
+ if (newCookies[dependency] !== oldCookies[dependency])
139
+ return true;
140
+ }
141
+ return false;
187
142
  }
188
143
 
189
- var SwipeDirection;
190
- (function (SwipeDirection) {
191
- SwipeDirection["UP"] = "UP";
192
- SwipeDirection["RIGHT"] = "RIGHT";
193
- SwipeDirection["DOWN"] = "DOWN";
194
- SwipeDirection["LEFT"] = "LEFT";
195
- SwipeDirection["NONE"] = "NONE";
196
- })(SwipeDirection || (SwipeDirection = {}));
197
-
198
- /**
199
- * Reactive drauu
200
- *
201
- * @see https://vueuse.org/useDrauu
202
- * @param target The target svg element
203
- * @param options Drauu Options
204
- */
205
- function useDrauu(target, options) {
206
- const drauuInstance = ref();
207
- let disposables = [];
208
- const onChangedHook = createEventHook();
209
- const onCanceledHook = createEventHook();
210
- const onCommittedHook = createEventHook();
211
- const onStartHook = createEventHook();
212
- const onEndHook = createEventHook();
213
- const canUndo = ref(false);
214
- const canRedo = ref(false);
215
- const altPressed = ref(false);
216
- const shiftPressed = ref(false);
217
- const brush = ref({
218
- color: 'black',
219
- size: 3,
220
- arrowEnd: false,
221
- cornerRadius: 0,
222
- dasharray: undefined,
223
- fill: 'transparent',
224
- mode: 'draw',
225
- });
226
- watch(brush, () => {
227
- const instance = drauuInstance.value;
228
- if (instance)
229
- instance.brush = brush.value;
230
- }, { deep: true });
231
- const undo = () => { var _a; return (_a = drauuInstance.value) === null || _a === void 0 ? void 0 : _a.undo(); };
232
- const redo = () => { var _a; return (_a = drauuInstance.value) === null || _a === void 0 ? void 0 : _a.redo(); };
233
- const clear = () => { var _a; return (_a = drauuInstance.value) === null || _a === void 0 ? void 0 : _a.clear(); };
234
- const cancel = () => { var _a; return (_a = drauuInstance.value) === null || _a === void 0 ? void 0 : _a.cancel(); };
235
- const load = (svg) => { var _a; return (_a = drauuInstance.value) === null || _a === void 0 ? void 0 : _a.load(svg); };
236
- const dump = () => { var _a; return (_a = drauuInstance.value) === null || _a === void 0 ? void 0 : _a.dump(); };
237
- const cleanup = () => {
238
- var _a;
239
- disposables.forEach(dispose => dispose());
240
- (_a = drauuInstance.value) === null || _a === void 0 ? void 0 : _a.unmount();
241
- };
242
- const syncStatus = () => {
243
- if (drauuInstance.value) {
244
- canUndo.value = drauuInstance.value.canUndo();
245
- canRedo.value = drauuInstance.value.canRedo();
246
- altPressed.value = drauuInstance.value.altPressed;
247
- shiftPressed.value = drauuInstance.value.shiftPressed;
248
- }
249
- };
250
- watch(() => unrefElement(target), (el) => {
251
- if (!el || !(el instanceof SVGSVGElement))
252
- return;
253
- if (drauuInstance.value)
254
- cleanup();
255
- drauuInstance.value = createDrauu(Object.assign({ el }, options));
256
- syncStatus();
257
- disposables = [
258
- drauuInstance.value.on('canceled', () => onCanceledHook.trigger()),
259
- drauuInstance.value.on('committed', () => onCommittedHook.trigger()),
260
- drauuInstance.value.on('start', () => onStartHook.trigger()),
261
- drauuInstance.value.on('end', () => onEndHook.trigger()),
262
- drauuInstance.value.on('changed', () => {
263
- syncStatus();
264
- onChangedHook.trigger();
265
- }),
266
- ];
267
- }, { flush: 'post' });
268
- tryOnScopeDispose(() => cleanup());
269
- return {
270
- drauuInstance,
271
- load,
272
- dump,
273
- clear,
274
- cancel,
275
- undo,
276
- redo,
277
- canUndo,
278
- canRedo,
279
- brush,
280
- onChanged: onChangedHook.on,
281
- onCommitted: onCommittedHook.on,
282
- onStart: onStartHook.on,
283
- onEnd: onEndHook.on,
284
- onCanceled: onCanceledHook.on,
285
- };
144
+ var __defProp$1 = Object.defineProperty;
145
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
146
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
147
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
148
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
149
+ var __spreadValues$1 = (a, b) => {
150
+ for (var prop in b || (b = {}))
151
+ if (__hasOwnProp$1.call(b, prop))
152
+ __defNormalProp$1(a, prop, b[prop]);
153
+ if (__getOwnPropSymbols$1)
154
+ for (var prop of __getOwnPropSymbols$1(b)) {
155
+ if (__propIsEnum$1.call(b, prop))
156
+ __defNormalProp$1(a, prop, b[prop]);
157
+ }
158
+ return a;
159
+ };
160
+ function useDrauu(target, options) {
161
+ const drauuInstance = ref();
162
+ let disposables = [];
163
+ const onChangedHook = createEventHook();
164
+ const onCanceledHook = createEventHook();
165
+ const onCommittedHook = createEventHook();
166
+ const onStartHook = createEventHook();
167
+ const onEndHook = createEventHook();
168
+ const canUndo = ref(false);
169
+ const canRedo = ref(false);
170
+ const altPressed = ref(false);
171
+ const shiftPressed = ref(false);
172
+ const brush = ref({
173
+ color: "black",
174
+ size: 3,
175
+ arrowEnd: false,
176
+ cornerRadius: 0,
177
+ dasharray: void 0,
178
+ fill: "transparent",
179
+ mode: "draw"
180
+ });
181
+ watch(brush, () => {
182
+ const instance = drauuInstance.value;
183
+ if (instance)
184
+ instance.brush = brush.value;
185
+ }, { deep: true });
186
+ const undo = () => {
187
+ var _a;
188
+ return (_a = drauuInstance.value) == null ? void 0 : _a.undo();
189
+ };
190
+ const redo = () => {
191
+ var _a;
192
+ return (_a = drauuInstance.value) == null ? void 0 : _a.redo();
193
+ };
194
+ const clear = () => {
195
+ var _a;
196
+ return (_a = drauuInstance.value) == null ? void 0 : _a.clear();
197
+ };
198
+ const cancel = () => {
199
+ var _a;
200
+ return (_a = drauuInstance.value) == null ? void 0 : _a.cancel();
201
+ };
202
+ const load = (svg) => {
203
+ var _a;
204
+ return (_a = drauuInstance.value) == null ? void 0 : _a.load(svg);
205
+ };
206
+ const dump = () => {
207
+ var _a;
208
+ return (_a = drauuInstance.value) == null ? void 0 : _a.dump();
209
+ };
210
+ const cleanup = () => {
211
+ var _a;
212
+ disposables.forEach((dispose) => dispose());
213
+ (_a = drauuInstance.value) == null ? void 0 : _a.unmount();
214
+ };
215
+ const syncStatus = () => {
216
+ if (drauuInstance.value) {
217
+ canUndo.value = drauuInstance.value.canUndo();
218
+ canRedo.value = drauuInstance.value.canRedo();
219
+ altPressed.value = drauuInstance.value.altPressed;
220
+ shiftPressed.value = drauuInstance.value.shiftPressed;
221
+ }
222
+ };
223
+ watch(() => unrefElement(target), (el) => {
224
+ if (!el || !(el instanceof SVGSVGElement))
225
+ return;
226
+ if (drauuInstance.value)
227
+ cleanup();
228
+ drauuInstance.value = createDrauu(__spreadValues$1({ el }, options));
229
+ syncStatus();
230
+ disposables = [
231
+ drauuInstance.value.on("canceled", () => onCanceledHook.trigger()),
232
+ drauuInstance.value.on("committed", () => onCommittedHook.trigger()),
233
+ drauuInstance.value.on("start", () => onStartHook.trigger()),
234
+ drauuInstance.value.on("end", () => onEndHook.trigger()),
235
+ drauuInstance.value.on("changed", () => {
236
+ syncStatus();
237
+ onChangedHook.trigger();
238
+ })
239
+ ];
240
+ }, { flush: "post" });
241
+ tryOnScopeDispose(() => cleanup());
242
+ return {
243
+ drauuInstance,
244
+ load,
245
+ dump,
246
+ clear,
247
+ cancel,
248
+ undo,
249
+ redo,
250
+ canUndo,
251
+ canRedo,
252
+ brush,
253
+ onChanged: onChangedHook.on,
254
+ onCommitted: onCommittedHook.on,
255
+ onStart: onStartHook.on,
256
+ onEnd: onEndHook.on,
257
+ onCanceled: onCanceledHook.on
258
+ };
286
259
  }
287
260
 
288
- /**
289
- * Reactive focus-trap
290
- *
291
- * @see https://vueuse.org/useFocusTrap
292
- * @param target The target element to trap focus within
293
- * @param options Focus trap options
294
- * @param autoFocus Focus trap automatically when mounted
295
- */
296
- function useFocusTrap(target, options = {}) {
297
- let trap;
298
- const { immediate } = options, focusTrapOptions = __rest(options, ["immediate"]);
299
- const hasFocus = ref(false);
300
- const isPaused = ref(false);
301
- const activate = (opts) => trap && trap.activate(opts);
302
- const deactivate = (opts) => trap && trap.deactivate(opts);
303
- const pause = () => {
304
- if (trap) {
305
- trap.pause();
306
- isPaused.value = true;
307
- }
308
- };
309
- const unpause = () => {
310
- if (trap) {
311
- trap.unpause();
312
- isPaused.value = false;
313
- }
314
- };
315
- watch(() => unrefElement(target), (el) => {
316
- if (!el)
317
- return;
318
- trap = createFocusTrap(el, Object.assign(Object.assign({}, focusTrapOptions), { onActivate() {
319
- hasFocus.value = true;
320
- // Apply if user provided onActivate option
321
- if (options.onActivate)
322
- options.onActivate();
323
- },
324
- onDeactivate() {
325
- hasFocus.value = false;
326
- // Apply if user provided onDeactivate option
327
- if (options.onDeactivate)
328
- options.onDeactivate();
329
- } }));
330
- // Focus if immediate is set to true
331
- if (immediate)
332
- activate();
333
- }, { flush: 'post' });
334
- // Cleanup on unmount
335
- tryOnScopeDispose(() => deactivate());
336
- return {
337
- hasFocus,
338
- isPaused,
339
- activate,
340
- deactivate,
341
- pause,
342
- unpause,
343
- };
261
+ var __defProp = Object.defineProperty;
262
+ var __defProps = Object.defineProperties;
263
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
264
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
265
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
266
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
267
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
268
+ var __spreadValues = (a, b) => {
269
+ for (var prop in b || (b = {}))
270
+ if (__hasOwnProp.call(b, prop))
271
+ __defNormalProp(a, prop, b[prop]);
272
+ if (__getOwnPropSymbols)
273
+ for (var prop of __getOwnPropSymbols(b)) {
274
+ if (__propIsEnum.call(b, prop))
275
+ __defNormalProp(a, prop, b[prop]);
276
+ }
277
+ return a;
278
+ };
279
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
280
+ var __objRest = (source, exclude) => {
281
+ var target = {};
282
+ for (var prop in source)
283
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
284
+ target[prop] = source[prop];
285
+ if (source != null && __getOwnPropSymbols)
286
+ for (var prop of __getOwnPropSymbols(source)) {
287
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
288
+ target[prop] = source[prop];
289
+ }
290
+ return target;
291
+ };
292
+ function useFocusTrap(target, options = {}) {
293
+ let trap;
294
+ const _a = options, { immediate } = _a, focusTrapOptions = __objRest(_a, ["immediate"]);
295
+ const hasFocus = ref(false);
296
+ const isPaused = ref(false);
297
+ const activate = (opts) => trap && trap.activate(opts);
298
+ const deactivate = (opts) => trap && trap.deactivate(opts);
299
+ const pause = () => {
300
+ if (trap) {
301
+ trap.pause();
302
+ isPaused.value = true;
303
+ }
304
+ };
305
+ const unpause = () => {
306
+ if (trap) {
307
+ trap.unpause();
308
+ isPaused.value = false;
309
+ }
310
+ };
311
+ watch(() => unrefElement(target), (el) => {
312
+ if (!el)
313
+ return;
314
+ trap = createFocusTrap(el, __spreadProps(__spreadValues({}, focusTrapOptions), {
315
+ onActivate() {
316
+ hasFocus.value = true;
317
+ if (options.onActivate)
318
+ options.onActivate();
319
+ },
320
+ onDeactivate() {
321
+ hasFocus.value = false;
322
+ if (options.onDeactivate)
323
+ options.onDeactivate();
324
+ }
325
+ }));
326
+ if (immediate)
327
+ activate();
328
+ }, { flush: "post" });
329
+ tryOnScopeDispose$1(() => deactivate());
330
+ return {
331
+ hasFocus,
332
+ isPaused,
333
+ activate,
334
+ deactivate,
335
+ pause,
336
+ unpause
337
+ };
344
338
  }
345
339
 
346
- /**
347
- * Reactive decoded jwt token.
348
- *
349
- * @see https://vueuse.org/useJwt
350
- * @param jwt
351
- */
352
- function useJwt(encodedJwt, options = {}) {
353
- const encodedJwtRef = ref(encodedJwt);
354
- const { onError, fallbackValue = null, } = options;
355
- const decodeWithFallback = (encodedJwt, options) => {
356
- try {
357
- return jwt_decode(encodedJwt, options);
358
- }
359
- catch (err) {
360
- onError === null || onError === void 0 ? void 0 : onError(err);
361
- return fallbackValue;
362
- }
363
- };
364
- const header = computed(() => decodeWithFallback(encodedJwtRef.value, { header: true }));
365
- const payload = computed(() => decodeWithFallback(encodedJwtRef.value));
366
- return {
367
- header,
368
- payload,
369
- };
340
+ function useJwt(encodedJwt, options = {}) {
341
+ const encodedJwtRef = ref(encodedJwt);
342
+ const {
343
+ onError,
344
+ fallbackValue = null
345
+ } = options;
346
+ const decodeWithFallback = (encodedJwt2, options2) => {
347
+ try {
348
+ return jwt_decode(encodedJwt2, options2);
349
+ } catch (err) {
350
+ onError == null ? void 0 : onError(err);
351
+ return fallbackValue;
352
+ }
353
+ };
354
+ const header = computed(() => decodeWithFallback(encodedJwtRef.value, { header: true }));
355
+ const payload = computed(() => decodeWithFallback(encodedJwtRef.value));
356
+ return {
357
+ header,
358
+ payload
359
+ };
370
360
  }
371
361
 
372
- /**
373
- * Reactive progress bar.
374
- *
375
- * @see https://vueuse.org/useNProgress
376
- * @param currentProgress
377
- * @param options
378
- */
379
- function useNProgress(currentProgress = null, options) {
380
- const progress = isRef(currentProgress)
381
- ? currentProgress
382
- : ref(currentProgress);
383
- const isLoading = computed({
384
- set: load => load ? nprogress.start() : nprogress.done(),
385
- get: () => isNumber(progress.value) && progress.value < 1,
386
- });
387
- if (options)
388
- nprogress.configure(options);
389
- const setProgress = nprogress.set;
390
- nprogress.set = (n) => {
391
- progress.value = n;
392
- return setProgress.call(nprogress, n);
393
- };
394
- watchEffect(() => {
395
- if (isNumber(progress.value))
396
- setProgress.call(nprogress, progress.value);
397
- });
398
- tryOnScopeDispose(nprogress.remove);
399
- return {
400
- isLoading,
401
- progress,
402
- start: nprogress.start,
403
- done: nprogress.done,
404
- remove: () => {
405
- progress.value = null;
406
- nprogress.remove();
407
- },
408
- };
362
+ function useNProgress(currentProgress = null, options) {
363
+ const progress = isRef(currentProgress) ? currentProgress : ref(currentProgress);
364
+ const isLoading = computed({
365
+ set: (load) => load ? nprogress.start() : nprogress.done(),
366
+ get: () => isNumber(progress.value) && progress.value < 1
367
+ });
368
+ if (options)
369
+ nprogress.configure(options);
370
+ const setProgress = nprogress.set;
371
+ nprogress.set = (n) => {
372
+ progress.value = n;
373
+ return setProgress.call(nprogress, n);
374
+ };
375
+ watchEffect(() => {
376
+ if (isNumber(progress.value))
377
+ setProgress.call(nprogress, progress.value);
378
+ });
379
+ tryOnScopeDispose(nprogress.remove);
380
+ return {
381
+ isLoading,
382
+ progress,
383
+ start: nprogress.start,
384
+ done: nprogress.done,
385
+ remove: () => {
386
+ progress.value = null;
387
+ nprogress.remove();
388
+ }
389
+ };
409
390
  }
410
391
 
411
- /**
412
- * Wrapper for qrcode.
413
- *
414
- * @see https://vueuse.org/useQRCode
415
- * @param text
416
- * @param options
417
- */
418
- function useQRCode(text, options) {
419
- const src = ref(text);
420
- const result = ref('');
421
- watch(src, async (value) => {
422
- if (src.value && isClient)
423
- result.value = await QRCode.toDataURL(value, options);
424
- }, { immediate: true });
425
- return result;
392
+ function useQRCode(text, options) {
393
+ const src = ref(text);
394
+ const result = ref("");
395
+ watch(src, async (value) => {
396
+ if (src.value && isClient)
397
+ result.value = await QRCode.toDataURL(value, options);
398
+ }, { immediate: true });
399
+ return result;
426
400
  }
427
401
 
428
402
  export { createCookies, useAxios, useCookies, useDrauu, useFocusTrap, useJwt, useNProgress, useQRCode };