@movk/nuxt 1.1.1 → 1.2.0
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/README.md +5 -29
- package/dist/module.d.mts +3 -31
- package/dist/module.json +3 -3
- package/dist/module.mjs +135 -77
- package/dist/runtime/auto-form/controls.d.ts +221 -0
- package/dist/runtime/auto-form/controls.js +70 -0
- package/dist/runtime/{utils → auto-form}/field-utils.d.ts +4 -20
- package/dist/runtime/{utils → auto-form}/field-utils.js +1 -2
- package/dist/runtime/auto-form/metadata.d.ts +22 -0
- package/dist/runtime/auto-form/metadata.js +53 -0
- package/dist/runtime/auto-form/provider.d.ts +27 -0
- package/dist/runtime/{internal/useAutoFormProvider.js → auto-form/provider.js} +1 -1
- package/dist/runtime/{utils → auto-form}/reactive-utils.d.ts +4 -22
- package/dist/runtime/{utils → auto-form}/schema-introspector.d.ts +3 -9
- package/dist/runtime/{utils → auto-form}/schema-introspector.js +11 -9
- package/dist/runtime/components/AutoForm.d.vue.ts +4 -5
- package/dist/runtime/components/AutoForm.vue +12 -35
- package/dist/runtime/components/AutoForm.vue.d.ts +4 -5
- package/dist/runtime/components/ColorChooser.d.vue.ts +10 -6
- package/dist/runtime/components/ColorChooser.vue +4 -7
- package/dist/runtime/components/ColorChooser.vue.d.ts +10 -6
- package/dist/runtime/components/DatePicker.d.vue.ts +16 -10
- package/dist/runtime/components/DatePicker.vue.d.ts +16 -10
- package/dist/runtime/components/SearchForm.d.vue.ts +171 -0
- package/dist/runtime/components/SearchForm.vue +216 -0
- package/dist/runtime/components/SearchForm.vue.d.ts +171 -0
- package/dist/runtime/components/SlideVerify.d.vue.ts +5 -32
- package/dist/runtime/components/SlideVerify.vue +4 -4
- package/dist/runtime/components/SlideVerify.vue.d.ts +5 -32
- package/dist/runtime/components/StarRating.d.vue.ts +8 -16
- package/dist/runtime/components/StarRating.vue +50 -65
- package/dist/runtime/components/StarRating.vue.d.ts +8 -16
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.d.vue.ts +10 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue +16 -23
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue.d.ts +10 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.d.vue.ts +26 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.vue +50 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.vue.d.ts +26 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue +2 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue.d.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue +29 -64
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue.d.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue +15 -69
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue.d.ts +8 -2
- package/dist/runtime/components/input/AsPhoneNumberInput.d.vue.ts +36 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue +35 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue.d.ts +36 -0
- package/dist/runtime/components/input/WithCharacterLimit.d.vue.ts +17 -9
- package/dist/runtime/components/input/WithCharacterLimit.vue +5 -5
- package/dist/runtime/components/input/WithCharacterLimit.vue.d.ts +17 -9
- package/dist/runtime/components/input/WithClear.d.vue.ts +13 -9
- package/dist/runtime/components/input/WithClear.vue +2 -2
- package/dist/runtime/components/input/WithClear.vue.d.ts +13 -9
- package/dist/runtime/components/input/WithCopy.d.vue.ts +16 -10
- package/dist/runtime/components/input/WithCopy.vue +3 -3
- package/dist/runtime/components/input/WithCopy.vue.d.ts +16 -10
- package/dist/runtime/components/input/WithFloatingLabel.d.vue.ts +36 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue +67 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue.d.ts +36 -0
- package/dist/runtime/components/input/WithPasswordToggle.d.vue.ts +11 -9
- package/dist/runtime/components/input/WithPasswordToggle.vue +3 -3
- package/dist/runtime/components/input/WithPasswordToggle.vue.d.ts +11 -9
- package/dist/runtime/components/theme-picker/ThemePicker.d.vue.ts +1 -1
- package/dist/runtime/components/theme-picker/ThemePicker.vue +19 -25
- package/dist/runtime/components/theme-picker/ThemePicker.vue.d.ts +1 -1
- package/dist/runtime/components/theme-picker/ThemePickerButton.d.vue.ts +1 -7
- package/dist/runtime/components/theme-picker/ThemePickerButton.vue.d.ts +1 -7
- package/dist/runtime/composables/index.d.ts +8 -0
- package/dist/runtime/composables/index.js +8 -0
- package/dist/runtime/composables/useApiFetch.d.ts +17 -14
- package/dist/runtime/composables/useApiFetch.js +3 -28
- package/dist/runtime/composables/useAutoForm.d.ts +14 -98
- package/dist/runtime/composables/useAutoForm.js +37 -157
- package/dist/runtime/composables/useClientApiFetch.d.ts +5 -6
- package/dist/runtime/composables/useDownloadWithProgress.js +5 -6
- package/dist/runtime/composables/useLazyApiFetch.d.ts +18 -0
- package/dist/runtime/composables/useLazyApiFetch.js +4 -0
- package/dist/runtime/composables/useTheme.d.ts +17 -14
- package/dist/runtime/composables/useTheme.js +68 -72
- package/dist/runtime/composables/useUploadWithProgress.d.ts +2 -2
- package/dist/runtime/composables/useUploadWithProgress.js +7 -7
- package/dist/runtime/constants/api-defaults.d.ts +9 -0
- package/dist/runtime/constants/api-defaults.js +32 -0
- package/dist/runtime/constants/auto-form.d.ts +0 -2
- package/dist/runtime/constants/auto-form.js +0 -25
- package/dist/runtime/constants/grid-cols.d.ts +7 -0
- package/dist/runtime/constants/grid-cols.js +44 -0
- package/dist/runtime/plugins/api.factory.js +78 -121
- package/dist/runtime/plugins/theme.js +44 -64
- package/dist/runtime/style.css +1 -1
- package/dist/runtime/types/api.d.ts +277 -146
- package/dist/runtime/types/auto-form.d.ts +122 -411
- package/dist/runtime/types/index.d.ts +3 -2
- package/dist/runtime/types/index.js +3 -2
- package/dist/runtime/types/module.d.ts +96 -0
- package/dist/runtime/types/theme.d.ts +2 -0
- package/dist/runtime/types/zod.d.ts +11 -10
- package/dist/runtime/utils/api-utils.d.ts +27 -48
- package/dist/runtime/utils/api-utils.js +18 -47
- package/dist/runtime/utils/meta.d.ts +7 -0
- package/dist/runtime/utils/meta.js +16 -0
- package/dist/types.d.mts +6 -2
- package/package.json +68 -37
- package/dist/runtime/composables/useApiAuth.d.ts +0 -47
- package/dist/runtime/composables/useApiAuth.js +0 -66
- package/dist/runtime/internal/useAutoFormProvider.d.ts +0 -50
- package/dist/runtime/schemas/api.d.ts +0 -590
- package/dist/runtime/schemas/api.js +0 -228
- package/dist/runtime/server/api/_movk/session.post.d.ts +0 -10
- package/dist/runtime/server/api/_movk/session.post.js +0 -18
- package/dist/runtime/types/auth.d.ts +0 -34
- package/dist/runtime/types/auto-form-renderer.d.ts +0 -22
- package/dist/runtime/types/components.d.ts +0 -43
- package/dist/runtime/utils/auto-form.d.ts +0 -3
- package/dist/runtime/utils/auto-form.js +0 -18
- /package/dist/runtime/{utils → auto-form}/reactive-utils.js +0 -0
- /package/dist/runtime/types/{auto-form-renderer.js → module.js} +0 -0
- /package/dist/runtime/types/{components.js → theme.js} +0 -0
|
@@ -1,157 +1,109 @@
|
|
|
1
|
-
import { getPath, triggerDownload, extractFilename } from "@movk/core";
|
|
2
1
|
import {
|
|
3
2
|
showToast,
|
|
4
3
|
isBusinessSuccess,
|
|
5
4
|
extractMessage,
|
|
6
|
-
|
|
5
|
+
extractData,
|
|
6
|
+
createApiError,
|
|
7
|
+
extractToastMessage,
|
|
8
|
+
getAuthHeaders
|
|
7
9
|
} from "../utils/api-utils.js";
|
|
8
10
|
import { defineNuxtPlugin, navigateTo, useNuxtApp, useUserSession, useRuntimeConfig } from "#imports";
|
|
9
11
|
import defu from "defu";
|
|
10
|
-
function
|
|
11
|
-
try {
|
|
12
|
-
const nuxtApp = useNuxtApp();
|
|
13
|
-
return nuxtApp.runWithContext(() => useUserSession());
|
|
14
|
-
} catch {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function getTokenFromSession(tokenPath) {
|
|
19
|
-
const userSession = getUserSession();
|
|
20
|
-
if (!userSession?.session?.value) return null;
|
|
21
|
-
const sessionData = userSession.session.value;
|
|
22
|
-
return getPath(sessionData, tokenPath) || null;
|
|
23
|
-
}
|
|
24
|
-
function buildAuthHeader(token, config) {
|
|
25
|
-
const tokenType = config.tokenType === "Custom" ? config.customTokenType || "" : config.tokenType || "Bearer";
|
|
26
|
-
return tokenType ? `${tokenType} ${token}` : token;
|
|
27
|
-
}
|
|
28
|
-
async function handleUnauthorized(config) {
|
|
29
|
-
const userSession = getUserSession();
|
|
12
|
+
async function handleUnauthorized(config, nuxtApp) {
|
|
30
13
|
const unauthorizedConfig = config.unauthorized;
|
|
31
|
-
if (unauthorizedConfig
|
|
32
|
-
|
|
14
|
+
if (!unauthorizedConfig) return;
|
|
15
|
+
if (unauthorizedConfig.clearSession) {
|
|
16
|
+
try {
|
|
17
|
+
const userSession = nuxtApp.vueApp.runWithContext(() => useUserSession());
|
|
18
|
+
if (userSession?.clear) {
|
|
19
|
+
await userSession.clear();
|
|
20
|
+
await userSession.fetch();
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
33
24
|
}
|
|
34
|
-
if (unauthorizedConfig
|
|
25
|
+
if (unauthorizedConfig.redirect) {
|
|
35
26
|
const loginPath = unauthorizedConfig.loginPath || "/login";
|
|
36
|
-
const nuxtApp = useNuxtApp();
|
|
37
27
|
await nuxtApp.runWithContext(() => navigateTo(loginPath));
|
|
38
28
|
}
|
|
39
29
|
}
|
|
40
|
-
function getApiFetchContext(
|
|
41
|
-
return
|
|
30
|
+
function getApiFetchContext(options) {
|
|
31
|
+
return options.context || {};
|
|
42
32
|
}
|
|
43
|
-
function
|
|
33
|
+
function createEndpointFetch(resolvedConfig, publicConfig, nuxtApp) {
|
|
44
34
|
const { auth: authConfig, toast: toastConfig, response: responseConfig } = resolvedConfig;
|
|
45
|
-
return {
|
|
46
|
-
|
|
35
|
+
return $fetch.create({
|
|
36
|
+
baseURL: resolvedConfig.baseURL,
|
|
37
|
+
headers: resolvedConfig.headers,
|
|
38
|
+
async onRequest(context) {
|
|
47
39
|
if (authConfig.enabled) {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const headerValue = buildAuthHeader(token, authConfig);
|
|
53
|
-
context.options.headers = context.options.headers || new Headers();
|
|
54
|
-
if (context.options.headers instanceof Headers) {
|
|
55
|
-
context.options.headers.set(headerName, headerValue);
|
|
56
|
-
} else {
|
|
57
|
-
context.options.headers[headerName] = headerValue;
|
|
58
|
-
}
|
|
40
|
+
const authHeaders = getAuthHeaders({ auth: authConfig });
|
|
41
|
+
const headers = new Headers(context.options.headers);
|
|
42
|
+
for (const [key, value] of Object.entries(authHeaders)) {
|
|
43
|
+
headers.set(key, value);
|
|
59
44
|
}
|
|
45
|
+
context.options.headers = headers;
|
|
60
46
|
}
|
|
61
47
|
if (publicConfig.debug) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
48
|
+
const h = context.options.headers;
|
|
49
|
+
const headersLog = h instanceof Headers ? Object.fromEntries(h.entries()) : h;
|
|
50
|
+
console.log("[Movk API] Request:", {
|
|
51
|
+
method: context.options.method || "GET",
|
|
52
|
+
url: `${resolvedConfig.baseURL}${context.request}`,
|
|
53
|
+
headers: headersLog,
|
|
54
|
+
body: context.options.body ? "(body present)" : void 0
|
|
55
|
+
});
|
|
68
56
|
}
|
|
57
|
+
await nuxtApp.callHook("movk:api:request", context);
|
|
69
58
|
},
|
|
70
59
|
async onResponse(context) {
|
|
71
|
-
const
|
|
72
|
-
const
|
|
60
|
+
const raw = context.response._data;
|
|
61
|
+
const { toast, skipBusinessCheck } = getApiFetchContext(context.options);
|
|
73
62
|
if (publicConfig.debug) {
|
|
74
|
-
console.log("[Movk API] Response:",
|
|
63
|
+
console.log("[Movk API] Response:", raw);
|
|
75
64
|
}
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
65
|
+
if (skipBusinessCheck || isBusinessSuccess(raw, responseConfig)) {
|
|
66
|
+
context.response._data = extractData(raw, responseConfig);
|
|
67
|
+
await nuxtApp.callHook("movk:api:response", context);
|
|
68
|
+
if (import.meta.client) {
|
|
69
|
+
const message = toast !== false ? extractToastMessage(toast, "success", extractMessage(raw, responseConfig) || "") : void 0;
|
|
70
|
+
showToast("success", message, toast, toastConfig);
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
await nuxtApp.callHook("movk:api:error", context);
|
|
74
|
+
if (import.meta.client) {
|
|
75
|
+
const message = extractMessage(raw, responseConfig);
|
|
76
|
+
const errorMessage = toast !== false ? extractToastMessage(toast, "error", message || "\u8BF7\u6C42\u5931\u8D25") : void 0;
|
|
77
|
+
showToast("error", errorMessage, toast, toastConfig);
|
|
78
|
+
}
|
|
79
|
+
throw createApiError(raw, extractMessage(raw, responseConfig));
|
|
83
80
|
}
|
|
84
81
|
},
|
|
85
82
|
async onResponseError(context) {
|
|
86
83
|
const { response } = context;
|
|
84
|
+
const { toast } = getApiFetchContext(context.options);
|
|
87
85
|
if (response.status === 401) {
|
|
88
|
-
|
|
86
|
+
const result = { handled: false };
|
|
87
|
+
await nuxtApp.callHook("movk:api:unauthorized", context, result);
|
|
88
|
+
if (!result.handled) {
|
|
89
|
+
await handleUnauthorized(authConfig, nuxtApp);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
await nuxtApp.callHook("movk:api:error", context);
|
|
93
|
+
if (import.meta.client) {
|
|
94
|
+
const data = response._data;
|
|
95
|
+
const message = data ? extractMessage(data, responseConfig) : void 0;
|
|
96
|
+
const errorMessage = toast !== false ? extractToastMessage(toast, "error", message || `\u8BF7\u6C42\u5931\u8D25 (${response.status})`) : void 0;
|
|
97
|
+
showToast("error", errorMessage, toast, toastConfig);
|
|
89
98
|
}
|
|
90
99
|
if (publicConfig.debug) {
|
|
91
100
|
console.error("[Movk API] Error:", response.status, response._data);
|
|
92
101
|
}
|
|
93
|
-
if (!import.meta.client) return;
|
|
94
|
-
const { toast } = getApiFetchContext(context);
|
|
95
|
-
const data = response._data;
|
|
96
|
-
const message = data ? extractMessage(data, responseConfig) : void 0;
|
|
97
|
-
const errorMessage = toast !== false ? toast?.errorMessage || message || `\u8BF7\u6C42\u5931\u8D25 (${response.status})` : void 0;
|
|
98
|
-
showToast("error", errorMessage, toast, toastConfig);
|
|
99
102
|
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function createApiClient(resolvedConfig, publicConfig, getOrCreateEndpoint) {
|
|
103
|
-
const builtinHooks = createBuiltinHooks(resolvedConfig, publicConfig);
|
|
104
|
-
resolvedConfig.builtinHooks = builtinHooks;
|
|
105
|
-
const $fetchInstance = $fetch.create({
|
|
106
|
-
baseURL: resolvedConfig.baseURL,
|
|
107
|
-
headers: resolvedConfig.headers,
|
|
108
|
-
onRequest: builtinHooks.onRequest,
|
|
109
|
-
onRequestError: builtinHooks.onRequestError,
|
|
110
|
-
onResponse: builtinHooks.onResponse,
|
|
111
|
-
onResponseError: builtinHooks.onResponseError
|
|
112
103
|
});
|
|
113
|
-
const download = async (url, filename, options = {}) => {
|
|
114
|
-
const { toast, ...fetchOptions } = options;
|
|
115
|
-
const response = await $fetchInstance.raw(url, {
|
|
116
|
-
...fetchOptions,
|
|
117
|
-
method: "GET",
|
|
118
|
-
responseType: "blob",
|
|
119
|
-
context: { toast }
|
|
120
|
-
});
|
|
121
|
-
if (!response._data) {
|
|
122
|
-
throw new Error("\u4E0B\u8F7D\u5931\u8D25: \u672A\u63A5\u6536\u5230\u6570\u636E");
|
|
123
|
-
}
|
|
124
|
-
const finalFilename = filename || extractFilename(response.headers, url.split("/").pop() || "download");
|
|
125
|
-
triggerDownload(response._data, finalFilename);
|
|
126
|
-
if (import.meta.client && toast !== false) {
|
|
127
|
-
const message = extractToastMessage(toast, "success", `\u4E0B\u8F7D\u6210\u529F: ${finalFilename}`);
|
|
128
|
-
showToast("success", message, toast, resolvedConfig.toast);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
const upload = async (url, file, options = {}) => {
|
|
132
|
-
const { toast, fieldName = "file", ...fetchOptions } = options;
|
|
133
|
-
const formData = file instanceof FormData ? file : (() => {
|
|
134
|
-
const fd = new FormData();
|
|
135
|
-
const files = Array.isArray(file) ? file : [file];
|
|
136
|
-
files.forEach((f) => fd.append(fieldName, f));
|
|
137
|
-
return fd;
|
|
138
|
-
})();
|
|
139
|
-
return $fetchInstance(url, {
|
|
140
|
-
...fetchOptions,
|
|
141
|
-
method: "POST",
|
|
142
|
-
body: formData,
|
|
143
|
-
context: { toast }
|
|
144
|
-
});
|
|
145
|
-
};
|
|
146
|
-
return {
|
|
147
|
-
$fetch: $fetchInstance,
|
|
148
|
-
use: (endpoint) => getOrCreateEndpoint(endpoint),
|
|
149
|
-
download,
|
|
150
|
-
upload,
|
|
151
|
-
getConfig: () => resolvedConfig
|
|
152
|
-
};
|
|
153
104
|
}
|
|
154
105
|
export default defineNuxtPlugin(() => {
|
|
106
|
+
const nuxtApp = useNuxtApp();
|
|
155
107
|
const runtimeConfig = useRuntimeConfig();
|
|
156
108
|
const publicConfig = runtimeConfig.public.movkApi;
|
|
157
109
|
const privateConfig = import.meta.server ? runtimeConfig.movkApi : void 0;
|
|
@@ -174,13 +126,18 @@ export default defineNuxtPlugin(() => {
|
|
|
174
126
|
toast: defu(endpointConfig.toast, publicConfig.toast),
|
|
175
127
|
response: defu(endpointConfig.response, publicConfig.response)
|
|
176
128
|
};
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
129
|
+
const $fetchInstance = createEndpointFetch(resolvedConfig, publicConfig, nuxtApp);
|
|
130
|
+
const apiInstance = Object.assign($fetchInstance, {
|
|
131
|
+
use: (endpoint) => getOrCreateEndpoint(endpoint)
|
|
132
|
+
});
|
|
133
|
+
endpointCache.set(endpointName, apiInstance);
|
|
134
|
+
return apiInstance;
|
|
180
135
|
};
|
|
181
136
|
const defaultEndpoint = publicConfig.defaultEndpoint || "default";
|
|
182
137
|
const api = getOrCreateEndpoint(defaultEndpoint);
|
|
183
138
|
return {
|
|
184
|
-
provide: {
|
|
139
|
+
provide: {
|
|
140
|
+
api
|
|
141
|
+
}
|
|
185
142
|
};
|
|
186
143
|
});
|
|
@@ -1,98 +1,78 @@
|
|
|
1
|
-
import { defineNuxtPlugin,
|
|
1
|
+
import { defineNuxtPlugin, useAppConfig, useHead, useSiteConfig } from "#imports";
|
|
2
|
+
import { kebabCase } from "@movk/core";
|
|
2
3
|
import { themeIcons } from "../utils/theme.js";
|
|
3
4
|
export default defineNuxtPlugin({
|
|
4
5
|
enforce: "post",
|
|
5
6
|
setup() {
|
|
6
7
|
const appConfig = useAppConfig();
|
|
7
8
|
const site = useSiteConfig();
|
|
9
|
+
const name = kebabCase(site.name);
|
|
8
10
|
if (import.meta.client) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const radius = localStorage.getItem(`${site.name}-ui-radius`);
|
|
16
|
-
if (radius) {
|
|
17
|
-
appConfig.theme.radius = Number.parseFloat(radius);
|
|
18
|
-
}
|
|
19
|
-
}, updateBlackAsPrimary = function() {
|
|
20
|
-
const blackAsPrimary = localStorage.getItem(`${site.name}-ui-black-as-primary`);
|
|
21
|
-
if (blackAsPrimary) {
|
|
22
|
-
appConfig.theme.blackAsPrimary = blackAsPrimary === "true";
|
|
23
|
-
}
|
|
24
|
-
}, updateFont = function() {
|
|
25
|
-
const font = localStorage.getItem(`${site.name}-ui-font`);
|
|
26
|
-
if (font) {
|
|
27
|
-
appConfig.theme.font = font;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
updateColor("primary");
|
|
31
|
-
updateColor("neutral");
|
|
32
|
-
updateRadius();
|
|
33
|
-
updateBlackAsPrimary();
|
|
34
|
-
updateFont();
|
|
11
|
+
const primary = localStorage.getItem(`${name}-ui-primary`);
|
|
12
|
+
if (primary) appConfig.ui.colors.primary = primary;
|
|
13
|
+
const neutral = localStorage.getItem(`${name}-ui-neutral`);
|
|
14
|
+
if (neutral) appConfig.ui.colors.neutral = neutral;
|
|
15
|
+
const icons = localStorage.getItem(`${name}-ui-icons`);
|
|
16
|
+
if (icons) appConfig.ui.icons = themeIcons[icons];
|
|
35
17
|
}
|
|
36
|
-
onNuxtReady(() => {
|
|
37
|
-
function updateIcons() {
|
|
38
|
-
const icons = localStorage.getItem(`${site.name}-ui-icons`);
|
|
39
|
-
if (icons) {
|
|
40
|
-
appConfig.theme.icons = icons;
|
|
41
|
-
appConfig.ui.icons = themeIcons[icons];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
updateIcons();
|
|
45
|
-
});
|
|
46
18
|
if (import.meta.server) {
|
|
47
19
|
useHead({
|
|
48
20
|
script: [{
|
|
49
21
|
innerHTML: `
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
22
|
+
var colorsEl = document.querySelector('style#nuxt-ui-colors');
|
|
23
|
+
if (colorsEl) {
|
|
24
|
+
let html = colorsEl.innerHTML;
|
|
25
|
+
if (localStorage.getItem('${name}-ui-primary')) {
|
|
26
|
+
const primaryColor = localStorage.getItem('${name}-ui-primary');
|
|
27
|
+
if (primaryColor !== 'black') {
|
|
28
|
+
html = html.replace(
|
|
29
|
+
/(--ui-color-primary-\\d{2,3}:\\s*var\\(--color-)${appConfig.ui.colors.primary}(-\\d{2,3}.*?\\))/g,
|
|
30
|
+
\`$1\${primaryColor}$2\`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (localStorage.getItem('${name}-ui-neutral')) {
|
|
35
|
+
let neutralColor = localStorage.getItem('${name}-ui-neutral');
|
|
55
36
|
html = html.replace(
|
|
56
|
-
/(--ui-color-
|
|
57
|
-
\`$1\${
|
|
37
|
+
/(--ui-color-neutral-\\d{2,3}:\\s*var\\(--color-)${appConfig.ui.colors.neutral}(-\\d{2,3}.*?\\))/g,
|
|
38
|
+
\`$1\${neutralColor === 'neutral' ? 'old-neutral' : neutralColor}$2\`
|
|
58
39
|
);
|
|
59
40
|
}
|
|
60
|
-
}
|
|
61
|
-
if (localStorage.getItem('${site.name}-ui-neutral')) {
|
|
62
|
-
let neutralColor = localStorage.getItem('${site.name}-ui-neutral');
|
|
63
|
-
html = html.replace(
|
|
64
|
-
/(--ui-color-neutral-\\d{2,3}:\\s*var\\(--color-)${appConfig.ui.colors.neutral}(-\\d{2,3}.*?\\))/g,
|
|
65
|
-
\`$1\${neutralColor === 'neutral' ? 'old-neutral' : neutralColor}$2\`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
41
|
|
|
69
|
-
|
|
42
|
+
colorsEl.innerHTML = html;
|
|
43
|
+
}
|
|
70
44
|
`.replace(/\s+/g, " "),
|
|
71
45
|
type: "text/javascript",
|
|
72
46
|
tagPriority: -1
|
|
73
47
|
}, {
|
|
74
48
|
innerHTML: `
|
|
75
|
-
if (localStorage.getItem('${
|
|
76
|
-
document.
|
|
49
|
+
if (localStorage.getItem('${name}-ui-radius')) {
|
|
50
|
+
document.getElementById('${name}-ui-radius').innerHTML = ':root { --ui-radius: ' + localStorage.getItem('${name}-ui-radius') + 'rem; }';
|
|
77
51
|
}
|
|
78
52
|
`.replace(/\s+/g, " "),
|
|
79
53
|
type: "text/javascript",
|
|
80
54
|
tagPriority: -1
|
|
81
55
|
}, {
|
|
82
56
|
innerHTML: `
|
|
83
|
-
if (localStorage.getItem('${
|
|
84
|
-
document.
|
|
57
|
+
if (localStorage.getItem('${name}-ui-black-as-primary') === 'true') {
|
|
58
|
+
document.getElementById('${name}-ui-black-as-primary').innerHTML = ':root { --ui-primary: black; } .dark { --ui-primary: white; }';
|
|
85
59
|
} else {
|
|
86
|
-
document.
|
|
60
|
+
document.getElementById('${name}-ui-black-as-primary').innerHTML = '';
|
|
87
61
|
}
|
|
88
62
|
`.replace(/\s+/g, " ")
|
|
89
63
|
}, {
|
|
90
|
-
innerHTML:
|
|
91
|
-
if (localStorage.getItem('${
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
64
|
+
innerHTML: [
|
|
65
|
+
`if (localStorage.getItem('${name}-ui-font')) {`,
|
|
66
|
+
`var font = localStorage.getItem('${name}-ui-font');`,
|
|
67
|
+
`document.getElementById('${name}-ui-font').innerHTML = ':root { --font-sans: \\'' + font + '\\', sans-serif; }';`,
|
|
68
|
+
`if (font !== 'Alibaba PuHuiTi' && ['Alibaba PuHuiTi', 'Public Sans', 'DM Sans', 'Geist', 'Inter', 'Poppins', 'Outfit', 'Raleway'].includes(font)) {`,
|
|
69
|
+
`var lnk = document.createElement('link');`,
|
|
70
|
+
`lnk.rel = 'stylesheet';`,
|
|
71
|
+
`lnk.href = 'https://fonts.googleapis.com/css2?family=' + encodeURIComponent(font) + ':wght@400;500;600;700&display=swap';`,
|
|
72
|
+
`lnk.id = 'font-' + font.toLowerCase().replace(/\\s+/g, '-');`,
|
|
73
|
+
`document.head.appendChild(lnk);`,
|
|
74
|
+
`}}`
|
|
75
|
+
].join(" ")
|
|
96
76
|
}]
|
|
97
77
|
});
|
|
98
78
|
}
|
package/dist/runtime/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@import "tailwindcss" theme(static);@import "@nuxt/ui";@source "./components"
|
|
1
|
+
@import "tailwindcss" theme(static);@import "@nuxt/ui";@source "./components";@source "./constants";@theme static{--font-sans:"Alibaba PuHuiTi",sans-serif}
|