nuxt-hs-ui 2.1.12 → 2.1.13

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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.15.0"
6
6
  },
7
- "version": "2.1.12",
7
+ "version": "2.1.13",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -1,4 +1,4 @@
1
- interface StoreState {
1
+ export declare const useHsMisc: import("pinia").StoreDefinition<"HsMisc", Pick<{
2
2
  state: {
3
3
  isInit: boolean;
4
4
  isReady: boolean;
@@ -10,11 +10,43 @@ interface StoreState {
10
10
  };
11
11
  scrollbarWidth: number;
12
12
  };
13
- }
14
- export declare const useHsMisc: import("pinia").StoreDefinition<"HsMisc", StoreState, {}, {
15
- IsMobile(): boolean;
16
- Init(arg?: {
13
+ GetUa: () => string;
14
+ IsMobile: () => boolean;
15
+ Init: (arg?: {
17
16
  readyDeray?: number;
18
- }): Promise<void>;
19
- }>;
20
- export {};
17
+ }) => Promise<void>;
18
+ }, "state">, Pick<{
19
+ state: {
20
+ isInit: boolean;
21
+ isReady: boolean;
22
+ isMobile: boolean;
23
+ readyDeray: number;
24
+ window: {
25
+ h: number;
26
+ w: number;
27
+ };
28
+ scrollbarWidth: number;
29
+ };
30
+ GetUa: () => string;
31
+ IsMobile: () => boolean;
32
+ Init: (arg?: {
33
+ readyDeray?: number;
34
+ }) => Promise<void>;
35
+ }, never>, Pick<{
36
+ state: {
37
+ isInit: boolean;
38
+ isReady: boolean;
39
+ isMobile: boolean;
40
+ readyDeray: number;
41
+ window: {
42
+ h: number;
43
+ w: number;
44
+ };
45
+ scrollbarWidth: number;
46
+ };
47
+ GetUa: () => string;
48
+ IsMobile: () => boolean;
49
+ Init: (arg?: {
50
+ readyDeray?: number;
51
+ }) => Promise<void>;
52
+ }, "Init" | "GetUa" | "IsMobile">>;
@@ -1,59 +1,85 @@
1
1
  import { defineStore } from "pinia";
2
- import { nextTick } from "vue";
2
+ import { nextTick, reactive } from "vue";
3
3
  import { useEventListener } from "@vueuse/core";
4
- import { Sleep, IsMobile } from "../utils/com.js";
5
- export const useHsMisc = defineStore("HsMisc", {
6
- state: () => {
7
- return {
8
- state: {
9
- isInit: false,
10
- isReady: false,
11
- isMobile: IsMobile(),
12
- readyDeray: 10,
13
- window: {
14
- h: 0,
15
- w: 0
16
- },
17
- scrollbarWidth: 0
4
+ import { useRequestHeaders } from "#app";
5
+ import { Sleep } from "../utils/com.js";
6
+ export const useHsMisc = defineStore("HsMisc", () => {
7
+ const GetUa = () => {
8
+ try {
9
+ if (import.meta.client) {
10
+ if (navigator === void 0) return "";
11
+ return navigator.userAgent.toLowerCase();
18
12
  }
19
- };
20
- },
21
- // ----------------------------------------------------------------------------
22
- actions: {
23
- IsMobile() {
24
- return IsMobile();
25
- },
26
- // ---------------------
27
- async Init(arg) {
28
- await Sleep(0);
29
- const state = this.state;
30
- if (state.isInit) return;
31
- if (arg?.readyDeray) {
32
- state.readyDeray = arg.readyDeray;
13
+ if (import.meta.server) {
14
+ return useRequestHeaders(["User-Agent"])["user-agent"] || "";
33
15
  }
34
- state.isInit = true;
35
- state.isMobile = IsMobile();
36
- const initWindow = () => {
37
- useEventListener(window, "resize", () => {
38
- state.window = {
39
- h: window.innerHeight,
40
- w: window.innerWidth
41
- };
42
- state.scrollbarWidth = window.innerWidth - document.body.clientWidth < 0 ? 0 : window.innerWidth - document.body.clientWidth;
43
- });
16
+ return "";
17
+ } catch (err) {
18
+ console.error(err);
19
+ return "";
20
+ }
21
+ };
22
+ const IsTouchDevice = () => {
23
+ try {
24
+ if (import.meta.client) return "ontouchend" in document;
25
+ return false;
26
+ } catch (err) {
27
+ console.error(err);
28
+ return false;
29
+ }
30
+ };
31
+ const IsMobile = () => {
32
+ const ua = GetUa();
33
+ if (/android|ipod|ipad|iphone|macintosh/.test(ua) || IsTouchDevice()) {
34
+ return true;
35
+ } else {
36
+ return false;
37
+ }
38
+ };
39
+ const state = reactive({
40
+ isInit: false,
41
+ isReady: false,
42
+ isMobile: IsMobile(),
43
+ readyDeray: 10,
44
+ window: {
45
+ h: 0,
46
+ w: 0
47
+ },
48
+ scrollbarWidth: 0
49
+ });
50
+ const Init = async (arg) => {
51
+ await Sleep(0);
52
+ if (state.isInit) return;
53
+ if (arg?.readyDeray) {
54
+ state.readyDeray = arg.readyDeray;
55
+ }
56
+ state.isInit = true;
57
+ state.isMobile = IsMobile();
58
+ const initWindow = () => {
59
+ useEventListener(window, "resize", () => {
44
60
  state.window = {
45
61
  h: window.innerHeight,
46
62
  w: window.innerWidth
47
63
  };
48
- setTimeout(() => {
49
- state.scrollbarWidth = window.innerWidth - document.body.clientWidth < 0 ? 0 : window.innerWidth - document.body.clientWidth;
50
- }, 1e3);
64
+ state.scrollbarWidth = window.innerWidth - document.body.clientWidth < 0 ? 0 : window.innerWidth - document.body.clientWidth;
65
+ });
66
+ state.window = {
67
+ h: window.innerHeight,
68
+ w: window.innerWidth
51
69
  };
52
- initWindow();
53
- await Sleep(state.readyDeray);
54
- state.isReady = true;
55
- await nextTick();
56
- }
57
- // ---------------------
58
- }
70
+ setTimeout(() => {
71
+ state.scrollbarWidth = window.innerWidth - document.body.clientWidth < 0 ? 0 : window.innerWidth - document.body.clientWidth;
72
+ }, 1e3);
73
+ };
74
+ initWindow();
75
+ await Sleep(state.readyDeray);
76
+ state.isReady = true;
77
+ await nextTick();
78
+ };
79
+ return {
80
+ state,
81
+ GetUa,
82
+ IsMobile,
83
+ Init
84
+ };
59
85
  });
@@ -2,8 +2,3 @@
2
2
  export declare const GenerateUniqeKey: (len?: number) => string;
3
3
  /** 一定時間処理を待機 */
4
4
  export declare const Sleep: (time: number) => Promise<unknown>;
5
- export declare const GetUa: () => string;
6
- export declare const IsTouchDevice: () => boolean;
7
- /** モバイル系デバイスかどうかの判定
8
- * - ブラウザ側で実行すること */
9
- export declare const IsMobile: () => boolean;
@@ -1,5 +1,4 @@
1
1
  import dayjs from "dayjs/esm/index";
2
- import { useRequestHeaders } from "#app";
3
2
  export const GenerateUniqeKey = (len = 32) => {
4
3
  const S = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
5
4
  const word = len < 14 ? 14 : len - 15;
@@ -12,35 +11,3 @@ export const Sleep = (time) => {
12
11
  }, time);
13
12
  });
14
13
  };
15
- export const GetUa = () => {
16
- try {
17
- if (import.meta.client) {
18
- if (navigator === void 0) return "";
19
- return navigator.userAgent.toLowerCase();
20
- }
21
- if (import.meta.server) {
22
- return useRequestHeaders(["User-Agent"])["user-agent"] || "";
23
- }
24
- return "";
25
- } catch (err) {
26
- console.error(err);
27
- return "";
28
- }
29
- };
30
- export const IsTouchDevice = () => {
31
- try {
32
- if (import.meta.client) return "ontouchend" in document;
33
- return false;
34
- } catch (err) {
35
- console.error(err);
36
- return false;
37
- }
38
- };
39
- export const IsMobile = () => {
40
- const ua = GetUa();
41
- if (/android|ipod|ipad|iphone|macintosh/.test(ua) || IsTouchDevice()) {
42
- return true;
43
- } else {
44
- return false;
45
- }
46
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-hs-ui",
3
- "version": "2.1.12",
3
+ "version": "2.1.13",
4
4
  "description": "My new Nuxt module",
5
5
  "repository": "https://github.com/hare-systems-ryo/nuxt-hs-ui",
6
6
  "license": "MIT",