nuxt-hs-ui 2.1.12 → 2.1.14

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.14",
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,79 @@
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 IsMobile = () => {
23
+ const ua = GetUa();
24
+ if (/\(iPad.*OS/i.test(ua)) return true;
25
+ if (/iP(?:ad|hone|od)/i.test(ua)) return true;
26
+ if (/android|ipod|ipad|iphone|mobile/i.test(ua)) return true;
27
+ if (/Macintosh/.test(ua) && import.meta.client) {
28
+ if (navigator === void 0) return false;
29
+ return navigator.maxTouchPoints > 1;
30
+ }
31
+ return false;
32
+ };
33
+ const state = reactive({
34
+ isInit: false,
35
+ isReady: false,
36
+ isMobile: IsMobile(),
37
+ readyDeray: 10,
38
+ window: {
39
+ h: 0,
40
+ w: 0
41
+ },
42
+ scrollbarWidth: 0
43
+ });
44
+ const Init = async (arg) => {
45
+ await Sleep(0);
46
+ if (state.isInit) return;
47
+ if (arg?.readyDeray) {
48
+ state.readyDeray = arg.readyDeray;
49
+ }
50
+ state.isInit = true;
51
+ state.isMobile = IsMobile();
52
+ const initWindow = () => {
53
+ useEventListener(window, "resize", () => {
44
54
  state.window = {
45
55
  h: window.innerHeight,
46
56
  w: window.innerWidth
47
57
  };
48
- setTimeout(() => {
49
- state.scrollbarWidth = window.innerWidth - document.body.clientWidth < 0 ? 0 : window.innerWidth - document.body.clientWidth;
50
- }, 1e3);
58
+ state.scrollbarWidth = window.innerWidth - document.body.clientWidth < 0 ? 0 : window.innerWidth - document.body.clientWidth;
59
+ });
60
+ state.window = {
61
+ h: window.innerHeight,
62
+ w: window.innerWidth
51
63
  };
52
- initWindow();
53
- await Sleep(state.readyDeray);
54
- state.isReady = true;
55
- await nextTick();
56
- }
57
- // ---------------------
58
- }
64
+ setTimeout(() => {
65
+ state.scrollbarWidth = window.innerWidth - document.body.clientWidth < 0 ? 0 : window.innerWidth - document.body.clientWidth;
66
+ }, 1e3);
67
+ };
68
+ initWindow();
69
+ await Sleep(state.readyDeray);
70
+ state.isReady = true;
71
+ await nextTick();
72
+ };
73
+ return {
74
+ state,
75
+ GetUa,
76
+ IsMobile,
77
+ Init
78
+ };
59
79
  });
@@ -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.14",
4
4
  "description": "My new Nuxt module",
5
5
  "repository": "https://github.com/hare-systems-ryo/nuxt-hs-ui",
6
6
  "license": "MIT",