nhanh-pure-function 1.4.1 → 2.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/LICENSE +21 -0
- package/README.md +10 -1
- package/dist/Constant.d.ts +82 -0
- package/dist/Math/index.d.ts +60 -0
- package/dist/Math/type.d.ts +4 -0
- package/dist/User/index.d.ts +67 -0
- package/dist/User/type.d.ts +33 -0
- package/dist/Utility/index.d.ts +260 -0
- package/dist/Utility/type.d.ts +0 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.es.js +911 -0
- package/dist/nhanh-pure-function.css +1 -0
- package/package.json +24 -3
- package/lib/Constant.ts +0 -249
- package/lib/Index.d.ts +0 -3
- package/lib/Index.js +0 -5
- package/lib/Math/Math.d.ts +0 -73
- package/lib/Math/Math.js +0 -165
- package/lib/User/User.d.ts +0 -95
- package/lib/User/User.js +0 -338
- package/lib/Utility/Utility.d.ts +0 -366
- package/lib/Utility/Utility.js +0 -856
- package/lib/index.css +0 -8
- package/lib/index.less +0 -5
- package/lib/test.ts +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.nhanh-pure-function{--nhanh: 2233}.no-select{-webkit-user-select:none;-ms-user-select:none;user-select:none}
|
package/package.json
CHANGED
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhanh-pure-function",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "纯函数工具",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
6
|
+
"module": "./dist/index.es.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
6
11
|
"scripts": {
|
|
7
|
-
"
|
|
12
|
+
"build": "vite build",
|
|
13
|
+
"test": "jest --coverage"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@babel/core": "^7.26.9",
|
|
17
|
+
"@babel/preset-env": "^7.26.9",
|
|
18
|
+
"@types/jest": "^29.5.14",
|
|
19
|
+
"babel-jest": "^29.7.0",
|
|
20
|
+
"jest": "^29.7.0",
|
|
21
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
22
|
+
"less": "^4.2.2",
|
|
23
|
+
"ts-jest": "^29.2.5",
|
|
24
|
+
"ts-node": "^10.9.2",
|
|
25
|
+
"typescript": "^5.7.3",
|
|
26
|
+
"vite": "^6.1.0",
|
|
27
|
+
"vite-plugin-dts": "^4.5.0",
|
|
28
|
+
"vite-tsconfig-paths": "^5.1.4"
|
|
8
29
|
},
|
|
9
30
|
"keywords": [
|
|
10
31
|
"pure-function",
|
package/lib/Constant.ts
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
export const EXTENSION_TO_MIME = {
|
|
2
|
-
/* 常见扩展名映射 */
|
|
3
|
-
".mp3": "audio/mpeg",
|
|
4
|
-
".mp4": "video/mp4",
|
|
5
|
-
".m4a": "audio/mp4",
|
|
6
|
-
".aac": "audio/aac",
|
|
7
|
-
".ogg": "audio/ogg",
|
|
8
|
-
".wav": "audio/wav",
|
|
9
|
-
".flac": "audio/flac",
|
|
10
|
-
".opus": "audio/opus",
|
|
11
|
-
".webm": "video/webm",
|
|
12
|
-
".avi": "video/x-msvideo",
|
|
13
|
-
".mov": "video/quicktime",
|
|
14
|
-
".wmv": "video/x-ms-wmv",
|
|
15
|
-
".png": "image/png",
|
|
16
|
-
".jpg": "image/jpeg",
|
|
17
|
-
".jpeg": "image/jpeg",
|
|
18
|
-
".gif": "image/gif",
|
|
19
|
-
".bmp": "image/bmp",
|
|
20
|
-
".tiff": "image/tiff",
|
|
21
|
-
".ico": "image/vnd.microsoft.icon",
|
|
22
|
-
".svg": "image/svg+xml",
|
|
23
|
-
".webp": "image/webp",
|
|
24
|
-
".heif": "image/heif",
|
|
25
|
-
".heic": "image/heic",
|
|
26
|
-
".json": "application/json",
|
|
27
|
-
".xml": "application/xml",
|
|
28
|
-
".html": "text/html",
|
|
29
|
-
".htm": "text/html",
|
|
30
|
-
".css": "text/css",
|
|
31
|
-
".js": "application/javascript",
|
|
32
|
-
".ts": "application/typescript",
|
|
33
|
-
".csv": "text/csv",
|
|
34
|
-
".tsv": "text/tab-separated-values",
|
|
35
|
-
".txt": "text/plain",
|
|
36
|
-
".md": "text/markdown",
|
|
37
|
-
".rtf": "application/rtf",
|
|
38
|
-
".pdf": "application/pdf",
|
|
39
|
-
".zip": "application/zip",
|
|
40
|
-
".rar": "application/x-rar-compressed",
|
|
41
|
-
".tar": "application/x-tar",
|
|
42
|
-
".gz": "application/gzip",
|
|
43
|
-
".7z": "application/x-7z-compressed",
|
|
44
|
-
".exe": "application/x-msdownload",
|
|
45
|
-
".apk": "application/vnd.android.package-archive",
|
|
46
|
-
".doc": "application/msword",
|
|
47
|
-
".docx":
|
|
48
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
49
|
-
".xls": "application/vnd.ms-excel",
|
|
50
|
-
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
51
|
-
".ppt": "application/vnd.ms-powerpoint",
|
|
52
|
-
".pptx":
|
|
53
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
54
|
-
".odt": "application/vnd.oasis.opendocument.text",
|
|
55
|
-
".ods": "application/vnd.oasis.opendocument.spreadsheet",
|
|
56
|
-
".odp": "application/vnd.oasis.opendocument.presentation",
|
|
57
|
-
".jsonld": "application/ld+json",
|
|
58
|
-
".yaml": "application/x-yaml",
|
|
59
|
-
".yml": "application/x-yaml",
|
|
60
|
-
".woff": "font/woff",
|
|
61
|
-
".woff2": "font/woff2",
|
|
62
|
-
".ttf": "font/ttf",
|
|
63
|
-
".otf": "font/otf",
|
|
64
|
-
".eot": "application/vnd.ms-fontobject",
|
|
65
|
-
".map": "application/json",
|
|
66
|
-
// 可根据需要继续扩展
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const FILE_EXTENSIONS = {
|
|
70
|
-
image: [
|
|
71
|
-
".jpg",
|
|
72
|
-
".jpeg",
|
|
73
|
-
".png",
|
|
74
|
-
".gif",
|
|
75
|
-
".bmp",
|
|
76
|
-
".webp",
|
|
77
|
-
".tiff",
|
|
78
|
-
".svg",
|
|
79
|
-
".heif",
|
|
80
|
-
".heic",
|
|
81
|
-
".ico",
|
|
82
|
-
".raw",
|
|
83
|
-
".jfif",
|
|
84
|
-
".avif",
|
|
85
|
-
".png8",
|
|
86
|
-
".indd",
|
|
87
|
-
".eps",
|
|
88
|
-
".ai",
|
|
89
|
-
],
|
|
90
|
-
ppt: [".ppt", ".pptx", ".odp"],
|
|
91
|
-
word: [".doc", ".docx", ".odt", ".rtf"],
|
|
92
|
-
excel: [".xls", ".xlsx", ".ods", ".csv", ".tsv"],
|
|
93
|
-
pdf: [".pdf"],
|
|
94
|
-
text: [
|
|
95
|
-
".txt",
|
|
96
|
-
".csv",
|
|
97
|
-
".md",
|
|
98
|
-
".json",
|
|
99
|
-
".yaml",
|
|
100
|
-
".yml",
|
|
101
|
-
".log",
|
|
102
|
-
".ini",
|
|
103
|
-
".rtf",
|
|
104
|
-
],
|
|
105
|
-
audio: [
|
|
106
|
-
".mp3",
|
|
107
|
-
".wav",
|
|
108
|
-
".ogg",
|
|
109
|
-
".flac",
|
|
110
|
-
".aac",
|
|
111
|
-
".wma",
|
|
112
|
-
".m4a",
|
|
113
|
-
".alac",
|
|
114
|
-
".ape",
|
|
115
|
-
".opus",
|
|
116
|
-
".amr",
|
|
117
|
-
".ra",
|
|
118
|
-
".mid",
|
|
119
|
-
".midi",
|
|
120
|
-
".aiff",
|
|
121
|
-
".pcm",
|
|
122
|
-
".au",
|
|
123
|
-
".wavpack",
|
|
124
|
-
".spx",
|
|
125
|
-
],
|
|
126
|
-
video: [
|
|
127
|
-
".mp4",
|
|
128
|
-
".avi",
|
|
129
|
-
".mkv",
|
|
130
|
-
".mov",
|
|
131
|
-
".wmv",
|
|
132
|
-
".flv",
|
|
133
|
-
".webm",
|
|
134
|
-
".mpg",
|
|
135
|
-
".mpeg",
|
|
136
|
-
".3gp",
|
|
137
|
-
".vob",
|
|
138
|
-
".ogv",
|
|
139
|
-
".m4v",
|
|
140
|
-
".ts",
|
|
141
|
-
".rm",
|
|
142
|
-
".rmvb",
|
|
143
|
-
".m2ts",
|
|
144
|
-
".divx",
|
|
145
|
-
".xvid",
|
|
146
|
-
".swf",
|
|
147
|
-
".f4v",
|
|
148
|
-
],
|
|
149
|
-
archive: [
|
|
150
|
-
".zip",
|
|
151
|
-
".rar",
|
|
152
|
-
".tar",
|
|
153
|
-
".gz",
|
|
154
|
-
".bz2",
|
|
155
|
-
".xz",
|
|
156
|
-
".7z",
|
|
157
|
-
".tar.gz",
|
|
158
|
-
".tar.bz2",
|
|
159
|
-
".tar.xz",
|
|
160
|
-
".tar.lz",
|
|
161
|
-
".tar.lzma",
|
|
162
|
-
".cab",
|
|
163
|
-
".iso",
|
|
164
|
-
".dmg",
|
|
165
|
-
".tgz",
|
|
166
|
-
".apk",
|
|
167
|
-
".gz2",
|
|
168
|
-
".tar.zst",
|
|
169
|
-
],
|
|
170
|
-
code: [
|
|
171
|
-
".js",
|
|
172
|
-
".ts",
|
|
173
|
-
".py",
|
|
174
|
-
".java",
|
|
175
|
-
".cpp",
|
|
176
|
-
".c",
|
|
177
|
-
".html",
|
|
178
|
-
".css",
|
|
179
|
-
".scss",
|
|
180
|
-
".less",
|
|
181
|
-
".sass",
|
|
182
|
-
".php",
|
|
183
|
-
".rb",
|
|
184
|
-
".go",
|
|
185
|
-
".swift",
|
|
186
|
-
".rs",
|
|
187
|
-
".kt",
|
|
188
|
-
".scala",
|
|
189
|
-
".lua",
|
|
190
|
-
".pl",
|
|
191
|
-
".m",
|
|
192
|
-
".h",
|
|
193
|
-
".xml",
|
|
194
|
-
".json",
|
|
195
|
-
".yaml",
|
|
196
|
-
".yml",
|
|
197
|
-
".toml",
|
|
198
|
-
".vue",
|
|
199
|
-
".ejs",
|
|
200
|
-
".handlebars",
|
|
201
|
-
".jinja",
|
|
202
|
-
".dart",
|
|
203
|
-
],
|
|
204
|
-
font: [
|
|
205
|
-
".woff",
|
|
206
|
-
".woff2",
|
|
207
|
-
".ttf",
|
|
208
|
-
".otf",
|
|
209
|
-
".eot",
|
|
210
|
-
".svg",
|
|
211
|
-
".ttc",
|
|
212
|
-
".fnt",
|
|
213
|
-
".fon",
|
|
214
|
-
".otc",
|
|
215
|
-
],
|
|
216
|
-
database: [
|
|
217
|
-
".sql",
|
|
218
|
-
".sqlite",
|
|
219
|
-
".db",
|
|
220
|
-
".mdb",
|
|
221
|
-
".accdb",
|
|
222
|
-
".jsonld",
|
|
223
|
-
".xml",
|
|
224
|
-
".csv",
|
|
225
|
-
],
|
|
226
|
-
markup: [".html", ".htm", ".xhtml", ".xml", ".json", ".yaml", ".yml"],
|
|
227
|
-
configuration: [
|
|
228
|
-
".ini",
|
|
229
|
-
".conf",
|
|
230
|
-
".cfg",
|
|
231
|
-
".env",
|
|
232
|
-
".properties",
|
|
233
|
-
".json",
|
|
234
|
-
".toml",
|
|
235
|
-
],
|
|
236
|
-
logs: [".log", ".err", ".trace", ".out"],
|
|
237
|
-
script: [
|
|
238
|
-
".bash",
|
|
239
|
-
".sh",
|
|
240
|
-
".zsh",
|
|
241
|
-
".bat",
|
|
242
|
-
".ps1",
|
|
243
|
-
".vbs",
|
|
244
|
-
".cmd",
|
|
245
|
-
".sed",
|
|
246
|
-
".awk",
|
|
247
|
-
".php",
|
|
248
|
-
],
|
|
249
|
-
};
|
package/lib/Index.d.ts
DELETED
package/lib/Index.js
DELETED
package/lib/Math/Math.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 转为百分比字符串
|
|
3
|
-
* @param value 分子
|
|
4
|
-
* @param totalValue 分母
|
|
5
|
-
* @param decimalPlaces 保留小数位
|
|
6
|
-
* @returns 10.00%
|
|
7
|
-
*/
|
|
8
|
-
export function _ConvertToPercentage(
|
|
9
|
-
value: number,
|
|
10
|
-
totalValue: number,
|
|
11
|
-
decimalPlaces?: number
|
|
12
|
-
): number;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 误差范围
|
|
16
|
-
* @param value 需要判断的数字
|
|
17
|
-
* @param target 目标数字
|
|
18
|
-
* @param errorMargin 正负误差范围
|
|
19
|
-
* @returns 是否在误差内
|
|
20
|
-
*/
|
|
21
|
-
export function _IsWithinErrorMargin(
|
|
22
|
-
value: number,
|
|
23
|
-
target: number,
|
|
24
|
-
errorMargin: number
|
|
25
|
-
): boolean;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 进度
|
|
29
|
-
* @param {(schedule)=>void} callback callback( 进度百分比 )
|
|
30
|
-
* @param {Number} TIME 总时长
|
|
31
|
-
*/
|
|
32
|
-
export function _Schedule(
|
|
33
|
-
callback: (schedule: number) => void,
|
|
34
|
-
TIME: number
|
|
35
|
-
): void;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 格式化数字,给数字加上千位分隔符。
|
|
39
|
-
* @param {number} number - 要格式化的数字。
|
|
40
|
-
* @returns {string} - 格式化后的字符串。
|
|
41
|
-
*/
|
|
42
|
-
export function _FormatNumber(number: number): string;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 纯数字转 数字加单位
|
|
46
|
-
* @param number 数字或字符串数字
|
|
47
|
-
* @param config : {
|
|
48
|
-
* join 拼接起来吗
|
|
49
|
-
* suffix 后缀
|
|
50
|
-
* integer 不超过万位的数字时保持整数吗
|
|
51
|
-
* }
|
|
52
|
-
* @returns 123456 --> 12.34万 | [ 12.34 , 万 ]
|
|
53
|
-
*/
|
|
54
|
-
export function _FormatNumberWithUnit(
|
|
55
|
-
number: string | number,
|
|
56
|
-
config?: {
|
|
57
|
-
join?: boolean;
|
|
58
|
-
suffix?: string;
|
|
59
|
-
integer?: boolean;
|
|
60
|
-
}
|
|
61
|
-
): string | [number, string];
|
|
62
|
-
|
|
63
|
-
interface Point {
|
|
64
|
-
x: number;
|
|
65
|
-
y: number;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 判断点是否在多边形内
|
|
69
|
-
* @param point - 待检测的点,包含 x 和 y 坐标
|
|
70
|
-
* @param polygon - 多边形的点集,数组形式,每个点包含 x 和 y 坐标
|
|
71
|
-
* @returns boolean - 点是否在多边形内
|
|
72
|
-
*/
|
|
73
|
-
export function _IsPointInPolygon(point: Point, polygon: Point[]): boolean;
|
package/lib/Math/Math.js
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 转为百分比字符串
|
|
3
|
-
* @param value 分子
|
|
4
|
-
* @param totalValue 分母
|
|
5
|
-
* @param decimalPlaces 保留小数位
|
|
6
|
-
* @returns 10.00%
|
|
7
|
-
*/
|
|
8
|
-
export function _ConvertToPercentage(value, totalValue, decimalPlaces = 2) {
|
|
9
|
-
if (
|
|
10
|
-
typeof value !== "number" ||
|
|
11
|
-
typeof totalValue !== "number" ||
|
|
12
|
-
typeof decimalPlaces !== "number" ||
|
|
13
|
-
totalValue == 0
|
|
14
|
-
) {
|
|
15
|
-
console.error("异常输入:", arguments);
|
|
16
|
-
return "0.00%";
|
|
17
|
-
}
|
|
18
|
-
return (
|
|
19
|
-
Number(
|
|
20
|
-
parseInt((value / totalValue) * Math.pow(10, 2 + decimalPlaces)) /
|
|
21
|
-
Math.pow(10, decimalPlaces)
|
|
22
|
-
) || 0
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 误差范围
|
|
28
|
-
* @param value 需要判断的数字
|
|
29
|
-
* @param target 目标数字
|
|
30
|
-
* @param errorMargin 正负误差范围
|
|
31
|
-
* @returns 是否在误差内
|
|
32
|
-
*/
|
|
33
|
-
export function _IsWithinErrorMargin(value, target, errorMargin) {
|
|
34
|
-
return Math.abs(value - target) <= errorMargin;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 进度
|
|
39
|
-
* @param {(schedule)=>void} callback callback( 进度百分比 )
|
|
40
|
-
* @param {Number} TIME 总时长
|
|
41
|
-
*/
|
|
42
|
-
export function _Schedule(callback, TIME = 500) {
|
|
43
|
-
let t;
|
|
44
|
-
function loop(time) {
|
|
45
|
-
if (!t) t = time;
|
|
46
|
-
let percentage = Math.min((time - t) / TIME, 1);
|
|
47
|
-
callback(percentage);
|
|
48
|
-
if (time - t < TIME) requestAnimationFrame(loop);
|
|
49
|
-
}
|
|
50
|
-
requestAnimationFrame(loop);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 格式化数字,给数字加上千位分隔符。
|
|
55
|
-
* @param {number} number - 要格式化的数字。
|
|
56
|
-
* @returns {string} - 格式化后的字符串。
|
|
57
|
-
*/
|
|
58
|
-
export function _FormatNumber(number) {
|
|
59
|
-
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 纯数字转 数字加单位
|
|
64
|
-
* @param number 数字或字符串数字
|
|
65
|
-
* @param config : {
|
|
66
|
-
* join 拼接起来吗
|
|
67
|
-
* suffix 后缀
|
|
68
|
-
* integer 不超过万位的数字时保持整数吗
|
|
69
|
-
* }
|
|
70
|
-
* @returns 123456 --> 12.34万 | [ 12.34 , 万 ]
|
|
71
|
-
*/
|
|
72
|
-
export function _FormatNumberWithUnit(number, config = {}) {
|
|
73
|
-
const { join, suffix, integer } = Object.assign(
|
|
74
|
-
{
|
|
75
|
-
join: true,
|
|
76
|
-
suffix: "",
|
|
77
|
-
integer: false,
|
|
78
|
-
},
|
|
79
|
-
config
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
function _join(value, suffix, plus = true) {
|
|
83
|
-
value = (plus ? "" : "-") + value;
|
|
84
|
-
if (join) return value + suffix;
|
|
85
|
-
else return [value, suffix];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (typeof number == "string") {
|
|
89
|
-
if (!/^\d+$/.test(number.trim())) {
|
|
90
|
-
console.error("错误输入:", number);
|
|
91
|
-
return _join(0, suffix);
|
|
92
|
-
}
|
|
93
|
-
} else if (typeof number != "number") {
|
|
94
|
-
console.error("错误输入:", number);
|
|
95
|
-
return _join(0, suffix);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (Math.abs(number) == Infinity || number == 0) {
|
|
99
|
-
return _join(0, suffix);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
number = Number(number);
|
|
103
|
-
const plus = number >= 0;
|
|
104
|
-
number = Math.abs(number);
|
|
105
|
-
|
|
106
|
-
const units = [
|
|
107
|
-
"",
|
|
108
|
-
"万",
|
|
109
|
-
"亿",
|
|
110
|
-
"兆",
|
|
111
|
-
"京",
|
|
112
|
-
"垓",
|
|
113
|
-
"秭",
|
|
114
|
-
"穰",
|
|
115
|
-
"沟",
|
|
116
|
-
"涧",
|
|
117
|
-
"正",
|
|
118
|
-
"载",
|
|
119
|
-
"极",
|
|
120
|
-
];
|
|
121
|
-
|
|
122
|
-
/** 计算位数 */
|
|
123
|
-
const digits = Math.floor(Math.log10(number) / 4);
|
|
124
|
-
|
|
125
|
-
/** 不超过万位的数字直接返回 */
|
|
126
|
-
if (digits === 0) {
|
|
127
|
-
if (integer) {
|
|
128
|
-
return _join(number, suffix, plus);
|
|
129
|
-
} else {
|
|
130
|
-
return _join(number.toFixed(2), suffix, plus);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const dividedNumber = number / Math.pow(10000, digits);
|
|
135
|
-
const formattedNumber = dividedNumber.toFixed(2);
|
|
136
|
-
|
|
137
|
-
return _join(formattedNumber, units[digits] + suffix, plus);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* 判断点是否在多边形内
|
|
142
|
-
* @param point - 待检测的点,包含 x 和 y 坐标
|
|
143
|
-
* @param polygon - 多边形的点集,数组形式,每个点包含 x 和 y 坐标
|
|
144
|
-
* @returns boolean - 点是否在多边形内
|
|
145
|
-
*/
|
|
146
|
-
export function _IsPointInPolygon(point, polygon) {
|
|
147
|
-
let isInside = false;
|
|
148
|
-
|
|
149
|
-
const { x, y } = point;
|
|
150
|
-
const len = polygon.length;
|
|
151
|
-
|
|
152
|
-
for (let i = 0, j = len - 1; i < len; j = i++) {
|
|
153
|
-
const xi = polygon[i].x,
|
|
154
|
-
yi = polygon[i].y;
|
|
155
|
-
const xj = polygon[j].x,
|
|
156
|
-
yj = polygon[j].y;
|
|
157
|
-
|
|
158
|
-
const intersect =
|
|
159
|
-
yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
|
|
160
|
-
|
|
161
|
-
if (intersect) isInside = !isInside;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return isInside;
|
|
165
|
-
}
|
package/lib/User/User.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 滚动结束监听器
|
|
3
|
-
* @param {(trigger: "vertical" | "horizontal") => void} callback
|
|
4
|
-
*/
|
|
5
|
-
export function _ScrollEndListener(
|
|
6
|
-
callback: (trigger: "vertical" | "horizontal") => void
|
|
7
|
-
): (payload: Event) => void;
|
|
8
|
-
|
|
9
|
-
type UiLibrary = "naiveUI" | "ElementPlus" | "Element";
|
|
10
|
-
/**
|
|
11
|
-
* 点击非指定dom(包含子级dom)时执行 callback
|
|
12
|
-
* @param querySelector 允许点击的 dom 顶层祖先元素选择器
|
|
13
|
-
* @param callback 满足条件时执行的回调
|
|
14
|
-
*
|
|
15
|
-
* @param options 其他配置
|
|
16
|
-
* @param options.uiLibrary 项目使用的 ui库 , 用于排除 ui库 创建的元素 , 避免点击 ui库 创建的元素时意外的执行 callback
|
|
17
|
-
* @param options.isClickAllowed 是否允许该点击 ( 如果不确定可以返回 undefined )
|
|
18
|
-
*/
|
|
19
|
-
export function _CloseOnOutsideClick(
|
|
20
|
-
querySelector: string[],
|
|
21
|
-
callback: Function,
|
|
22
|
-
options?: {
|
|
23
|
-
uiLibrary?: UiLibrary[];
|
|
24
|
-
isClickAllowed?: (event: MouseEvent) => boolean | undefined;
|
|
25
|
-
}
|
|
26
|
-
): void;
|
|
27
|
-
|
|
28
|
-
/** 拖拽配置 */
|
|
29
|
-
type DragOption = {
|
|
30
|
-
/** 拖拽范围限制 */
|
|
31
|
-
limit?: {
|
|
32
|
-
max: {
|
|
33
|
-
top: number;
|
|
34
|
-
left: number;
|
|
35
|
-
};
|
|
36
|
-
min: {
|
|
37
|
-
top: number;
|
|
38
|
-
left: number;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
/** 指定的拖拽元素 */
|
|
42
|
-
dragDom?: HTMLElement;
|
|
43
|
-
};
|
|
44
|
-
/** 拖拽 */
|
|
45
|
-
export class _Drag {
|
|
46
|
-
/**
|
|
47
|
-
* 初始化拖拽
|
|
48
|
-
* @param dom 被拖拽的元素
|
|
49
|
-
* @param option 拖拽配置
|
|
50
|
-
*/
|
|
51
|
-
init(dom: HTMLElement, option?: DragOption): void;
|
|
52
|
-
/** 结束拖拽 */
|
|
53
|
-
finish(): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** 更新后的位置信息 */
|
|
57
|
-
type UpdateValue = {
|
|
58
|
-
top: number;
|
|
59
|
-
left: number;
|
|
60
|
-
percentage?: {
|
|
61
|
-
top: number;
|
|
62
|
-
left: number;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
/** 局部拖拽配置 */
|
|
66
|
-
type LocalDragOptions = {
|
|
67
|
-
limit?: DragOption["limit"];
|
|
68
|
-
update_move?: (value: UpdateValue) => void | undefined;
|
|
69
|
-
update_up?: (value: UpdateValue) => void | undefined;
|
|
70
|
-
};
|
|
71
|
-
/** 局部拖拽 计算位置距离/百分比 */
|
|
72
|
-
export class _LocalDrag {
|
|
73
|
-
/**
|
|
74
|
-
* 初始化拖拽
|
|
75
|
-
* @param parentDom 被拖拽元素的祖先元素
|
|
76
|
-
* @param option 局部拖拽配置
|
|
77
|
-
*/
|
|
78
|
-
init(parentDom: HTMLElement, options?: LocalDragOptions): void;
|
|
79
|
-
/** 结束拖拽 */
|
|
80
|
-
finish(): void;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** 进入全屏模式 */
|
|
84
|
-
export function _EnterFullscreen(content: HTMLElement): Promise<void>;
|
|
85
|
-
/** 退出全屏模式 */
|
|
86
|
-
export function _ExitFullscreen(): Promise<void>;
|
|
87
|
-
/** 判断是否处于全屏模式 */
|
|
88
|
-
export function _IsFullscreen(): HTMLElement | undefined;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* 返回一个用于切换全屏模式的函数
|
|
92
|
-
* @param {HTMLElement} content - 需要进入全屏的元素
|
|
93
|
-
* 该函数通过检查不同浏览器的特定方法来实现全屏切换
|
|
94
|
-
*/
|
|
95
|
-
export function _Fullscreen(content: HTMLElement): () => void;
|