@whitesev/domutils 2.0.4 → 2.0.6
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 +51 -57
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +51 -57
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +51 -57
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +51 -57
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +51 -57
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +51 -57
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/CommonUtils.d.ts +10 -10
- package/dist/types/src/OriginPrototype.d.ts +1 -0
- package/dist/types/src/index.d.ts +2 -2
- package/package.json +5 -5
- package/src/CommonUtils.ts +27 -27
- package/src/ElementEvent.ts +16 -31
- package/src/OriginPrototype.ts +1 -0
- package/src/index.ts +11 -7
package/dist/index.iife.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var DOMUtils = (function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const version = "2.0.
|
|
4
|
+
const version = "2.0.6";
|
|
5
5
|
|
|
6
6
|
class WindowApi {
|
|
7
7
|
/** 默认的配置 */
|
|
@@ -108,15 +108,15 @@ var DOMUtils = (function () {
|
|
|
108
108
|
* @param $el
|
|
109
109
|
*/
|
|
110
110
|
forceShow($el) {
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
this.windowApi.document.documentElement.appendChild(
|
|
111
|
+
const $clone = $el.cloneNode(true);
|
|
112
|
+
$clone.setAttribute("style", "visibility: hidden !important;display:block !important;");
|
|
113
|
+
this.windowApi.document.documentElement.appendChild($clone);
|
|
114
114
|
return {
|
|
115
115
|
/**
|
|
116
116
|
* 恢复修改的style
|
|
117
117
|
*/
|
|
118
118
|
recovery() {
|
|
119
|
-
|
|
119
|
+
$clone.remove();
|
|
120
120
|
},
|
|
121
121
|
};
|
|
122
122
|
},
|
|
@@ -149,37 +149,37 @@ var DOMUtils = (function () {
|
|
|
149
149
|
},
|
|
150
150
|
/**
|
|
151
151
|
* 判断是否是window,例如window、self、globalThis
|
|
152
|
-
* @param
|
|
152
|
+
* @param obj
|
|
153
153
|
*/
|
|
154
|
-
isWin(
|
|
155
|
-
if (typeof
|
|
154
|
+
isWin(obj) {
|
|
155
|
+
if (typeof obj !== "object") {
|
|
156
156
|
return false;
|
|
157
157
|
}
|
|
158
|
-
if (
|
|
158
|
+
if (obj instanceof Node) {
|
|
159
159
|
return false;
|
|
160
160
|
}
|
|
161
|
-
if (
|
|
161
|
+
if (obj === globalThis) {
|
|
162
162
|
return true;
|
|
163
163
|
}
|
|
164
|
-
if (
|
|
164
|
+
if (obj === window) {
|
|
165
165
|
return true;
|
|
166
166
|
}
|
|
167
|
-
if (
|
|
167
|
+
if (obj === self) {
|
|
168
168
|
return true;
|
|
169
169
|
}
|
|
170
|
-
if (
|
|
170
|
+
if (obj === globalThis) {
|
|
171
171
|
return true;
|
|
172
172
|
}
|
|
173
|
-
if (
|
|
173
|
+
if (obj === window) {
|
|
174
174
|
return true;
|
|
175
175
|
}
|
|
176
|
-
if (
|
|
176
|
+
if (obj === self) {
|
|
177
177
|
return true;
|
|
178
178
|
}
|
|
179
|
-
if (typeof unsafeWindow !== "undefined" &&
|
|
179
|
+
if (typeof unsafeWindow !== "undefined" && obj === unsafeWindow) {
|
|
180
180
|
return true;
|
|
181
181
|
}
|
|
182
|
-
if (
|
|
182
|
+
if (obj?.Math?.toString() !== "[object Math]") {
|
|
183
183
|
return false;
|
|
184
184
|
}
|
|
185
185
|
return true;
|
|
@@ -199,23 +199,23 @@ var DOMUtils = (function () {
|
|
|
199
199
|
},
|
|
200
200
|
/**
|
|
201
201
|
* 删除对象上的属性
|
|
202
|
-
* @param
|
|
202
|
+
* @param obj
|
|
203
203
|
* @param propName
|
|
204
204
|
*/
|
|
205
|
-
delete(
|
|
205
|
+
delete(obj, propName) {
|
|
206
206
|
if (typeof Reflect === "object" && Reflect != null && Reflect.deleteProperty) {
|
|
207
|
-
return Reflect.deleteProperty(
|
|
207
|
+
return Reflect.deleteProperty(obj, propName);
|
|
208
208
|
}
|
|
209
209
|
else {
|
|
210
|
-
delete
|
|
210
|
+
delete obj[propName];
|
|
211
211
|
}
|
|
212
212
|
},
|
|
213
213
|
/**
|
|
214
214
|
* 判断是否是元素列表
|
|
215
|
-
* @param $
|
|
215
|
+
* @param $el
|
|
216
216
|
*/
|
|
217
|
-
isNodeList($
|
|
218
|
-
return Array.isArray($
|
|
217
|
+
isNodeList($el) {
|
|
218
|
+
return Array.isArray($el) || $el instanceof NodeList;
|
|
219
219
|
},
|
|
220
220
|
/** 获取 animationend 在各个浏览器的兼容名 */
|
|
221
221
|
getAnimationEndNameList() {
|
|
@@ -1357,6 +1357,7 @@ var DOMUtils = (function () {
|
|
|
1357
1357
|
const OriginPrototype = {
|
|
1358
1358
|
Object: {
|
|
1359
1359
|
defineProperty: Object.defineProperty,
|
|
1360
|
+
defineProperties: Object.defineProperties,
|
|
1360
1361
|
},
|
|
1361
1362
|
};
|
|
1362
1363
|
|
|
@@ -1392,20 +1393,12 @@ var DOMUtils = (function () {
|
|
|
1392
1393
|
option.passive = args[startIndex + 2];
|
|
1393
1394
|
}
|
|
1394
1395
|
}
|
|
1395
|
-
else if (currentParam &&
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
"overrideTarget" in currentParam ||
|
|
1402
|
-
"isPreventEvent" in currentParam)) {
|
|
1403
|
-
option.capture = currentParam.capture;
|
|
1404
|
-
option.once = currentParam.once;
|
|
1405
|
-
option.passive = currentParam.passive;
|
|
1406
|
-
option.isComposedPath = currentParam.isComposedPath;
|
|
1407
|
-
option.overrideTarget = currentParam.overrideTarget;
|
|
1408
|
-
option.isPreventEvent = currentParam.isPreventEvent;
|
|
1396
|
+
else if (currentParam && typeof currentParam === "object") {
|
|
1397
|
+
for (const key in option) {
|
|
1398
|
+
if (Reflect.has(currentParam, key)) {
|
|
1399
|
+
Reflect.set(option, key, currentParam[key]);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1409
1402
|
}
|
|
1410
1403
|
return option;
|
|
1411
1404
|
};
|
|
@@ -1525,16 +1518,16 @@ var DOMUtils = (function () {
|
|
|
1525
1518
|
// 这里尝试使用defineProperty修改event的target值
|
|
1526
1519
|
try {
|
|
1527
1520
|
const originTarget = event.target;
|
|
1528
|
-
OriginPrototype.Object.
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1521
|
+
OriginPrototype.Object.defineProperties(event, {
|
|
1522
|
+
target: {
|
|
1523
|
+
get() {
|
|
1524
|
+
return $target;
|
|
1525
|
+
},
|
|
1532
1526
|
},
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
return originTarget;
|
|
1527
|
+
originTarget: {
|
|
1528
|
+
get() {
|
|
1529
|
+
return originTarget;
|
|
1530
|
+
},
|
|
1538
1531
|
},
|
|
1539
1532
|
});
|
|
1540
1533
|
// oxlint-disable-next-line no-empty
|
|
@@ -1606,10 +1599,7 @@ var DOMUtils = (function () {
|
|
|
1606
1599
|
if (typeof currentParam === "boolean") {
|
|
1607
1600
|
option.capture = currentParam;
|
|
1608
1601
|
}
|
|
1609
|
-
else if (currentParam &&
|
|
1610
|
-
typeof currentParam === "object" &&
|
|
1611
|
-
currentParam != null &&
|
|
1612
|
-
"capture" in currentParam) {
|
|
1602
|
+
else if (currentParam && typeof currentParam === "object" && "capture" in currentParam) {
|
|
1613
1603
|
option.capture = currentParam.capture;
|
|
1614
1604
|
}
|
|
1615
1605
|
return option;
|
|
@@ -3324,7 +3314,7 @@ var DOMUtils = (function () {
|
|
|
3324
3314
|
handler($el, $fragment);
|
|
3325
3315
|
}
|
|
3326
3316
|
/**
|
|
3327
|
-
*
|
|
3317
|
+
* 移除元素(包括它和内部使用.on添加的监听事件)
|
|
3328
3318
|
* @param $el 目标元素,可以是数组、单个元素、NodeList、元素选择器
|
|
3329
3319
|
* @example
|
|
3330
3320
|
* DOMUtils.remove(document.querySelector("a.xx"))
|
|
@@ -3333,19 +3323,23 @@ var DOMUtils = (function () {
|
|
|
3333
3323
|
* DOMUtils.remove([a.xxx, div.xxx, span.xxx])
|
|
3334
3324
|
* */
|
|
3335
3325
|
remove($el) {
|
|
3336
|
-
const that = this;
|
|
3337
3326
|
if (typeof $el === "string") {
|
|
3338
|
-
$el =
|
|
3327
|
+
$el = this.selectorAll($el);
|
|
3339
3328
|
}
|
|
3340
3329
|
if ($el == null) {
|
|
3341
3330
|
return;
|
|
3342
3331
|
}
|
|
3343
3332
|
if (CommonUtils.isNodeList($el)) {
|
|
3344
3333
|
$el.forEach(($elItem) => {
|
|
3345
|
-
|
|
3334
|
+
this.remove($elItem);
|
|
3346
3335
|
});
|
|
3347
3336
|
return;
|
|
3348
3337
|
}
|
|
3338
|
+
// 移除事件
|
|
3339
|
+
$el.querySelectorAll("*").forEach(($elItem) => {
|
|
3340
|
+
this.offAll($elItem);
|
|
3341
|
+
});
|
|
3342
|
+
this.offAll($el);
|
|
3349
3343
|
if (typeof $el.remove === "function") {
|
|
3350
3344
|
$el.remove();
|
|
3351
3345
|
}
|
|
@@ -3380,7 +3374,7 @@ var DOMUtils = (function () {
|
|
|
3380
3374
|
return;
|
|
3381
3375
|
}
|
|
3382
3376
|
if ($el.innerHTML) {
|
|
3383
|
-
$el
|
|
3377
|
+
CommonUtils.setSafeHTML($el, "");
|
|
3384
3378
|
}
|
|
3385
3379
|
else if ($el.textContent) {
|
|
3386
3380
|
$el.textContent = "";
|
|
@@ -3578,7 +3572,7 @@ var DOMUtils = (function () {
|
|
|
3578
3572
|
}
|
|
3579
3573
|
else {
|
|
3580
3574
|
that.after($el, $newEl);
|
|
3581
|
-
|
|
3575
|
+
this.remove($el);
|
|
3582
3576
|
}
|
|
3583
3577
|
}
|
|
3584
3578
|
/**
|