@whitesev/domutils 1.5.0 → 1.5.1
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 +20 -4
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +20 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +20 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +20 -4
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +20 -4
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +20 -4
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/DOMUtilsCommonUtils.d.ts +4 -0
- package/package.json +1 -1
- package/src/DOMUtils.ts +16 -4
- package/src/DOMUtilsCommonUtils.ts +16 -14
package/dist/index.iife.js
CHANGED
|
@@ -58,6 +58,22 @@ var DOMUtils = (function () {
|
|
|
58
58
|
isShow(element) {
|
|
59
59
|
return Boolean(element.getClientRects().length);
|
|
60
60
|
},
|
|
61
|
+
/**
|
|
62
|
+
* 获取安全的html
|
|
63
|
+
*/
|
|
64
|
+
getSafeHTML(text) {
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
if (globalThis.trustedTypes) {
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
const policy = globalThis.trustedTypes.createPolicy("safe-innerHTML", {
|
|
69
|
+
createHTML: (html) => html,
|
|
70
|
+
});
|
|
71
|
+
return policy.createHTML(text);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return text;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
61
77
|
/**
|
|
62
78
|
* 在CSP策略下设置innerHTML
|
|
63
79
|
* @param $el 元素
|
|
@@ -1627,7 +1643,7 @@ var DOMUtils = (function () {
|
|
|
1627
1643
|
}
|
|
1628
1644
|
function elementAppendChild(ele, text) {
|
|
1629
1645
|
if (typeof content === "string") {
|
|
1630
|
-
ele.insertAdjacentHTML("beforeend", text);
|
|
1646
|
+
ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text));
|
|
1631
1647
|
}
|
|
1632
1648
|
else {
|
|
1633
1649
|
ele.appendChild(text);
|
|
@@ -1673,7 +1689,7 @@ var DOMUtils = (function () {
|
|
|
1673
1689
|
return;
|
|
1674
1690
|
}
|
|
1675
1691
|
if (typeof content === "string") {
|
|
1676
|
-
element.insertAdjacentHTML("afterbegin", content);
|
|
1692
|
+
element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
1677
1693
|
}
|
|
1678
1694
|
else {
|
|
1679
1695
|
let $firstChild = element.firstChild;
|
|
@@ -1710,7 +1726,7 @@ var DOMUtils = (function () {
|
|
|
1710
1726
|
return;
|
|
1711
1727
|
}
|
|
1712
1728
|
if (typeof content === "string") {
|
|
1713
|
-
element.insertAdjacentHTML("afterend", content);
|
|
1729
|
+
element.insertAdjacentHTML("afterend", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
1714
1730
|
}
|
|
1715
1731
|
else {
|
|
1716
1732
|
let $parent = element.parentElement;
|
|
@@ -1749,7 +1765,7 @@ var DOMUtils = (function () {
|
|
|
1749
1765
|
return;
|
|
1750
1766
|
}
|
|
1751
1767
|
if (typeof content === "string") {
|
|
1752
|
-
element.insertAdjacentHTML("beforebegin", content);
|
|
1768
|
+
element.insertAdjacentHTML("beforebegin", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
1753
1769
|
}
|
|
1754
1770
|
else {
|
|
1755
1771
|
let $parent = element.parentElement;
|