@whitesev/domutils 1.4.8 → 1.5.0
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 +42 -9
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +42 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +42 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +42 -9
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +42 -9
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +42 -9
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/DOMUtilsCommonUtils.d.ts +6 -0
- package/dist/types/src/types/DOMUtilsEvent.d.ts +1 -0
- package/package.json +1 -1
- package/src/DOMUtils.ts +15 -7
- package/src/DOMUtilsCommonUtils.ts +22 -0
- package/src/types/DOMUtilsEvent.d.ts +1 -0
package/dist/index.system.js
CHANGED
|
@@ -60,6 +60,30 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
60
60
|
isShow(element) {
|
|
61
61
|
return Boolean(element.getClientRects().length);
|
|
62
62
|
},
|
|
63
|
+
/**
|
|
64
|
+
* 在CSP策略下设置innerHTML
|
|
65
|
+
* @param $el 元素
|
|
66
|
+
* @param text 文本
|
|
67
|
+
*/
|
|
68
|
+
setSafeHTML($el, text) {
|
|
69
|
+
// 创建 TrustedHTML 策略(需 CSP 允许)
|
|
70
|
+
try {
|
|
71
|
+
$el.innerHTML = text;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
if (globalThis.trustedTypes) {
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
const policy = globalThis.trustedTypes.createPolicy("safe-innerHTML", {
|
|
78
|
+
createHTML: (html) => html,
|
|
79
|
+
});
|
|
80
|
+
$el.innerHTML = policy.createHTML(text);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
throw new Error("trustedTypes is not defined");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
63
87
|
/**
|
|
64
88
|
* 用于显示元素并获取它的高度宽度等其它属性
|
|
65
89
|
* @param element
|
|
@@ -1038,7 +1062,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1038
1062
|
super(option);
|
|
1039
1063
|
}
|
|
1040
1064
|
/** 版本号 */
|
|
1041
|
-
version = "
|
|
1065
|
+
version = "2025.3.2";
|
|
1042
1066
|
attr(element, attrName, attrValue) {
|
|
1043
1067
|
let DOMUtilsContext = this;
|
|
1044
1068
|
if (typeof element === "string") {
|
|
@@ -1095,7 +1119,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1095
1119
|
let DOMUtilsContext = this;
|
|
1096
1120
|
let tempElement = DOMUtilsContext.windowApi.document.createElement(tagName);
|
|
1097
1121
|
if (typeof property === "string") {
|
|
1098
|
-
tempElement
|
|
1122
|
+
DOMUtilsContext.html(tempElement, property);
|
|
1099
1123
|
return tempElement;
|
|
1100
1124
|
}
|
|
1101
1125
|
if (property == null) {
|
|
@@ -1106,6 +1130,10 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1106
1130
|
}
|
|
1107
1131
|
Object.keys(property).forEach((key) => {
|
|
1108
1132
|
let value = property[key];
|
|
1133
|
+
if (key === "innerHTML") {
|
|
1134
|
+
DOMUtilsContext.html(tempElement, value);
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1109
1137
|
tempElement[key] = value;
|
|
1110
1138
|
});
|
|
1111
1139
|
Object.keys(attributes).forEach((key) => {
|
|
@@ -1274,7 +1302,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1274
1302
|
html = html.innerHTML;
|
|
1275
1303
|
}
|
|
1276
1304
|
if ("innerHTML" in element) {
|
|
1277
|
-
element
|
|
1305
|
+
DOMUtilsCommonUtils.setSafeHTML(element, html);
|
|
1278
1306
|
}
|
|
1279
1307
|
}
|
|
1280
1308
|
}
|
|
@@ -1380,7 +1408,12 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1380
1408
|
return Reflect.get(element, propName);
|
|
1381
1409
|
}
|
|
1382
1410
|
else {
|
|
1383
|
-
|
|
1411
|
+
if (element instanceof Element && propName === "innerHTML") {
|
|
1412
|
+
DOMUtilsContext.html(element, propValue);
|
|
1413
|
+
}
|
|
1414
|
+
else {
|
|
1415
|
+
Reflect.set(element, propName, propValue);
|
|
1416
|
+
}
|
|
1384
1417
|
}
|
|
1385
1418
|
}
|
|
1386
1419
|
/**
|
|
@@ -1778,7 +1811,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1778
1811
|
});
|
|
1779
1812
|
return;
|
|
1780
1813
|
}
|
|
1781
|
-
element
|
|
1814
|
+
DOMUtilsContext.html(element, "");
|
|
1782
1815
|
}
|
|
1783
1816
|
/**
|
|
1784
1817
|
* 获取元素相对于文档的偏移坐标(加上文档的滚动条)
|
|
@@ -1988,10 +2021,10 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1988
2021
|
if (typeof duration !== "number" || duration <= 0) {
|
|
1989
2022
|
throw new TypeError("duration must be a positive number");
|
|
1990
2023
|
}
|
|
1991
|
-
if (typeof callback !== "function" && callback !==
|
|
2024
|
+
if (typeof callback !== "function" && callback !== undefined) {
|
|
1992
2025
|
throw new TypeError("callback must be a function or null");
|
|
1993
2026
|
}
|
|
1994
|
-
if (typeof styles !== "object" || styles ===
|
|
2027
|
+
if (typeof styles !== "object" || styles === undefined) {
|
|
1995
2028
|
throw new TypeError("styles must be an object");
|
|
1996
2029
|
}
|
|
1997
2030
|
if (Object.keys(styles).length === 0) {
|
|
@@ -2050,7 +2083,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2050
2083
|
element = element;
|
|
2051
2084
|
// 创建一个新的div元素,并将wrapperHTML作为其innerHTML
|
|
2052
2085
|
let wrapper = DOMUtilsContext.windowApi.document.createElement("div");
|
|
2053
|
-
wrapper
|
|
2086
|
+
DOMUtilsContext.html(wrapper, wrapperHTML);
|
|
2054
2087
|
let wrapperFirstChild = wrapper.firstChild;
|
|
2055
2088
|
// 将要包裹的元素插入目标元素前面
|
|
2056
2089
|
let parentElement = element.parentElement;
|
|
@@ -2146,7 +2179,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2146
2179
|
}
|
|
2147
2180
|
function parseHTMLByCreateDom() {
|
|
2148
2181
|
let tempDIV = DOMUtilsContext.windowApi.document.createElement("div");
|
|
2149
|
-
tempDIV
|
|
2182
|
+
DOMUtilsContext.html(tempDIV, html);
|
|
2150
2183
|
if (isComplete) {
|
|
2151
2184
|
return tempDIV;
|
|
2152
2185
|
}
|