@cclr/front 0.1.8 → 0.1.10
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/lib/cjs/index.js +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/type/index.d.ts +77 -1
- package/package.json +4 -4
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("@cclr/lang");
|
|
1
|
+
"use strict";var t=require("@cclr/lang");function r(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function e(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return r(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var n=function(){for(var r=[],o=0;o<arguments.length;o++){var i=o<0||arguments.length<=o?void 0:arguments[o];if(i)if("string"!=typeof i&&"number"!=typeof i){if(t.isArray(i)){var a=n.apply(void 0,e(i));a&&r.push(a)}else if("object"==typeof i){if(i.toString!==Object.prototype.toString){r.push(i.toString());continue}for(var u in i)t.hasOwn(i,u)&&i[u]&&r.push(u)}}else r.push(i)}return r.join(" ")},o=function(r,e,n,o){if(!(r instanceof HTMLElement))throw new Error("The provided DOM element is not an HTMLElement.");if("string"!=typeof e)throw new Error("The event type must be a string.");if(!(t.isFunction(n)||n instanceof Object))throw new Error("The listener must be a function or an EventListenerObject.");return r.addEventListener(e,n,o),function(){r.removeEventListener(e,n,o)}};exports.addEventListener=o,exports.addEventListenerMultiple=function(t,r,e){var n=[];return Object.keys(r).forEach((function(i){n.push(o(t,i,r[i],e))})),function(){n.forEach((function(t){return null==t?void 0:t()}))}},exports.classNames=n;
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isArray as t,hasOwn as
|
|
1
|
+
import{isArray as t,hasOwn as r,isFunction as n}from"@cclr/lang";function e(t,r){(null==r||r>t.length)&&(r=t.length);for(var n=0,e=Array(r);n<r;n++)e[n]=t[n];return e}function o(t){return function(t){if(Array.isArray(t))return e(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,r){if(t){if("string"==typeof t)return e(t,r);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,r):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var i=function(){for(var n=[],e=0;e<arguments.length;e++){var a=e<0||arguments.length<=e?void 0:arguments[e];if(a)if("string"!=typeof a&&"number"!=typeof a){if(t(a)){var f=i.apply(void 0,o(a));f&&n.push(f)}else if("object"==typeof a){if(a.toString!==Object.prototype.toString){n.push(a.toString());continue}for(var u in a)r(a,u)&&a[u]&&n.push(u)}}else n.push(a)}return n.join(" ")},a=function(t,r,e,o){if(!(t instanceof HTMLElement))throw new Error("The provided DOM element is not an HTMLElement.");if("string"!=typeof r)throw new Error("The event type must be a string.");if(!(n(e)||e instanceof Object))throw new Error("The listener must be a function or an EventListenerObject.");return t.addEventListener(r,e,o),function(){t.removeEventListener(r,e,o)}},f=function(t,r,n){var e=[];return Object.keys(r).forEach((function(o){e.push(a(t,o,r[o],n))})),function(){e.forEach((function(t){return null==t?void 0:t()}))}};export{a as addEventListener,f as addEventListenerMultiple,i as classNames};
|
package/lib/type/index.d.ts
CHANGED
|
@@ -11,4 +11,80 @@ type ClassObject = Record<string, TAny>;
|
|
|
11
11
|
*/
|
|
12
12
|
declare const classNames: (...args: ClassValue[]) => string;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
type CommonDOMEventTypes = 'click' | 'dblclick' | 'mousedown' | 'mouseup' | 'mousemove' | 'mouseover' | 'mouseout' | 'keydown' | 'keyup' | 'keypress' | 'touchstart' | 'touchend' | 'touchmove' | 'touchcancel' | 'dragstart' | 'drag' | 'dragend' | 'dragenter' | 'dragover' | 'dragleave' | 'drop' | 'scroll' | 'scroll' | 'scroll' | 'wheel' | 'resize';
|
|
15
|
+
type EventListenerOptions = boolean | AddEventListenerOptions;
|
|
16
|
+
type TEventMap = Partial<{
|
|
17
|
+
click: (e: MouseEvent) => void;
|
|
18
|
+
dblclick: (e: MouseEvent) => void;
|
|
19
|
+
mousedown: (e: MouseEvent) => void;
|
|
20
|
+
mouseup: (e: MouseEvent) => void;
|
|
21
|
+
mousemove: (e: MouseEvent) => void;
|
|
22
|
+
mouseover: (e: MouseEvent) => void;
|
|
23
|
+
mouseout: (e: MouseEvent) => void;
|
|
24
|
+
keydown: (e: KeyboardEvent) => void;
|
|
25
|
+
keyup: (e: KeyboardEvent) => void;
|
|
26
|
+
keypress: (e: KeyboardEvent) => void;
|
|
27
|
+
touchstart: (e: TouchEvent) => void;
|
|
28
|
+
touchend: (e: TouchEvent) => void;
|
|
29
|
+
touchmove: (e: TouchEvent) => void;
|
|
30
|
+
touchcancel: (e: TouchEvent) => void;
|
|
31
|
+
/**
|
|
32
|
+
* 拖动元素开始触发
|
|
33
|
+
* dataTransfer.setData()方法设置数据类型和拖动的数据
|
|
34
|
+
* e.dataTransfer.setData("Text", event.target.id);
|
|
35
|
+
*/
|
|
36
|
+
dragstart: (e: DragEvent) => void;
|
|
37
|
+
/**
|
|
38
|
+
* 拖动元素时触发
|
|
39
|
+
*/
|
|
40
|
+
drag: (e: DragEvent) => void;
|
|
41
|
+
/**
|
|
42
|
+
* 拖动元素结束触发
|
|
43
|
+
*/
|
|
44
|
+
dragend: (e: DragEvent) => void;
|
|
45
|
+
/**
|
|
46
|
+
* 接收元素,进入时触发
|
|
47
|
+
*/
|
|
48
|
+
dragenter: (e: DragEvent) => void;
|
|
49
|
+
/**
|
|
50
|
+
* 接收元素,内部移动时触发
|
|
51
|
+
* 如果使用drop,必须防止元素的默认处理
|
|
52
|
+
* event.preventDefault();
|
|
53
|
+
*/
|
|
54
|
+
dragover: (e: DragEvent) => void;
|
|
55
|
+
/**
|
|
56
|
+
* 接收元素,离开时触发
|
|
57
|
+
*/
|
|
58
|
+
dragleave: (e: DragEvent) => void;
|
|
59
|
+
/**
|
|
60
|
+
* 接收元素,拖动完成后触发
|
|
61
|
+
* dataTransfer.getData()方法获得拖放数据
|
|
62
|
+
* e.dataTransfer.getData("Text");
|
|
63
|
+
*/
|
|
64
|
+
drop: (e: DragEvent) => void;
|
|
65
|
+
scroll: (e: Event) => void;
|
|
66
|
+
wheel: (e: WheelEvent) => void;
|
|
67
|
+
resize: (e: Event) => void;
|
|
68
|
+
}>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 添加事件监听
|
|
72
|
+
* @param dom 要绑定事件的 DOM 元素
|
|
73
|
+
* @param type 事件类型
|
|
74
|
+
* @param listener 事件监听器
|
|
75
|
+
* @param options 事件监听选项
|
|
76
|
+
* @returns 移除事件监听的函数
|
|
77
|
+
*/
|
|
78
|
+
declare const addEventListener: <T extends HTMLElement = HTMLElement>(dom: T, type: CommonDOMEventTypes, listener: (event: Event) => void, options?: EventListenerOptions) => (() => void);
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 添加事件监听
|
|
82
|
+
* @param dom 要绑定事件的 DOM 元素
|
|
83
|
+
* @param type 事件类型
|
|
84
|
+
* @param listener 事件监听器
|
|
85
|
+
* @param options 事件监听选项
|
|
86
|
+
* @returns 移除事件监听的函数
|
|
87
|
+
*/
|
|
88
|
+
declare const addEventListenerMultiple: <T extends HTMLElement = HTMLElement>(dom: T, listenerMap: TEventMap, options?: EventListenerOptions) => () => void;
|
|
89
|
+
|
|
90
|
+
export { type CommonDOMEventTypes, type EventListenerOptions, type TEventMap, addEventListener, addEventListenerMultiple, classNames };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cclr/front",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "前端开发使用工具",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"g:test": "vitest run",
|
|
28
28
|
"g:build": "ccf build"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "ca3a561247bd3c614321b089cfd1a91f9a375ea8",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@cclr/lang": "0.1.
|
|
33
|
-
"@cclr/utils": "0.1.
|
|
32
|
+
"@cclr/lang": "0.1.10",
|
|
33
|
+
"@cclr/utils": "0.1.10"
|
|
34
34
|
}
|
|
35
35
|
}
|