@cbjwwwcode/common 0.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.
- package/dist/es/api.d.mts +14 -0
- package/dist/es/api.mjs +26 -0
- package/dist/es/common.d.mts +20 -0
- package/dist/es/common.mjs +112 -0
- package/dist/es/crypto.d.mts +5 -0
- package/dist/es/crypto.mjs +7 -0
- package/dist/es/dayjs.d.mts +7 -0
- package/dist/es/dayjs.mjs +47 -0
- package/dist/es/es-toolkit.d.mts +3 -0
- package/dist/es/es-toolkit.mjs +3 -0
- package/dist/es/idb-keyval.d.mts +16 -0
- package/dist/es/idb-keyval.mjs +63 -0
- package/dist/es/index.d.mts +21 -0
- package/dist/es/index.mjs +21 -0
- package/dist/es/loader.d.mts +6 -0
- package/dist/es/loader.mjs +44 -0
- package/dist/es/lowlight/common.mjs +81 -0
- package/dist/es/lowlight/hljs.d.mts +2 -0
- package/dist/es/lowlight/hljs.mjs +9 -0
- package/dist/es/lowlight/index.d.mts +159 -0
- package/dist/es/lowlight/index.mjs +16 -0
- package/dist/es/lowlight/lowlights.d.mts +66 -0
- package/dist/es/lowlight/lowlights.mjs +153 -0
- package/dist/es/nprogress.d.mts +5 -0
- package/dist/es/nprogress.mjs +16 -0
- package/dist/es/toastify.d.mts +7 -0
- package/dist/es/toastify.mjs +13 -0
- package/dist/es/vee-validate.d.mts +2 -0
- package/dist/es/vee-validate.mjs +2 -0
- package/dist/es/vtj/index.d.mts +3 -0
- package/dist/es/vtj/index.mjs +3 -0
- package/dist/es/vtj/node.d.mts +33 -0
- package/dist/es/vtj/node.mjs +70 -0
- package/dist/es/vtj/provider.d.mts +32 -0
- package/dist/es/vtj/provider.mjs +65 -0
- package/dist/es/vtj/request.d.mts +2 -0
- package/dist/es/vtj/request.mjs +22 -0
- package/dist/es/vtj/service.mjs +63 -0
- package/dist/es/vtj/stores.d.mts +11 -0
- package/dist/es/vtj/stores.mjs +103 -0
- package/dist/es/vue-router.d.mts +2 -0
- package/dist/es/vue-router.mjs +2 -0
- package/dist/es/vue.d.mts +2 -0
- package/dist/es/vue.mjs +2 -0
- package/dist/es/vueuse.d.mts +3 -0
- package/dist/es/vueuse.mjs +3 -0
- package/dist/es/window.d.mts +6 -0
- package/dist/es/window.mjs +39 -0
- package/dist/es/zod.d.mts +2 -0
- package/dist/es/zod.mjs +2 -0
- package/dist/umd/common.min.js +371 -0
- package/dist/umd/common.min.js.map +1 -0
- package/dist/umd/style.css +59 -0
- package/package.json +89 -0
- package/src/api.ts +83 -0
- package/src/common.ts +201 -0
- package/src/crypto.ts +7 -0
- package/src/dayjs.ts +60 -0
- package/src/es-toolkit.ts +4 -0
- package/src/highlight.ts +0 -0
- package/src/idb-keyval.ts +115 -0
- package/src/index.ts +20 -0
- package/src/loader.ts +62 -0
- package/src/lowlight/common.ts +79 -0
- package/src/lowlight/hljs.ts +11 -0
- package/src/lowlight/index.ts +22 -0
- package/src/lowlight/lowlights.ts +231 -0
- package/src/nprogress.ts +20 -0
- package/src/sortablejs.ts +1 -0
- package/src/tippy.ts +3 -0
- package/src/toastify.ts +19 -0
- package/src/vee-validate.ts +1 -0
- package/src/vtj/index.ts +2 -0
- package/src/vtj/node.ts +158 -0
- package/src/vtj/provider.ts +113 -0
- package/src/vtj/request.ts +34 -0
- package/src/vtj/service.ts +93 -0
- package/src/vtj/stores.ts +144 -0
- package/src/vue-router.ts +1 -0
- package/src/vue.ts +3 -0
- package/src/vueuse.ts +13 -0
- package/src/window.ts +60 -0
- package/src/zod.ts +1 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
pre code.hljs {
|
|
2
|
+
padding: 1em;
|
|
3
|
+
display: block;
|
|
4
|
+
overflow-x: auto;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
code.hljs {
|
|
8
|
+
padding: 3px 5px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.hljs {
|
|
12
|
+
color: #abb2bf;
|
|
13
|
+
background: #282c34;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.hljs-comment, .hljs-quote {
|
|
17
|
+
color: #5c6370;
|
|
18
|
+
font-style: italic;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.hljs-doctag, .hljs-formula, .hljs-keyword {
|
|
22
|
+
color: #c678dd;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.hljs-deletion, .hljs-name, .hljs-section, .hljs-selector-tag, .hljs-subst {
|
|
26
|
+
color: #e06c75;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.hljs-literal {
|
|
30
|
+
color: #56b6c2;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.hljs-addition, .hljs-attribute, .hljs-meta .hljs-string, .hljs-regexp, .hljs-string {
|
|
34
|
+
color: #98c379;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.hljs-attr, .hljs-number, .hljs-selector-attr, .hljs-selector-class, .hljs-selector-pseudo, .hljs-template-variable, .hljs-type, .hljs-variable {
|
|
38
|
+
color: #d19a66;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.hljs-bullet, .hljs-link, .hljs-meta, .hljs-selector-id, .hljs-symbol, .hljs-title {
|
|
42
|
+
color: #61aeee;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.hljs-built_in, .hljs-class .hljs-title, .hljs-title.class_ {
|
|
46
|
+
color: #e6c07b;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.hljs-emphasis {
|
|
50
|
+
font-style: italic;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.hljs-strong {
|
|
54
|
+
font-weight: 700;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.hljs-link {
|
|
58
|
+
text-decoration: underline;
|
|
59
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cbjwwwcode/common",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"author": "",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsdown",
|
|
11
|
+
"release": "standard-version --header \"\"",
|
|
12
|
+
"release:major": "standard-version --release-as major",
|
|
13
|
+
"release:minor": "standard-version --release-as minor",
|
|
14
|
+
"release:patch": "standard-version --release-as patch",
|
|
15
|
+
"push": "npm publish --access public"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"main": "dist/es/index.mjs",
|
|
22
|
+
"module": "dist/es/index.mjs",
|
|
23
|
+
"browser": "dist/umd/common.min.js",
|
|
24
|
+
"types": "dist/es/index.d.mts",
|
|
25
|
+
"exports": {
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/es/index.d.mts",
|
|
29
|
+
"import": "./dist/es/index.mjs",
|
|
30
|
+
"require": "./dist/es/index.mjs",
|
|
31
|
+
"default": "./dist/es/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./style.css": "./dist/umd/style.css",
|
|
34
|
+
"./es/": "./dist/es/",
|
|
35
|
+
"./umd/": "./dist/umd/"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@tsdown/css": "^0.23.0",
|
|
39
|
+
"@types/crypto-js": "^4.2.2",
|
|
40
|
+
"@types/node": "^26.6.2",
|
|
41
|
+
"@types/nprogress": "^0.2.3",
|
|
42
|
+
"concurrently": "^10.0.5",
|
|
43
|
+
"laravel-vite-plugin": "^3.2.0",
|
|
44
|
+
"rollup-plugin-bundle-stats": "^4.22.3",
|
|
45
|
+
"sass": "^1.104.1",
|
|
46
|
+
"sonda": "^0.14.0",
|
|
47
|
+
"tsdown": "^0.23.0",
|
|
48
|
+
"typescript": "^6.0.3",
|
|
49
|
+
"unplugin-vue": "^7.2.0",
|
|
50
|
+
"vite": "catalog:",
|
|
51
|
+
"vite-plugin-cp": "^8.0.1",
|
|
52
|
+
"vite-plugin-externals": "^0.6.2",
|
|
53
|
+
"vite-plugin-node-polyfills": "^0.28.0",
|
|
54
|
+
"vite-plugin-vue-devtools": "^8.2.1",
|
|
55
|
+
"vite-plus": "catalog:"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@alova/adapter-axios": "catalog:",
|
|
59
|
+
"@vtj/core": "^0.20.6",
|
|
60
|
+
"@vtj/parser": "^0.20.6",
|
|
61
|
+
"@vtj/renderer": "^0.20.6",
|
|
62
|
+
"@vtj/utils": "^0.20.6",
|
|
63
|
+
"@vueuse/core": "^14.4.0",
|
|
64
|
+
"@vueuse/integrations": "^14.4.0",
|
|
65
|
+
"aieditor": "^2.0.0",
|
|
66
|
+
"alova": "^3.5.5",
|
|
67
|
+
"antdv-next": "^1.5.4",
|
|
68
|
+
"antdv-next-tiptap": "^1.0.5",
|
|
69
|
+
"axios": "^1.20.0",
|
|
70
|
+
"crypto-js": "^4.2.0",
|
|
71
|
+
"dayjs": "^1.11.23",
|
|
72
|
+
"dompurify": "^3.4.15",
|
|
73
|
+
"es-toolkit": "^1.52.0",
|
|
74
|
+
"highlight.js": "^11.12.0",
|
|
75
|
+
"hucre": "^1.1.0",
|
|
76
|
+
"idb-keyval": "^6.3.0",
|
|
77
|
+
"jsbarcode": "^3.12.3",
|
|
78
|
+
"mitt": "^3.0.1",
|
|
79
|
+
"motion-v": "^2.4.4",
|
|
80
|
+
"nprogress": "^0.2.0",
|
|
81
|
+
"path-browserify": "^1.0.1",
|
|
82
|
+
"vee-validate": "^4.15.1",
|
|
83
|
+
"vue": "3.6.0-rc.2",
|
|
84
|
+
"vue-demi": "^0.14.10",
|
|
85
|
+
"vue-router": "catalog:",
|
|
86
|
+
"vue3-toastify": "^0.2.9",
|
|
87
|
+
"zod": "^4.6.5"
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { AlovaOptions } from 'alova';
|
|
2
|
+
import type {AxiosInstance, AxiosRequestConfig, AxiosResponse} from "axios";
|
|
3
|
+
import { axiosRequestAdapter } from '@alova/adapter-axios';
|
|
4
|
+
import { createAlova } from 'alova';
|
|
5
|
+
import VueHook from 'alova/vue';
|
|
6
|
+
import axios from "axios";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* axios请求配置参数
|
|
10
|
+
* 去掉了与method冲突的属性
|
|
11
|
+
*/
|
|
12
|
+
export type AlovaAxiosRequestConfig = Omit<
|
|
13
|
+
AxiosRequestConfig,
|
|
14
|
+
| 'url'
|
|
15
|
+
| 'method'
|
|
16
|
+
| 'baseURL'
|
|
17
|
+
| 'headers'
|
|
18
|
+
| 'params'
|
|
19
|
+
| 'data'
|
|
20
|
+
| 'timeout'
|
|
21
|
+
| 'cancelToken'
|
|
22
|
+
| 'signal'
|
|
23
|
+
| 'onUploadProgress'
|
|
24
|
+
| 'onDownloadProgress'
|
|
25
|
+
>;
|
|
26
|
+
|
|
27
|
+
export interface ApiConfig {
|
|
28
|
+
alovaOptions?: Partial<AlovaOptions<any>>;
|
|
29
|
+
init?: (axiosInst: AxiosInstance) => void;
|
|
30
|
+
options?: AxiosRequestConfig;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export function setupRequest(baseUrl: string, config?: ApiConfig) {
|
|
37
|
+
const axiosInst = axios.create(config?.options);
|
|
38
|
+
// // 请求拦截器
|
|
39
|
+
// axiosInst.interceptors.request.use((config) => {
|
|
40
|
+
// config.headers.token = localStorage.getItem('token') || '';
|
|
41
|
+
// return config;
|
|
42
|
+
// });
|
|
43
|
+
//
|
|
44
|
+
// // 响应拦截器
|
|
45
|
+
// axiosInst.interceptors.response.use(
|
|
46
|
+
// (response) => response,
|
|
47
|
+
// (error) => Promise.reject(error)
|
|
48
|
+
// );
|
|
49
|
+
// if (config?.init) {
|
|
50
|
+
// config.init(axiosInst);
|
|
51
|
+
// }
|
|
52
|
+
return createAlova({
|
|
53
|
+
baseURL: baseUrl,
|
|
54
|
+
statesHook: VueHook,
|
|
55
|
+
requestAdapter: axiosRequestAdapter({
|
|
56
|
+
axios: axiosInst,
|
|
57
|
+
}),
|
|
58
|
+
...config?.alovaOptions,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const $http = setupRequest( window.appConfig.baseApi || "admin", {
|
|
63
|
+
alovaOptions:{
|
|
64
|
+
id: "api",
|
|
65
|
+
responded(response: AxiosResponse<any,any,{}>) {
|
|
66
|
+
return response.data;
|
|
67
|
+
},
|
|
68
|
+
beforeRequest(method){
|
|
69
|
+
method.config.headers.token = localStorage.getItem('token') || '';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export {
|
|
75
|
+
axios
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
createClientTokenAuthentication,
|
|
80
|
+
useCaptcha,
|
|
81
|
+
useRequest,
|
|
82
|
+
useUploader,
|
|
83
|
+
} from 'alova/client';
|
package/src/common.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// @eslint-ignore
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
AsyncComponentLoader,
|
|
5
|
+
AsyncComponentOptions,
|
|
6
|
+
Component,
|
|
7
|
+
ComponentPublicInstance,
|
|
8
|
+
} from 'vue';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
defineAsyncComponent,
|
|
12
|
+
markRaw,
|
|
13
|
+
mergeProps,
|
|
14
|
+
resolveComponent,
|
|
15
|
+
useId,
|
|
16
|
+
} from 'vue';
|
|
17
|
+
|
|
18
|
+
import { omitBy, isNil, isPlainObject } from 'es-toolkit/compat';
|
|
19
|
+
|
|
20
|
+
export function makeRawComponent<
|
|
21
|
+
T extends Component = {
|
|
22
|
+
new (): ComponentPublicInstance;
|
|
23
|
+
},
|
|
24
|
+
>(source: AsyncComponentLoader<T> | AsyncComponentOptions<T>) {
|
|
25
|
+
return markRaw(defineAsyncComponent(source));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isComponentRegistered(name: string) {
|
|
29
|
+
try {
|
|
30
|
+
const component = resolveComponent(name);
|
|
31
|
+
return component !== name; // 如果返回的是字符串,说明未注册
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function randomId(length: number = 8) {
|
|
38
|
+
let result = '';
|
|
39
|
+
const characters =
|
|
40
|
+
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
41
|
+
const charactersLength = characters.length;
|
|
42
|
+
for (let i = 0; i < length; i++) {
|
|
43
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function hasProperty<T extends object>(target: T, key: string) {
|
|
49
|
+
return target && Reflect.has(target, key);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function mergeOmitBy<
|
|
53
|
+
T extends Record<string, any> = object,
|
|
54
|
+
E extends keyof T = string,
|
|
55
|
+
>(props: T, excludes: E[]) {
|
|
56
|
+
return omitBy(props, (value, key) => isNil(value) || excludes.includes(key as E)) as Omit<T, E>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function mergePropsOmitBy<
|
|
60
|
+
T extends Record<string, any> = any,
|
|
61
|
+
E extends string = string,
|
|
62
|
+
>(props: T, attrs: T, excludes: E[] = []) {
|
|
63
|
+
return mergeOmitBy(mergeProps(props, attrs), excludes) as Omit<T, E>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function mergeUrlWithParams(
|
|
67
|
+
baseUrl: string,
|
|
68
|
+
params: Record<string, any>,
|
|
69
|
+
) {
|
|
70
|
+
const query: string[] = [];
|
|
71
|
+
// 添加或更新查询参数
|
|
72
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
73
|
+
if (value !== undefined && value !== null) {
|
|
74
|
+
if (isPlainObject(value) || Array.isArray(value)) {
|
|
75
|
+
query.push(`${key}=${JSON.stringify(value)}`);
|
|
76
|
+
} else {
|
|
77
|
+
query.push(`${key}=${value.toString()}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
if (query.length > 0) {
|
|
82
|
+
if (baseUrl.includes('?')) {
|
|
83
|
+
return `${baseUrl}&${query.join('&')}`;
|
|
84
|
+
}
|
|
85
|
+
return `${baseUrl}?${query.join('&')}`;
|
|
86
|
+
} else {
|
|
87
|
+
return baseUrl;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function keepProps<T extends Record<string, any> = any, K extends keyof T = string, R extends T = any>(
|
|
92
|
+
object: T,
|
|
93
|
+
keys: K[] = [],
|
|
94
|
+
rest: R = {} as R,
|
|
95
|
+
): Pick<T, K & keyof T> & R {
|
|
96
|
+
return mergeProps(omitBy(object, (_value, key)=>!keys.includes(key as K)), rest) as Pick<T, K & keyof T> & R
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const fixToPx = (field: number | string, key: string) => {
|
|
100
|
+
return field.toString().includes(key);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export function isStringNumber(str) {
|
|
104
|
+
if (typeof str === 'number') return true;
|
|
105
|
+
if (typeof str !== 'string') return false;
|
|
106
|
+
// 排除空、全空格
|
|
107
|
+
if (str.trim() === '') return false;
|
|
108
|
+
return !isNaN(Number(str));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function transformPx(field: number | string | undefined) {
|
|
112
|
+
if (field === undefined) return field;
|
|
113
|
+
if (
|
|
114
|
+
fixToPx(field, 'px') ||
|
|
115
|
+
fixToPx(field, 'rem') ||
|
|
116
|
+
fixToPx(field, 'em') ||
|
|
117
|
+
fixToPx(field, 'vh') ||
|
|
118
|
+
fixToPx(field, 'vw') ||
|
|
119
|
+
fixToPx(field, 'pt') ||
|
|
120
|
+
fixToPx(field, '%') ||
|
|
121
|
+
fixToPx(field, 'auto') ||
|
|
122
|
+
fixToPx(field, 'calc')
|
|
123
|
+
) {
|
|
124
|
+
return field.toString();
|
|
125
|
+
}
|
|
126
|
+
return isStringNumber(field)?`${field}px`:field;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 把十六进制颜色值转成 rgba 颜色值
|
|
130
|
+
*
|
|
131
|
+
* @param {string} hex
|
|
132
|
+
* @returns {string} rgba 颜色值
|
|
133
|
+
*/
|
|
134
|
+
const hexToRgba = (hex: string): string => {
|
|
135
|
+
if (hex && hex.includes('rgb')) {
|
|
136
|
+
return hex;
|
|
137
|
+
}
|
|
138
|
+
const rgba: number[] = [];
|
|
139
|
+
hex = hex.replace('#', '').padEnd(8, 'F');
|
|
140
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
141
|
+
rgba.push(Number.parseInt(hex.slice(i, i + 2), 16));
|
|
142
|
+
}
|
|
143
|
+
return `${rgba.reduce((prev, item, index) => {
|
|
144
|
+
return (prev +=
|
|
145
|
+
index >= rgba.length - 1 ? Number((item / 255).toFixed(2)) : `${item}, `);
|
|
146
|
+
}, 'rgba(')})`;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 计算文本颜色值
|
|
151
|
+
*
|
|
152
|
+
* @param {string} hexColor
|
|
153
|
+
* @returns {'black' | 'white'} 文本颜色值
|
|
154
|
+
*/
|
|
155
|
+
export const determineTextColor = (hexColor: string): 'black' | 'white' => {
|
|
156
|
+
// 将十六进制颜色值转换为 RGB 格式
|
|
157
|
+
const rgbColor = hexToRgba(hexColor);
|
|
158
|
+
// 获取颜色的 RGB 分量
|
|
159
|
+
const [r, g, b, a] = (rgbColor.match(/\d+(\.\d+)?/g) || []).map(Number);
|
|
160
|
+
// 计算颜色的相对亮度
|
|
161
|
+
const brightness =
|
|
162
|
+
(Number(r || 0) * 299 + Number(g || 0) * 587 + Number(b || 0) * 114) / 1000;
|
|
163
|
+
// 根据相对亮度确定文本颜色
|
|
164
|
+
return brightness > 125 ? 'black' : Number(a || 0) < 0.4 ? 'black' : 'white';
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export function makeUuid() {
|
|
168
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replaceAll(/[xy]/g, (c) => {
|
|
169
|
+
const r = (Math.random() * 16) | 0;
|
|
170
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
171
|
+
return v.toString(16);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function createFunction<T extends object = any>(code: string, scope: T) {
|
|
176
|
+
return new Function('__scope__', `with(__scope__){ return ${code};}`)(scope);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function makeVueId(prefix: string = '', suffix: string = ''): string {
|
|
180
|
+
return (prefix ? `${prefix}-` : '') + useId() + (suffix ? `-${suffix}` : '');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 判断是否是 http / https 链接
|
|
185
|
+
* @param {string} str
|
|
186
|
+
* @returns {boolean}
|
|
187
|
+
*/
|
|
188
|
+
export function isHttpUrl<T extends string>(str: T) {
|
|
189
|
+
if (typeof str !== 'string') return false;
|
|
190
|
+
try {
|
|
191
|
+
const url = new URL(str);
|
|
192
|
+
// protocol 带冒号:http: https:
|
|
193
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
194
|
+
} catch {
|
|
195
|
+
// 解析失败,不是标准url
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
package/src/crypto.ts
ADDED
package/src/dayjs.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { registerWindow } from './window';
|
|
2
|
+
import dayjs from "dayjs"
|
|
3
|
+
import utc from 'dayjs/plugin/utc';
|
|
4
|
+
import advancedFormat from "dayjs/plugin/advancedFormat"
|
|
5
|
+
import customParseFormat from "dayjs/plugin/customParseFormat"
|
|
6
|
+
import localeData from "dayjs/plugin/localeData"
|
|
7
|
+
import weekday from "dayjs/plugin/weekday"
|
|
8
|
+
import weekOfYear from "dayjs/plugin/weekOfYear"
|
|
9
|
+
import weekYear from "dayjs/plugin/weekYear"
|
|
10
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
11
|
+
import timezone from 'dayjs/plugin/timezone';
|
|
12
|
+
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
|
|
13
|
+
import dayjsEnUS from 'dayjs/locale/en';
|
|
14
|
+
import dayjsZhCN from 'dayjs/locale/zh-cn';
|
|
15
|
+
import 'dayjs/locale/zh-cn'
|
|
16
|
+
import 'dayjs/locale/en'
|
|
17
|
+
|
|
18
|
+
// 必须 extend 注册
|
|
19
|
+
dayjs.extend(utc)
|
|
20
|
+
dayjs.extend(advancedFormat)
|
|
21
|
+
dayjs.extend(customParseFormat)
|
|
22
|
+
dayjs.extend(localeData)
|
|
23
|
+
dayjs.extend(weekday)
|
|
24
|
+
dayjs.extend(weekOfYear)
|
|
25
|
+
dayjs.extend(weekYear)
|
|
26
|
+
dayjs.extend(relativeTime)
|
|
27
|
+
dayjs.extend(timezone)
|
|
28
|
+
dayjs.extend(quarterOfYear)
|
|
29
|
+
|
|
30
|
+
registerWindow('dayjs_plugin_customParseFormat', customParseFormat);
|
|
31
|
+
registerWindow('dayjs_plugin_weekday', weekday);
|
|
32
|
+
registerWindow('dayjs_plugin_localeData', localeData);
|
|
33
|
+
registerWindow('dayjs_plugin_weekOfYear', weekOfYear);
|
|
34
|
+
registerWindow('dayjs_plugin_weekYear', weekYear);
|
|
35
|
+
registerWindow('dayjs_plugin_advancedFormat', advancedFormat);
|
|
36
|
+
registerWindow('dayjs_plugin_quarterOfYear', quarterOfYear);
|
|
37
|
+
registerWindow('dayjs_plugin_relativeTime', relativeTime);
|
|
38
|
+
registerWindow('dayjs_plugin_timezone', timezone);
|
|
39
|
+
registerWindow('dayjs_plugin_utc', utc);
|
|
40
|
+
registerWindow('dayjs_locale_zh_cn', dayjsZhCN);
|
|
41
|
+
registerWindow('dayjs_locale_en', dayjsEnUS);
|
|
42
|
+
|
|
43
|
+
const locales: Record<string, string> = {
|
|
44
|
+
en: 'en',
|
|
45
|
+
'zh-CN':'zh-cn'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const setDayjsLocale = (locale: string, object?: Partial<ILocale>, isLocal?: boolean)=>{
|
|
49
|
+
dayjs.locale(locales[locale]||locale, object, isLocal)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
dayjs
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
registerWindow('dayjs', dayjs);
|
|
59
|
+
|
|
60
|
+
|
package/src/highlight.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import type {
|
|
3
|
+
UseIDBKeyvalReturn,
|
|
4
|
+
UseIDBOptions,
|
|
5
|
+
} from '@vueuse/integrations/useIDBKeyval';
|
|
6
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
7
|
+
import type { RemovableRef } from '@vueuse/core';
|
|
8
|
+
|
|
9
|
+
import type { Ref } from 'vue';
|
|
10
|
+
|
|
11
|
+
import { ref, shallowRef, toRaw, toValue, watch } from 'vue';
|
|
12
|
+
import { isNotNil } from 'es-toolkit';
|
|
13
|
+
|
|
14
|
+
import * as idb from 'idb-keyval';
|
|
15
|
+
|
|
16
|
+
export function createNaiveStore(storeName: string) {
|
|
17
|
+
return idb.createStore('naive-admin', storeName);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function loadJsStore(
|
|
21
|
+
key: IDBValidKey,
|
|
22
|
+
callback: (idb: any) => Promise<any>,
|
|
23
|
+
) {
|
|
24
|
+
const customJsStore = createNaiveStore('remove-js-store');
|
|
25
|
+
let content = await idb.get(key, customJsStore);
|
|
26
|
+
if (!content) {
|
|
27
|
+
content = await callback(idb);
|
|
28
|
+
await idb.set(key, content, customJsStore);
|
|
29
|
+
}
|
|
30
|
+
return content;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export declare interface IDBOptions extends UseIDBOptions<any> {
|
|
34
|
+
storeName?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export declare interface IDBKeyValReturn<T> extends UseIDBKeyvalReturn<T> {
|
|
38
|
+
idb: typeof idb;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function useIdb<T = any>(
|
|
42
|
+
key: IDBValidKey,
|
|
43
|
+
initialValue: MaybeRefOrGetter<T>,
|
|
44
|
+
options: IDBOptions,
|
|
45
|
+
): IDBKeyValReturn<T> {
|
|
46
|
+
const {
|
|
47
|
+
storeName = 'base-store',
|
|
48
|
+
flush = 'pre',
|
|
49
|
+
deep = true,
|
|
50
|
+
shallow = false,
|
|
51
|
+
onError = (e) => {
|
|
52
|
+
console.error(e);
|
|
53
|
+
},
|
|
54
|
+
writeDefaults = true,
|
|
55
|
+
} = options;
|
|
56
|
+
const store = createNaiveStore(storeName);
|
|
57
|
+
const isFinished = ref(false);
|
|
58
|
+
const data = (shallow ? shallowRef : ref)(initialValue) as Ref<T>;
|
|
59
|
+
|
|
60
|
+
const rawInit: T = toValue(initialValue);
|
|
61
|
+
|
|
62
|
+
async function read() {
|
|
63
|
+
try {
|
|
64
|
+
const rawValue = await idb.get<T>(key, store);
|
|
65
|
+
if (rawValue === undefined) {
|
|
66
|
+
if (isNotNil(rawInit) && writeDefaults)
|
|
67
|
+
await idb.set(key, rawInit, store);
|
|
68
|
+
} else {
|
|
69
|
+
data.value = rawValue;
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {
|
|
72
|
+
onError(error);
|
|
73
|
+
}
|
|
74
|
+
isFinished.value = true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
read();
|
|
78
|
+
|
|
79
|
+
async function write() {
|
|
80
|
+
try {
|
|
81
|
+
if (data.value === null) {
|
|
82
|
+
await idb.del(key, store);
|
|
83
|
+
} else {
|
|
84
|
+
// IndexedDB does not support saving proxies, convert from proxy before saving
|
|
85
|
+
await idb.update(key, () => toRaw(data.value), store);
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
onError(error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const { pause: pauseWatch, resume: resumeWatch } = watch(
|
|
93
|
+
data,
|
|
94
|
+
() => write(),
|
|
95
|
+
{ flush, deep },
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
async function setData(value: T): Promise<void> {
|
|
99
|
+
pauseWatch();
|
|
100
|
+
data.value = value;
|
|
101
|
+
await write();
|
|
102
|
+
resumeWatch();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
set: setData,
|
|
107
|
+
isFinished,
|
|
108
|
+
data: data as RemovableRef<T>,
|
|
109
|
+
idb,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { idb };
|
|
114
|
+
|
|
115
|
+
export { type UseStore } from 'idb-keyval';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './api';
|
|
2
|
+
export * from './common';
|
|
3
|
+
export * from './crypto';
|
|
4
|
+
export * from './dayjs';
|
|
5
|
+
export * from './es-toolkit';
|
|
6
|
+
export * from './idb-keyval';
|
|
7
|
+
export * from './loader';
|
|
8
|
+
export * from './nprogress';
|
|
9
|
+
// export * from './sortablejs';
|
|
10
|
+
// export * from './tippy';
|
|
11
|
+
export * from './toastify';
|
|
12
|
+
export * from './vee-validate';
|
|
13
|
+
export * from './vue';
|
|
14
|
+
export * from './vue-router';
|
|
15
|
+
export * from './vueuse';
|
|
16
|
+
export * from './window';
|
|
17
|
+
export * from './zod';
|
|
18
|
+
export * from './vtj';
|
|
19
|
+
export * from './lowlight';
|
|
20
|
+
|