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