@whitesev/utils 2.1.5 → 2.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/dist/index.amd.js +1 -34
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +1 -34
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -34
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +1 -34
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +1 -34
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +1 -34
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +0 -66
- package/package.json +1 -1
- package/src/Utils.ts +1 -127
|
@@ -944,72 +944,6 @@ declare class Utils {
|
|
|
944
944
|
* > ['jsonToArray', 'Array']
|
|
945
945
|
**/
|
|
946
946
|
parseObjectToArray(target: AnyObject): any;
|
|
947
|
-
/**
|
|
948
|
-
* 监听某个元素键盘按键事件或window全局按键事件
|
|
949
|
-
* 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
|
|
950
|
-
* @param target 需要监听的对象,可以是全局Window或者某个元素
|
|
951
|
-
* @param eventName 事件名,默认keypress
|
|
952
|
-
* @param callback 自己定义的回调事件,参数1为当前的key,参数2为组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
|
|
953
|
-
* @param options 监听事件的配置
|
|
954
|
-
* @example
|
|
955
|
-
Utils.listenKeyboard(window,(keyName,keyValue,otherKey,event)=>{
|
|
956
|
-
if(keyName === "Enter"){
|
|
957
|
-
console.log("回车按键的值是:"+keyValue)
|
|
958
|
-
}
|
|
959
|
-
if(otherKey.indexOf("ctrl") && keyName === "Enter" ){
|
|
960
|
-
console.log("Ctrl和回车键");
|
|
961
|
-
}
|
|
962
|
-
})
|
|
963
|
-
* @example
|
|
964
|
-
字母和数字键的键码值(keyCode)
|
|
965
|
-
按键 键码 按键 键码 按键 键码 按键 键码
|
|
966
|
-
A 65 J 74 S 83 1 49
|
|
967
|
-
B 66 K 75 T 84 2 50
|
|
968
|
-
C 67 L 76 U 85 3 51
|
|
969
|
-
D 68 M 77 V 86 4 52
|
|
970
|
-
E 69 N 78 W 87 5 53
|
|
971
|
-
F 70 O 79 X 88 6 54
|
|
972
|
-
G 71 P 80 Y 89 7 55
|
|
973
|
-
H 72 Q 81 Z 90 8 56
|
|
974
|
-
I 73 R 82 0 48 9 57
|
|
975
|
-
|
|
976
|
-
数字键盘上的键的键码值(keyCode)
|
|
977
|
-
功能键键码值(keyCode)
|
|
978
|
-
按键 键码 按键 键码 按键 键码 按键 键码
|
|
979
|
-
0 96 8 104 F1 112 F7 118
|
|
980
|
-
1 97 9 105 F2 113 F8 119
|
|
981
|
-
2 98 * 106 F3 114 F9 120
|
|
982
|
-
3 99 + 107 F4 115 F10 121
|
|
983
|
-
4 100 Enter 108 F5 116 F11 122
|
|
984
|
-
5 101 - 109 F6 117 F12 123
|
|
985
|
-
6 102 . 110
|
|
986
|
-
7 103 / 111
|
|
987
|
-
|
|
988
|
-
控制键键码值(keyCode)
|
|
989
|
-
按键 键码 按键 键码 按键 键码 按键 键码
|
|
990
|
-
BackSpace 8 Esc 27 → 39 -_ 189
|
|
991
|
-
Tab 9 Spacebar 32 ↓ 40 .> 190
|
|
992
|
-
Clear 12 Page Up 33 Insert 45 /? 191
|
|
993
|
-
Enter 13 Page Down 34 Delete 46 `~ 192
|
|
994
|
-
Shift 16 End 35 Num Lock 144 [{ 219
|
|
995
|
-
Control 17 Home 36 ;: 186 \| 220
|
|
996
|
-
Alt 18 ← 37 =+ 187 ]} 221
|
|
997
|
-
Cape Lock 20 ↑ 38 ,< 188 '" 222
|
|
998
|
-
|
|
999
|
-
多媒体键码值(keyCode)
|
|
1000
|
-
按键 键码
|
|
1001
|
-
音量加 175
|
|
1002
|
-
音量减 174
|
|
1003
|
-
停止 179
|
|
1004
|
-
静音 173
|
|
1005
|
-
浏览器 172
|
|
1006
|
-
邮件 180
|
|
1007
|
-
搜索 170
|
|
1008
|
-
收藏 171
|
|
1009
|
-
**/
|
|
1010
|
-
listenKeyboard(target: Window | Node | HTMLElement | typeof globalThis, eventName: "keyup" | "keypress" | "keydown", callback: (keyName: string, keyValue: string, otherCodeList: string[], event: KeyboardEvent) => void, options?: AddEventListenerOptions | boolean): {
|
|
1011
|
-
removeListen(): void;
|
|
1012
|
-
};
|
|
1013
947
|
/**
|
|
1014
948
|
* 自动锁对象,用于循环判断运行的函数,在循环外new后使用,注意,如果函数内部存在异步操作,需要使用await
|
|
1015
949
|
* @example
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -52,7 +52,7 @@ class Utils {
|
|
|
52
52
|
this.windowApi = new WindowApi(option);
|
|
53
53
|
}
|
|
54
54
|
/** 版本号 */
|
|
55
|
-
version = "2024.
|
|
55
|
+
version = "2024.8.30";
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
|
|
@@ -2304,132 +2304,6 @@ class Utils {
|
|
|
2304
2304
|
return result;
|
|
2305
2305
|
}
|
|
2306
2306
|
/**
|
|
2307
|
-
* 监听某个元素键盘按键事件或window全局按键事件
|
|
2308
|
-
* 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
|
|
2309
|
-
* @param target 需要监听的对象,可以是全局Window或者某个元素
|
|
2310
|
-
* @param eventName 事件名,默认keypress
|
|
2311
|
-
* @param callback 自己定义的回调事件,参数1为当前的key,参数2为组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
|
|
2312
|
-
* @param options 监听事件的配置
|
|
2313
|
-
* @example
|
|
2314
|
-
Utils.listenKeyboard(window,(keyName,keyValue,otherKey,event)=>{
|
|
2315
|
-
if(keyName === "Enter"){
|
|
2316
|
-
console.log("回车按键的值是:"+keyValue)
|
|
2317
|
-
}
|
|
2318
|
-
if(otherKey.indexOf("ctrl") && keyName === "Enter" ){
|
|
2319
|
-
console.log("Ctrl和回车键");
|
|
2320
|
-
}
|
|
2321
|
-
})
|
|
2322
|
-
* @example
|
|
2323
|
-
字母和数字键的键码值(keyCode)
|
|
2324
|
-
按键 键码 按键 键码 按键 键码 按键 键码
|
|
2325
|
-
A 65 J 74 S 83 1 49
|
|
2326
|
-
B 66 K 75 T 84 2 50
|
|
2327
|
-
C 67 L 76 U 85 3 51
|
|
2328
|
-
D 68 M 77 V 86 4 52
|
|
2329
|
-
E 69 N 78 W 87 5 53
|
|
2330
|
-
F 70 O 79 X 88 6 54
|
|
2331
|
-
G 71 P 80 Y 89 7 55
|
|
2332
|
-
H 72 Q 81 Z 90 8 56
|
|
2333
|
-
I 73 R 82 0 48 9 57
|
|
2334
|
-
|
|
2335
|
-
数字键盘上的键的键码值(keyCode)
|
|
2336
|
-
功能键键码值(keyCode)
|
|
2337
|
-
按键 键码 按键 键码 按键 键码 按键 键码
|
|
2338
|
-
0 96 8 104 F1 112 F7 118
|
|
2339
|
-
1 97 9 105 F2 113 F8 119
|
|
2340
|
-
2 98 * 106 F3 114 F9 120
|
|
2341
|
-
3 99 + 107 F4 115 F10 121
|
|
2342
|
-
4 100 Enter 108 F5 116 F11 122
|
|
2343
|
-
5 101 - 109 F6 117 F12 123
|
|
2344
|
-
6 102 . 110
|
|
2345
|
-
7 103 / 111
|
|
2346
|
-
|
|
2347
|
-
控制键键码值(keyCode)
|
|
2348
|
-
按键 键码 按键 键码 按键 键码 按键 键码
|
|
2349
|
-
BackSpace 8 Esc 27 → 39 -_ 189
|
|
2350
|
-
Tab 9 Spacebar 32 ↓ 40 .> 190
|
|
2351
|
-
Clear 12 Page Up 33 Insert 45 /? 191
|
|
2352
|
-
Enter 13 Page Down 34 Delete 46 `~ 192
|
|
2353
|
-
Shift 16 End 35 Num Lock 144 [{ 219
|
|
2354
|
-
Control 17 Home 36 ;: 186 \| 220
|
|
2355
|
-
Alt 18 ← 37 =+ 187 ]} 221
|
|
2356
|
-
Cape Lock 20 ↑ 38 ,< 188 '" 222
|
|
2357
|
-
|
|
2358
|
-
多媒体键码值(keyCode)
|
|
2359
|
-
按键 键码
|
|
2360
|
-
音量加 175
|
|
2361
|
-
音量减 174
|
|
2362
|
-
停止 179
|
|
2363
|
-
静音 173
|
|
2364
|
-
浏览器 172
|
|
2365
|
-
邮件 180
|
|
2366
|
-
搜索 170
|
|
2367
|
-
收藏 171
|
|
2368
|
-
**/
|
|
2369
|
-
listenKeyboard(
|
|
2370
|
-
target: Window | Node | HTMLElement | typeof globalThis,
|
|
2371
|
-
eventName: "keyup" | "keypress" | "keydown",
|
|
2372
|
-
callback: (
|
|
2373
|
-
keyName: string,
|
|
2374
|
-
keyValue: string,
|
|
2375
|
-
otherCodeList: string[],
|
|
2376
|
-
event: KeyboardEvent
|
|
2377
|
-
) => void,
|
|
2378
|
-
options?: AddEventListenerOptions | boolean
|
|
2379
|
-
): {
|
|
2380
|
-
removeListen(): void;
|
|
2381
|
-
};
|
|
2382
|
-
listenKeyboard(
|
|
2383
|
-
target: Window | Node | HTMLElement | typeof globalThis,
|
|
2384
|
-
eventName: "keyup" | "keypress" | "keydown" = "keypress",
|
|
2385
|
-
callback: (
|
|
2386
|
-
keyName: string,
|
|
2387
|
-
keyValue: string,
|
|
2388
|
-
otherCodeList: string[],
|
|
2389
|
-
event: KeyboardEvent
|
|
2390
|
-
) => void,
|
|
2391
|
-
options?: AddEventListenerOptions | boolean
|
|
2392
|
-
): {
|
|
2393
|
-
removeListen(): void;
|
|
2394
|
-
} {
|
|
2395
|
-
if (
|
|
2396
|
-
typeof target !== "object" ||
|
|
2397
|
-
(typeof target["addEventListener"] !== "function" &&
|
|
2398
|
-
typeof target["removeEventListener"] !== "function")
|
|
2399
|
-
) {
|
|
2400
|
-
throw new Error(
|
|
2401
|
-
"Utils.listenKeyboard 参数 target 必须为 Window|HTMLElement 类型"
|
|
2402
|
-
);
|
|
2403
|
-
}
|
|
2404
|
-
let keyEvent = function (event: KeyboardEvent) {
|
|
2405
|
-
let keyName = event.key || event.code;
|
|
2406
|
-
let keyValue = event.charCode || event.keyCode || event.which;
|
|
2407
|
-
let otherCodeList = [];
|
|
2408
|
-
if (event.ctrlKey) {
|
|
2409
|
-
otherCodeList.push("ctrl");
|
|
2410
|
-
}
|
|
2411
|
-
if (event.altKey) {
|
|
2412
|
-
otherCodeList.push("alt");
|
|
2413
|
-
}
|
|
2414
|
-
if (event.metaKey) {
|
|
2415
|
-
otherCodeList.push("meta");
|
|
2416
|
-
}
|
|
2417
|
-
if (event.shiftKey) {
|
|
2418
|
-
otherCodeList.push("shift");
|
|
2419
|
-
}
|
|
2420
|
-
if (typeof callback === "function") {
|
|
2421
|
-
callback(keyName, keyValue.toString(), otherCodeList, event);
|
|
2422
|
-
}
|
|
2423
|
-
};
|
|
2424
|
-
|
|
2425
|
-
target.addEventListener(eventName, keyEvent as any, options);
|
|
2426
|
-
return {
|
|
2427
|
-
removeListen() {
|
|
2428
|
-
target.removeEventListener(eventName, keyEvent as any);
|
|
2429
|
-
},
|
|
2430
|
-
};
|
|
2431
|
-
}
|
|
2432
|
-
/**
|
|
2433
2307
|
* 自动锁对象,用于循环判断运行的函数,在循环外new后使用,注意,如果函数内部存在异步操作,需要使用await
|
|
2434
2308
|
* @example
|
|
2435
2309
|
let lock = new Utils.LockFunction(()=>{console.log(1)}))
|