@whitesev/domutils 1.2.0 → 1.3.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.
@@ -1,8 +1,8 @@
1
- import type { DOMUtilsCoreOption } from "./DOMUtilsCore";
2
1
  import { type DOMUtilsCreateElementAttributesMap, DOMUtilsEvent } from "./DOMUtilsEvent";
3
2
  import { ParseHTMLReturnType } from "./types/global";
3
+ import { type UtilsWindowApiOption } from "./WindowApi";
4
4
  declare class DOMUtils extends DOMUtilsEvent {
5
- constructor(option?: DOMUtilsCoreOption);
5
+ constructor(option?: UtilsWindowApiOption);
6
6
  /** 版本号 */
7
7
  version: string;
8
8
  /**
@@ -589,7 +589,7 @@ declare class DOMUtils extends DOMUtilsEvent {
589
589
  * @param option
590
590
  * @returns
591
591
  */
592
- createDOMUtils(option?: DOMUtilsCoreOption): DOMUtils;
592
+ createDOMUtils(option?: UtilsWindowApiOption): DOMUtils;
593
593
  /**
594
594
  * 获取文字的位置信息
595
595
  * @param $input 输入框
@@ -1,5 +1,7 @@
1
+ import { UtilsWindowApiOption } from "./WindowApi";
1
2
  /** 通用工具类 */
2
3
  declare const DOMUtilsCommonUtils: {
4
+ windowApi: UtilsWindowApiOption;
3
5
  /**
4
6
  * 判断元素是否已显示或已连接
5
7
  * @param element
@@ -1,3 +1,4 @@
1
+ import { UtilsWindowApiOption } from "./WindowApi";
1
2
  export type DOMUtilsEventObject<T extends Node> = Event & {
2
3
  target: T;
3
4
  };
@@ -199,7 +200,9 @@ export declare interface DOMUtilsEventListenerOptionsAttribute {
199
200
  selector?: string;
200
201
  }
201
202
  export declare type DOMUtilsElementEventType = HTMLElement | string | NodeList | (HTMLElement | Window | Document | Element | typeof globalThis)[] | Window | Document | Element | null | typeof globalThis | ShadowRoot | EventTarget | ChildNode | Node;
202
- declare class DOMUtilsEvent {
203
+ export declare class DOMUtilsEvent {
204
+ windowApi: UtilsWindowApiOption;
205
+ constructor(windowApiOption?: UtilsWindowApiOption);
203
206
  /**
204
207
  * 绑定事件
205
208
  * @param element 需要绑定的元素|元素数组|window
@@ -505,5 +508,70 @@ declare class DOMUtilsEvent {
505
508
  * })
506
509
  */
507
510
  keypress(target: HTMLElement | Window | typeof globalThis | string, handler: (event: DOMUtils_Event["keypress"]) => void, option?: boolean | AddEventListenerOptions): void;
511
+ /**
512
+ * 监听某个元素键盘按键事件或window全局按键事件
513
+ * 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
514
+ * @param target 需要监听的对象,可以是全局Window或者某个元素
515
+ * @param eventName 事件名,默认keypress
516
+ * @param callback 自己定义的回调事件,参数1为当前的key,参数2为组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
517
+ * @param options 监听事件的配置
518
+ * @example
519
+ Utils.listenKeyboard(window,(keyName,keyValue,otherKey,event)=>{
520
+ if(keyName === "Enter"){
521
+ console.log("回车按键的值是:"+keyValue)
522
+ }
523
+ if(otherKey.indexOf("ctrl") && keyName === "Enter" ){
524
+ console.log("Ctrl和回车键");
525
+ }
526
+ })
527
+ * @example
528
+ 字母和数字键的键码值(keyCode)
529
+ 按键 键码 按键 键码 按键 键码 按键 键码
530
+ A 65 J 74 S 83 1 49
531
+ B 66 K 75 T 84 2 50
532
+ C 67 L 76 U 85 3 51
533
+ D 68 M 77 V 86 4 52
534
+ E 69 N 78 W 87 5 53
535
+ F 70 O 79 X 88 6 54
536
+ G 71 P 80 Y 89 7 55
537
+ H 72 Q 81 Z 90 8 56
538
+ I 73 R 82 0 48 9 57
539
+
540
+ 数字键盘上的键的键码值(keyCode)
541
+ 功能键键码值(keyCode)
542
+ 按键 键码 按键 键码 按键 键码 按键 键码
543
+ 0 96 8 104 F1 112 F7 118
544
+ 1 97 9 105 F2 113 F8 119
545
+ 2 98 * 106 F3 114 F9 120
546
+ 3 99 + 107 F4 115 F10 121
547
+ 4 100 Enter 108 F5 116 F11 122
548
+ 5 101 - 109 F6 117 F12 123
549
+ 6 102 . 110
550
+ 7 103 / 111
551
+
552
+ 控制键键码值(keyCode)
553
+ 按键 键码 按键 键码 按键 键码 按键 键码
554
+ BackSpace 8 Esc 27 → 39 -_ 189
555
+ Tab 9 Spacebar 32 ↓ 40 .> 190
556
+ Clear 12 Page Up 33 Insert 45 /? 191
557
+ Enter 13 Page Down 34 Delete 46 `~ 192
558
+ Shift 16 End 35 Num Lock 144 [{ 219
559
+ Control 17 Home 36 ;: 186 \| 220
560
+ Alt 18 ← 37 =+ 187 ]} 221
561
+ Cape Lock 20 ↑ 38 ,< 188 '" 222
562
+
563
+ 多媒体键码值(keyCode)
564
+ 按键 键码
565
+ 音量加 175
566
+ 音量减 174
567
+ 停止 179
568
+ 静音 173
569
+ 浏览器 172
570
+ 邮件 180
571
+ 搜索 170
572
+ 收藏 171
573
+ **/
574
+ listenKeyboard(target: Window | Node | HTMLElement | typeof globalThis, eventName: ("keyup" | "keypress" | "keydown") | undefined, callback: (keyName: string, keyValue: string, otherCodeList: string[], event: KeyboardEvent) => void, options?: AddEventListenerOptions | boolean): {
575
+ removeListen(): void;
576
+ };
508
577
  }
509
- export { DOMUtilsEvent };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 配置类型
3
+ */
4
+ export type UtilsWindowApiOption = {
5
+ document: Document;
6
+ window: Window & typeof globalThis;
7
+ globalThis: typeof globalThis | Window;
8
+ self: Window & typeof globalThis;
9
+ top: Window;
10
+ };
11
+ export declare class WindowApi {
12
+ /** 默认的配置 */
13
+ private defaultApi;
14
+ /** 使用的配置 */
15
+ private api;
16
+ constructor(option?: UtilsWindowApiOption);
17
+ get document(): Document;
18
+ get window(): Window & typeof globalThis;
19
+ get globalThis(): typeof globalThis | Window;
20
+ get self(): Window & typeof globalThis;
21
+ get top(): Window;
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/domutils",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "使用js重新对jQuery的部分函数进行了仿写",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",