nuxt-hs-ui 1.0.1

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.
Files changed (54) hide show
  1. package/README.md +4 -0
  2. package/dist/module.cjs +5 -0
  3. package/dist/module.d.mts +8 -0
  4. package/dist/module.d.ts +8 -0
  5. package/dist/module.json +9 -0
  6. package/dist/module.mjs +92 -0
  7. package/dist/runtime/components/hs-fc/btn/index.vue +508 -0
  8. package/dist/runtime/components/hs-fc/btn/line-loading.vue +125 -0
  9. package/dist/runtime/components/hs-fc/hoge +0 -0
  10. package/dist/runtime/components/hs-ui/accordion.vue +93 -0
  11. package/dist/runtime/components/hs-ui/aspect-box.vue +78 -0
  12. package/dist/runtime/components/hs-ui/block-loading.vue +210 -0
  13. package/dist/runtime/components/hs-ui/card-item.vue +136 -0
  14. package/dist/runtime/components/hs-ui/card.vue +48 -0
  15. package/dist/runtime/components/hs-ui/container.vue +46 -0
  16. package/dist/runtime/components/hs-ui/dialog/index.type.d.ts +48 -0
  17. package/dist/runtime/components/hs-ui/dialog/index.type.js +57 -0
  18. package/dist/runtime/components/hs-ui/dialog/index.vue +353 -0
  19. package/dist/runtime/components/hs-ui/modal/bg.vue +90 -0
  20. package/dist/runtime/components/hs-ui/modal/index.vue +203 -0
  21. package/dist/runtime/components/hs-ui/modal/use-ui-modal.d.ts +20 -0
  22. package/dist/runtime/components/hs-ui/modal/use-ui-modal.js +74 -0
  23. package/dist/runtime/components/hs-ui/toast/index.type.d.ts +24 -0
  24. package/dist/runtime/components/hs-ui/toast/index.type.js +7 -0
  25. package/dist/runtime/components/hs-ui/toast/index.vue +355 -0
  26. package/dist/runtime/components/hs-ui/window-loader.vue +185 -0
  27. package/dist/runtime/components/v-test.vue +57 -0
  28. package/dist/runtime/composables/use-hs-form-focus.d.ts +10 -0
  29. package/dist/runtime/composables/use-hs-form-focus.js +29 -0
  30. package/dist/runtime/composables/use-hs-multi-lang.d.ts +9 -0
  31. package/dist/runtime/composables/use-hs-multi-lang.js +21 -0
  32. package/dist/runtime/composables/use-hs-ui-dialog.d.ts +22 -0
  33. package/dist/runtime/composables/use-hs-ui-dialog.js +43 -0
  34. package/dist/runtime/composables/use-hs-ui-toast.d.ts +20 -0
  35. package/dist/runtime/composables/use-hs-ui-toast.js +55 -0
  36. package/dist/runtime/composables/use-hs-ui-window-loader.d.ts +11 -0
  37. package/dist/runtime/composables/use-hs-ui-window-loader.js +21 -0
  38. package/dist/runtime/lib/class-style.d.ts +8 -0
  39. package/dist/runtime/lib/class-style.js +59 -0
  40. package/dist/runtime/lib/com.d.ts +14 -0
  41. package/dist/runtime/lib/com.js +25 -0
  42. package/dist/runtime/lib/multi-lang.d.ts +9 -0
  43. package/dist/runtime/lib/multi-lang.js +75 -0
  44. package/dist/runtime/lib/number.d.ts +16 -0
  45. package/dist/runtime/lib/number.js +101 -0
  46. package/dist/runtime/lib/prefix.d.ts +2 -0
  47. package/dist/runtime/lib/prefix.js +19 -0
  48. package/dist/runtime/lib/theme.d.ts +2 -0
  49. package/dist/runtime/lib/theme.js +21 -0
  50. package/dist/runtime/server/tsconfig.json +3 -0
  51. package/dist/runtime/style.css +1 -0
  52. package/dist/types.d.mts +17 -0
  53. package/dist/types.d.ts +17 -0
  54. package/package.json +82 -0
@@ -0,0 +1,185 @@
1
+ <script setup lang="ts">
2
+ /* ----------------------------------------------------------------------------
3
+ src\runtime\components\hs-ui\window-loader.vue
4
+ // ----------------------------------------------------------------------------
5
+ HsUiWindowLoader
6
+ HsUiWindowLoaderHsUiWindowLoader
7
+ ----------------------------------------------------------------------------- */
8
+
9
+ /* ----------------------------------------------------------------------------
10
+ const WindowLoader = useHsUiWindowLoader();
11
+ WindowLoader.Show()
12
+ WindowLoader.zindex=10000
13
+ ----------------------------------------------------------------------------- */
14
+
15
+ // [ vue ]
16
+ import { ref, watch } from 'vue';
17
+ import { useHsUiWindowLoader } from '../../composables/use-hs-ui-window-loader';
18
+ // [ vueuse ]
19
+ import { useFocusTrap } from '@vueuse/integrations/useFocusTrap';
20
+ // ----------------------------------------------------------------------------
21
+ const WindowLoader = useHsUiWindowLoader();
22
+ // ----------------------------------------------------------------------------
23
+ // [ focusTrap ]
24
+ const focusTargetElm = ref<HTMLElement | null>(null);
25
+ const { activate, deactivate } = useFocusTrap(focusTargetElm);
26
+ watch(
27
+ () => WindowLoader.state.show,
28
+ (show) => {
29
+ if (show) {
30
+ activate();
31
+ } else {
32
+ deactivate();
33
+ }
34
+ }
35
+ );
36
+ // ----------------------------------------------------------------------------
37
+ </script>
38
+ <template>
39
+ <div
40
+ ref="focusTargetElm"
41
+ class="HsUiWindowLoader"
42
+ :class="{ show: WindowLoader.state.show }"
43
+ :style="{ 'z-index': WindowLoader.state.zindex }"
44
+ >
45
+ <!-- -->
46
+ <!-- -->
47
+ <div class="HsUiWindowLoader-body">
48
+ <div class="sk-cube-grid">
49
+ <div class="sk-cube sk-cube1" />
50
+ <div class="sk-cube sk-cube2" />
51
+ <div class="sk-cube sk-cube3" />
52
+ <div class="sk-cube sk-cube4" />
53
+ <div class="sk-cube sk-cube5" />
54
+ <div class="sk-cube sk-cube6" />
55
+ <div class="sk-cube sk-cube7" />
56
+ <div class="sk-cube sk-cube8" />
57
+ <div class="sk-cube sk-cube9" />
58
+ </div>
59
+ <div class="HsUiWindowLoader-text">Please wait...</div>
60
+ <input type="checkbox" class="dummy" />
61
+ </div>
62
+ </div>
63
+ </template>
64
+
65
+ <style scoped>
66
+ .dummy {
67
+ opacity: 0;
68
+ -webkit-appearance: none;
69
+ -moz-appearance: none;
70
+ appearance: none;
71
+ outline: none;
72
+ }
73
+
74
+ .HsUiWindowLoader {
75
+ position: fixed;
76
+ left: 0;
77
+ top: 0;
78
+ right: 0;
79
+ bottom: 0;
80
+ background-color: rgba(0, 0, 0, 0.411);
81
+ display: flex;
82
+ justify-content: center;
83
+ align-items: center;
84
+ transition: opacity 300ms;
85
+ opacity: 0;
86
+ pointer-events: none;
87
+ overflow: hidden;
88
+ }
89
+ .HsUiWindowLoader.show {
90
+ pointer-events: all;
91
+ opacity: 1;
92
+ }
93
+ .HsUiWindowLoader .HsUiWindowLoader-body {
94
+ display: flex;
95
+ flex-direction: column;
96
+ justify-content: center;
97
+ align-items: center;
98
+ }
99
+ .HsUiWindowLoader .HsUiWindowLoader-text {
100
+ padding: 18px 0 0 0;
101
+ font-size: 20px;
102
+ line-height: 1em;
103
+ color: white;
104
+ -moz-user-select: none;
105
+ -webkit-user-select: none;
106
+ -ms-user-select: none;
107
+ user-select: none;
108
+ outline: none;
109
+ }
110
+ @media screen and (min-width: 0px) and (max-width: 599.9px) {
111
+ .HsUiWindowLoader .HsUiWindowLoader-text {
112
+ font-size: 16px;
113
+ }
114
+ }
115
+ .HsUiWindowLoader .HsUiWindowLoader-text:focus {
116
+ background-color: red;
117
+ }
118
+ .HsUiWindowLoader .sk-cube-grid {
119
+ width: 130px;
120
+ height: 130px;
121
+ display: flex;
122
+ flex-wrap: wrap;
123
+ justify-content: center;
124
+ align-items: center;
125
+ }
126
+ .HsUiWindowLoader .sk-cube {
127
+ width: calc(33.33% - 2px);
128
+ height: calc(33.33% - 2px);
129
+ margin: 1px;
130
+ background-color: rgba(37, 243, 233, 0.767);
131
+ animation: HsUiWindowLoader-anime 1.3s infinite ease-in-out;
132
+ }
133
+ .HsUiWindowLoader .sk-cube1 {
134
+ -webkit-animation-delay: 0.2s;
135
+ animation-delay: 0.2s;
136
+ }
137
+ .HsUiWindowLoader .sk-cube2 {
138
+ -webkit-animation-delay: 0.3s;
139
+ animation-delay: 0.3s;
140
+ }
141
+ .HsUiWindowLoader .sk-cube3 {
142
+ -webkit-animation-delay: 0.4s;
143
+ animation-delay: 0.4s;
144
+ }
145
+ .HsUiWindowLoader .sk-cube4 {
146
+ -webkit-animation-delay: 0.1s;
147
+ animation-delay: 0.1s;
148
+ }
149
+ .HsUiWindowLoader .sk-cube5 {
150
+ -webkit-animation-delay: 0.2s;
151
+ animation-delay: 0.2s;
152
+ }
153
+ .HsUiWindowLoader .sk-cube6 {
154
+ -webkit-animation-delay: 0.3s;
155
+ animation-delay: 0.3s;
156
+ }
157
+ .HsUiWindowLoader .sk-cube7 {
158
+ -webkit-animation-delay: 0s;
159
+ animation-delay: 0s;
160
+ }
161
+ .HsUiWindowLoader .sk-cube8 {
162
+ -webkit-animation-delay: 0.1s;
163
+ animation-delay: 0.1s;
164
+ }
165
+ .HsUiWindowLoader .sk-cube9 {
166
+ -webkit-animation-delay: 0.2s;
167
+ animation-delay: 0.2s;
168
+ }
169
+ </style>
170
+
171
+ <style lang="scss">
172
+ @keyframes HsUiWindowLoader-anime {
173
+ 0%,
174
+ 70%,
175
+ 100% {
176
+ -webkit-transform: scale3D(1, 1, 1);
177
+ transform: scale3D(1, 1, 1);
178
+ }
179
+
180
+ 35% {
181
+ -webkit-transform: scale3D(0, 0, 1);
182
+ transform: scale3D(0, 0, 1);
183
+ }
184
+ }
185
+ </style>
@@ -0,0 +1,57 @@
1
+ <script setup lang="ts">
2
+ // [ vue ]
3
+
4
+ import { computed, ref } from 'vue';
5
+ // [ tailwind ]
6
+ import { extendTailwindMerge } from 'tailwind-merge';
7
+ import { type ClassType, ClassTypeToString } from '../lib/com';
8
+ import { GetPrefix, RemovePrefix } from '../lib/prefix';
9
+
10
+ // ----------------------------------------------------------------------------
11
+ const twMerge = extendTailwindMerge({
12
+ prefix: GetPrefix(),
13
+ });
14
+ // ----------------------------------------------------------------------------
15
+
16
+ interface Props {
17
+ class?: ClassType;
18
+ text?: string;
19
+ }
20
+ const props = withDefaults(defineProps<Props>(), {
21
+ text: 'hello',
22
+ class: '',
23
+ });
24
+
25
+ const baseClass = RemovePrefix([
26
+ //
27
+ 'bg-blue-400',
28
+ 'tw-bg-blue-400',
29
+ `m-0`,
30
+ `sm:m-4`,
31
+ `tw-m-0`,
32
+ `sm:tw-m-4`,
33
+ ]);
34
+
35
+ const topClass = computed(() => {
36
+ return twMerge(baseClass, ClassTypeToString(props.class));
37
+ });
38
+ const counter = ref(0);
39
+ </script>
40
+ <template>
41
+ <div class="tw-my-3">
42
+ <button class="text-message" :class="topClass" @click="counter++">
43
+ {{ topClass }}
44
+ </button>
45
+ </div>
46
+ </template>
47
+
48
+ <style scoped>
49
+ .text-message {
50
+ color: black;
51
+ border: solid 2px rgb(227, 123, 27);
52
+ padding: 2px 10px;
53
+ border-radius: 4px;
54
+ outline: none;
55
+ font-weight: bold;
56
+ }
57
+ </style>
@@ -0,0 +1,10 @@
1
+ interface State {
2
+ state: {
3
+ isInit: boolean;
4
+ id: string;
5
+ };
6
+ }
7
+ export declare const useHsFormFocus: import("pinia").StoreDefinition<"HsFormFocus", State, {}, {
8
+ Init(): Promise<void>;
9
+ }>;
10
+ export {};
@@ -0,0 +1,29 @@
1
+ import { watch } from "vue";
2
+ import { defineStore } from "pinia";
3
+ import { useRoute } from "#imports";
4
+ export const useHsFormFocus = defineStore({
5
+ id: "HsFormFocus",
6
+ state: () => {
7
+ return {
8
+ state: {
9
+ isInit: false,
10
+ id: ""
11
+ }
12
+ };
13
+ },
14
+ actions: {
15
+ async Init() {
16
+ const state = this.state;
17
+ if (state.isInit)
18
+ return;
19
+ const route = useRoute();
20
+ watch(
21
+ () => route.fullPath,
22
+ () => {
23
+ state.id = "";
24
+ }
25
+ );
26
+ }
27
+ // ---------------------------------------------------
28
+ }
29
+ });
@@ -0,0 +1,9 @@
1
+ import { type MultiLang } from '../lib/multi-lang.js';
2
+ export interface StoreState {
3
+ lang: string;
4
+ fallback: string;
5
+ }
6
+ export declare const useHsMultiLang: import("pinia").StoreDefinition<"HsMultiLang", StoreState, {}, {
7
+ MultiLangText(text: MultiLang): string;
8
+ GetTextByMultiLang: (text: MultiLang, lang: string | undefined, fallback?: string | undefined) => string;
9
+ }>;
@@ -0,0 +1,21 @@
1
+ import { computed } from "vue";
2
+ import { defineStore } from "pinia";
3
+ import { GetTextByMultiLang } from "../lib/multi-lang.js";
4
+ export const useHsMultiLang = defineStore({
5
+ id: "HsMultiLang",
6
+ state: () => {
7
+ return {
8
+ lang: "ja",
9
+ fallback: "ja"
10
+ };
11
+ },
12
+ // ----------------------------------------------------------------------------
13
+ actions: {
14
+ MultiLangText(text) {
15
+ return computed(() => {
16
+ return GetTextByMultiLang(text, this.lang, this.fallback);
17
+ }).value;
18
+ },
19
+ GetTextByMultiLang
20
+ }
21
+ });
@@ -0,0 +1,22 @@
1
+ import { type MultiLang } from '../lib/multi-lang.js';
2
+ import { DialogItem, DialogResult, type DialogOption } from '../components/hs-ui/dialog/index.type.js';
3
+ interface State {
4
+ state: {
5
+ id: number;
6
+ pendingList: {
7
+ ts: string;
8
+ data: DialogItem;
9
+ }[];
10
+ };
11
+ }
12
+ export declare const useHsUiDialog: import("pinia").StoreDefinition<"HsUiDialog", State, {
13
+ InitOption: () => () => DialogOption;
14
+ Result: () => {
15
+ readonly left: "left";
16
+ readonly right: "right";
17
+ readonly cancel: "cancel";
18
+ };
19
+ }, {
20
+ Show(message: MultiLang, title: MultiLang, option?: DialogOption): Promise<DialogResult>;
21
+ }>;
22
+ export {};
@@ -0,0 +1,43 @@
1
+ import dayjs from "dayjs";
2
+ import { defineStore } from "pinia";
3
+ import { GenerateUniqeKey } from "../lib/com.js";
4
+ import { DialogItem, InitDialogOption, DialogResult } from "../components/hs-ui/dialog/index.type.js";
5
+ export const useHsUiDialog = defineStore({
6
+ id: "HsUiDialog",
7
+ state: () => {
8
+ return {
9
+ state: {
10
+ id: 0,
11
+ pendingList: []
12
+ }
13
+ };
14
+ },
15
+ getters: {
16
+ // hoge: (state) => {
17
+ // return '';
18
+ // },
19
+ InitOption: () => {
20
+ return InitDialogOption;
21
+ },
22
+ Result: () => {
23
+ return DialogResult;
24
+ }
25
+ },
26
+ actions: {
27
+ async Show(message, title, option = InitDialogOption()) {
28
+ if (import.meta.server)
29
+ return DialogResult.cancel;
30
+ const item = new DialogItem(message, title, option);
31
+ const pendingList = this.state.pendingList;
32
+ const ts = GenerateUniqeKey() + dayjs().format("x");
33
+ pendingList.push({
34
+ ts,
35
+ data: item
36
+ });
37
+ const ret = await item.show();
38
+ this.state.pendingList = this.state.pendingList.filter((row) => row.ts !== ts);
39
+ return ret;
40
+ }
41
+ // ---------------------------------------------------
42
+ }
43
+ });
@@ -0,0 +1,20 @@
1
+ import { type MultiLang } from '../lib/multi-lang.js';
2
+ import { type Message } from '../components/hs-ui/toast/index.type.js';
3
+ interface State {
4
+ state: {
5
+ id: number;
6
+ pendingList: Message[];
7
+ zindex: number;
8
+ };
9
+ }
10
+ export declare const useHsUiToast: import("pinia").StoreDefinition<"HsUiToast", State, {}, {
11
+ s(message: MultiLang, title: MultiLang, hideAfter?: number): void;
12
+ Success(message: MultiLang, title: MultiLang, hideAfter?: number): void;
13
+ Info(message: MultiLang, title: MultiLang, hideAfter?: number): void;
14
+ i(message: MultiLang, title: MultiLang, hideAfter?: number): void;
15
+ w(message: MultiLang, title: MultiLang, hideAfter?: number): void;
16
+ Warning(message: MultiLang, title: MultiLang, hideAfter?: number): void;
17
+ e(message: MultiLang, title: MultiLang, hideAfter?: number): void;
18
+ Error(message: MultiLang, title: MultiLang, hideAfter?: number): void;
19
+ }>;
20
+ export {};
@@ -0,0 +1,55 @@
1
+ import { defineStore } from "pinia";
2
+ import { GenerateUniqeKey } from "../lib/com.js";
3
+ import { Theme } from "../components/hs-ui/toast/index.type.js";
4
+ const toastShow = (message, title, hideAfter, theme) => {
5
+ const toast = useHsUiToast();
6
+ const newToast = {
7
+ key: GenerateUniqeKey(),
8
+ isShow: true,
9
+ title,
10
+ message,
11
+ hideAfter,
12
+ barWidth: 0,
13
+ theme
14
+ };
15
+ toast.state.pendingList.push(newToast);
16
+ };
17
+ export const useHsUiToast = defineStore({
18
+ id: "HsUiToast",
19
+ state: () => {
20
+ return {
21
+ state: {
22
+ id: 0,
23
+ pendingList: [],
24
+ zindex: 10002
25
+ }
26
+ };
27
+ },
28
+ actions: {
29
+ s(message, title, hideAfter = 0) {
30
+ toastShow(message, title, hideAfter, Theme.Success);
31
+ },
32
+ Success(message, title, hideAfter = 0) {
33
+ toastShow(message, title, hideAfter, Theme.Success);
34
+ },
35
+ Info(message, title, hideAfter = 0) {
36
+ toastShow(message, title, hideAfter, Theme.Info);
37
+ },
38
+ i(message, title, hideAfter = 0) {
39
+ toastShow(message, title, hideAfter, Theme.Info);
40
+ },
41
+ w(message, title, hideAfter = 0) {
42
+ toastShow(message, title, hideAfter, Theme.Warning);
43
+ },
44
+ Warning(message, title, hideAfter = 0) {
45
+ toastShow(message, title, hideAfter, Theme.Warning);
46
+ },
47
+ e(message, title, hideAfter = 0) {
48
+ toastShow(message, title, hideAfter, Theme.Error);
49
+ },
50
+ Error(message, title, hideAfter = 0) {
51
+ toastShow(message, title, hideAfter, Theme.Error);
52
+ }
53
+ // ---------------------------------------------------
54
+ }
55
+ });
@@ -0,0 +1,11 @@
1
+ interface State {
2
+ state: {
3
+ show: boolean;
4
+ zindex: number;
5
+ };
6
+ }
7
+ export declare const useHsUiWindowLoader: import("pinia").StoreDefinition<"HsUiWindowLoader", State, {}, {
8
+ Show(): Promise<void>;
9
+ Hide(): Promise<void>;
10
+ }>;
11
+ export {};
@@ -0,0 +1,21 @@
1
+ import { defineStore } from "pinia";
2
+ export const useHsUiWindowLoader = defineStore({
3
+ id: "HsUiWindowLoader",
4
+ state: () => {
5
+ return {
6
+ state: {
7
+ show: false,
8
+ zindex: 1e4
9
+ }
10
+ };
11
+ },
12
+ actions: {
13
+ async Show() {
14
+ this.state.show = true;
15
+ },
16
+ async Hide() {
17
+ this.state.show = false;
18
+ }
19
+ // ---------------------------------------------------
20
+ }
21
+ });
@@ -0,0 +1,8 @@
1
+ type ClassTypeObje = {
2
+ [key: string]: boolean;
3
+ };
4
+ type ClassTypeArray = (string | ClassTypeObje | ClassTypeArray)[];
5
+ export type ClassType = string | ClassTypeObje | ClassTypeArray;
6
+ export declare const ClassTypeToString: (c: ClassType | undefined) => string;
7
+ export declare const ClassTypeToArray: (c: ClassType | undefined) => string[];
8
+ export {};
@@ -0,0 +1,59 @@
1
+ const typeOf = (obj) => {
2
+ return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
3
+ };
4
+ export const ClassTypeToString = (c) => {
5
+ if (c === void 0)
6
+ return "";
7
+ const valueType = typeOf(c);
8
+ if (valueType === "string")
9
+ return c;
10
+ if (valueType === "undefined")
11
+ return "";
12
+ if (valueType === "array") {
13
+ return c.reduce((ret, row) => {
14
+ const a = ClassTypeToString(row);
15
+ if (a) {
16
+ ret.push(a);
17
+ }
18
+ return ret;
19
+ }, []).join(" ");
20
+ }
21
+ if (valueType === "object") {
22
+ return Object.keys(c).reduce((ret, key) => {
23
+ const b = c[key];
24
+ if (b) {
25
+ ret.push(key);
26
+ }
27
+ return ret;
28
+ }, []).join(" ");
29
+ }
30
+ return "";
31
+ };
32
+ export const ClassTypeToArray = (c) => {
33
+ if (c === void 0)
34
+ return [];
35
+ const valueType = typeOf(c);
36
+ if (valueType === "string")
37
+ return [c];
38
+ if (valueType === "undefined")
39
+ return [];
40
+ if (valueType === "array") {
41
+ return c.reduce((ret, row) => {
42
+ const a = ClassTypeToString(row);
43
+ if (a) {
44
+ ret.push(a);
45
+ }
46
+ return ret;
47
+ }, []);
48
+ }
49
+ if (valueType === "object") {
50
+ return Object.keys(c).reduce((ret, key) => {
51
+ const b = c[key];
52
+ if (b) {
53
+ ret.push(key);
54
+ }
55
+ return ret;
56
+ }, []);
57
+ }
58
+ return [];
59
+ };
@@ -0,0 +1,14 @@
1
+ export { type ClassType, ClassTypeToString } from './class-style.js';
2
+ export { RemovePrefix } from './prefix.js';
3
+ /**
4
+ * ユニークな文字列を生成する
5
+ */
6
+ export declare const GenerateUniqeKey: (len?: number) => string;
7
+ /**
8
+ * 一定時間処理を待機
9
+ */
10
+ export declare const Sleep: (time: number) => Promise<unknown>;
11
+ /**
12
+ * マウント後にブラウザ側で実行すること
13
+ */
14
+ export declare const IsMobile: () => boolean;
@@ -0,0 +1,25 @@
1
+ import dayjs from "dayjs";
2
+ export { ClassTypeToString } from "./class-style.js";
3
+ export { RemovePrefix } from "./prefix.js";
4
+ export const GenerateUniqeKey = (len = 32) => {
5
+ const S = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
6
+ const word = len < 14 ? 14 : len - 15;
7
+ return dayjs().format("YYYYMMDDHHmmssSSS") + "_" + Array.from(Array(word)).map(() => S[Math.floor(Math.random() * S.length)]).join("");
8
+ };
9
+ export const Sleep = (time) => {
10
+ return new Promise((resolve) => {
11
+ setTimeout(() => {
12
+ resolve(true);
13
+ }, time);
14
+ });
15
+ };
16
+ export const IsMobile = () => {
17
+ if (navigator === void 0)
18
+ return false;
19
+ const userAgent = navigator.userAgent.toLowerCase();
20
+ if (/android|ipod|ipad|iphone|macintosh/.test(userAgent) && "ontouchend" in document) {
21
+ return true;
22
+ } else {
23
+ return false;
24
+ }
25
+ };
@@ -0,0 +1,9 @@
1
+ export type MultiLang = string | {
2
+ [key: string]: string;
3
+ };
4
+ export declare const GetTextByMultiLang: (text: MultiLang, lang: string | undefined, fallback?: string | undefined) => string;
5
+ /**
6
+ * 複数のマルチ言語データを結合します
7
+ * @returns MultiLangオブジェクト
8
+ */
9
+ export declare const JoinMultiLang: (list: MultiLang[], seq?: string) => MultiLang;
@@ -0,0 +1,75 @@
1
+ const isObject = (value) => {
2
+ return value !== null && typeof value === "object";
3
+ };
4
+ export const GetTextByMultiLang = (text, lang, fallback = "ja") => {
5
+ if (lang === void 0) {
6
+ lang = "ja";
7
+ }
8
+ const textIsObject = isObject(text);
9
+ if (!textIsObject) {
10
+ return String(text);
11
+ }
12
+ if (lang in text) {
13
+ return text[lang];
14
+ } else if (fallback in text) {
15
+ console.error(`GetTextByMultiLang :: Language fallback [${lang} -> ${fallback}]`, text);
16
+ return text.ja;
17
+ } else {
18
+ console.error(`GetTextByMultiLang :: Language Error [${lang}]`, text);
19
+ return JSON.stringify(text);
20
+ }
21
+ };
22
+ export const JoinMultiLang = (list, seq = "\n") => {
23
+ if (Array.isArray(list) === false)
24
+ return "";
25
+ if (list.length === 0)
26
+ return "";
27
+ const temp = list.map((row) => {
28
+ return { type: isObject(row) ? "object" : "string", multiLang: row };
29
+ });
30
+ const langList = temp.reduce((ret, row) => {
31
+ if (row.type === "string")
32
+ return ret;
33
+ Object.keys(row.multiLang).forEach((key) => {
34
+ if (!ret.includes(key))
35
+ ret.push(key);
36
+ });
37
+ return ret;
38
+ }, []);
39
+ if (langList.length === 0) {
40
+ return list.filter((row) => row !== "").join(seq);
41
+ }
42
+ const multiData = langList.reduce((ret, lang) => {
43
+ ret[lang] = [];
44
+ return ret;
45
+ }, {});
46
+ temp.forEach((row) => {
47
+ if (row.type === "string") {
48
+ if (row.multiLang !== "") {
49
+ langList.forEach((lang) => {
50
+ multiData[lang].push(String(row.multiLang));
51
+ });
52
+ }
53
+ } else if (row.type === "object") {
54
+ langList.forEach((lang) => {
55
+ const langText = row.multiLang;
56
+ if (lang in langText) {
57
+ if (!langText[lang])
58
+ return;
59
+ multiData[lang].push(langText[lang]);
60
+ } else if ("ja" in langText) {
61
+ if (!langText.ja)
62
+ return;
63
+ multiData[lang].push(langText.ja);
64
+ console.error(`JoinMultiLang :: Language fallback [${lang} -> ja]`, row.multiLang);
65
+ } else {
66
+ console.error(`JoinMultiLang :: Language Error [${lang} -> ja]`, row.multiLang);
67
+ }
68
+ });
69
+ }
70
+ });
71
+ return Object.keys(multiData).reduce((ret, lang) => {
72
+ ret[lang] = multiData[lang].join(seq);
73
+ return ret;
74
+ }, {});
75
+ };