@whitesev/domutils 1.5.1 → 1.5.3
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 +28 -37
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +28 -37
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +28 -37
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +28 -37
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +28 -37
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +28 -37
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/DOMUtils.ts +21 -20
- package/src/DOMUtilsEvent.ts +9 -6
package/package.json
CHANGED
package/src/DOMUtils.ts
CHANGED
|
@@ -20,7 +20,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
20
20
|
super(option);
|
|
21
21
|
}
|
|
22
22
|
/** 版本号 */
|
|
23
|
-
version = "2025.
|
|
23
|
+
version = "2025.4.23";
|
|
24
24
|
/**
|
|
25
25
|
* 获取元素的属性值
|
|
26
26
|
* @param element 目标元素
|
|
@@ -280,36 +280,37 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
280
280
|
}
|
|
281
281
|
return;
|
|
282
282
|
}
|
|
283
|
+
let setStyleProperty = (
|
|
284
|
+
propertyName: string,
|
|
285
|
+
propertyValue: string | number
|
|
286
|
+
) => {
|
|
287
|
+
if (propertyValue === "string" && propertyValue.includes("!important")) {
|
|
288
|
+
propertyValue = propertyValue
|
|
289
|
+
.trim()
|
|
290
|
+
.replace(/!important$/gi, "")
|
|
291
|
+
.trim();
|
|
292
|
+
element.style.setProperty(propertyName, propertyValue, "important");
|
|
293
|
+
} else {
|
|
294
|
+
propertyValue = handlePixe(propertyName, propertyValue);
|
|
295
|
+
element.style.setProperty(propertyName, propertyValue);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
283
298
|
if (typeof property === "string") {
|
|
284
299
|
if (value == null) {
|
|
285
300
|
return DOMUtilsContext.windowApi.globalThis
|
|
286
301
|
.getComputedStyle(element)
|
|
287
302
|
.getPropertyValue(property);
|
|
288
303
|
} else {
|
|
289
|
-
|
|
290
|
-
element.style.setProperty(property, value, "important");
|
|
291
|
-
} else {
|
|
292
|
-
value = handlePixe(property, value);
|
|
293
|
-
element.style.setProperty(property, value);
|
|
294
|
-
}
|
|
304
|
+
setStyleProperty(property, value);
|
|
295
305
|
}
|
|
296
306
|
} else if (typeof property === "object") {
|
|
297
307
|
for (let prop in property) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
(property[prop] as string).includes("!important")
|
|
301
|
-
) {
|
|
302
|
-
element.style.setProperty(
|
|
303
|
-
prop,
|
|
304
|
-
property[prop] as string,
|
|
305
|
-
"important"
|
|
306
|
-
);
|
|
307
|
-
} else {
|
|
308
|
-
property[prop] = handlePixe(prop, property[prop] as string);
|
|
309
|
-
element.style.setProperty(prop, property[prop] as string);
|
|
310
|
-
}
|
|
308
|
+
let value = property[prop];
|
|
309
|
+
setStyleProperty(prop, value!);
|
|
311
310
|
}
|
|
312
311
|
} else {
|
|
312
|
+
// 其他情况
|
|
313
|
+
throw new TypeError("property must be string or object");
|
|
313
314
|
}
|
|
314
315
|
}
|
|
315
316
|
/**
|
package/src/DOMUtilsEvent.ts
CHANGED
|
@@ -271,19 +271,22 @@ export class DOMUtilsEvent {
|
|
|
271
271
|
let eventTarget = listenerOption.isComposedPath
|
|
272
272
|
? (event.composedPath()[0] as HTMLElement)
|
|
273
273
|
: (event.target as HTMLElement);
|
|
274
|
-
let totalParent =
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
let totalParent =
|
|
275
|
+
DOMUtilsCommonUtils.isWin(elementItem) ||
|
|
276
|
+
// @ts-ignore
|
|
277
|
+
elementItem === DOMUtilsContext.windowApi.document
|
|
278
|
+
? DOMUtilsContext.windowApi.document.documentElement
|
|
279
|
+
: elementItem;
|
|
277
280
|
let findValue = selectorList.find((selectorItem) => {
|
|
278
281
|
// 判断目标元素是否匹配选择器
|
|
279
|
-
if (eventTarget
|
|
282
|
+
if (eventTarget?.matches(selectorItem)) {
|
|
280
283
|
/* 当前目标可以被selector所匹配到 */
|
|
281
284
|
return true;
|
|
282
285
|
}
|
|
283
286
|
/* 在上层与主元素之间寻找可以被selector所匹配到的 */
|
|
284
287
|
let $closestMatches =
|
|
285
|
-
eventTarget
|
|
286
|
-
if ($closestMatches && totalParent
|
|
288
|
+
eventTarget?.closest<HTMLElement>(selectorItem);
|
|
289
|
+
if ($closestMatches && totalParent?.contains($closestMatches)) {
|
|
287
290
|
eventTarget = $closestMatches;
|
|
288
291
|
return true;
|
|
289
292
|
}
|