@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.cjs.js
CHANGED
|
@@ -57,6 +57,22 @@ const DOMUtilsCommonUtils = {
|
|
|
57
57
|
isShow(element) {
|
|
58
58
|
return Boolean(element.getClientRects().length);
|
|
59
59
|
},
|
|
60
|
+
/**
|
|
61
|
+
* 获取安全的html
|
|
62
|
+
*/
|
|
63
|
+
getSafeHTML(text) {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
if (globalThis.trustedTypes) {
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
const policy = globalThis.trustedTypes.createPolicy("safe-innerHTML", {
|
|
68
|
+
createHTML: (html) => html,
|
|
69
|
+
});
|
|
70
|
+
return policy.createHTML(text);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return text;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
60
76
|
/**
|
|
61
77
|
* 在CSP策略下设置innerHTML
|
|
62
78
|
* @param $el 元素
|
|
@@ -1626,7 +1642,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1626
1642
|
}
|
|
1627
1643
|
function elementAppendChild(ele, text) {
|
|
1628
1644
|
if (typeof content === "string") {
|
|
1629
|
-
ele.insertAdjacentHTML("beforeend", text);
|
|
1645
|
+
ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text));
|
|
1630
1646
|
}
|
|
1631
1647
|
else {
|
|
1632
1648
|
ele.appendChild(text);
|
|
@@ -1672,7 +1688,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1672
1688
|
return;
|
|
1673
1689
|
}
|
|
1674
1690
|
if (typeof content === "string") {
|
|
1675
|
-
element.insertAdjacentHTML("afterbegin", content);
|
|
1691
|
+
element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
1676
1692
|
}
|
|
1677
1693
|
else {
|
|
1678
1694
|
let $firstChild = element.firstChild;
|
|
@@ -1709,7 +1725,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1709
1725
|
return;
|
|
1710
1726
|
}
|
|
1711
1727
|
if (typeof content === "string") {
|
|
1712
|
-
element.insertAdjacentHTML("afterend", content);
|
|
1728
|
+
element.insertAdjacentHTML("afterend", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
1713
1729
|
}
|
|
1714
1730
|
else {
|
|
1715
1731
|
let $parent = element.parentElement;
|
|
@@ -1748,7 +1764,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1748
1764
|
return;
|
|
1749
1765
|
}
|
|
1750
1766
|
if (typeof content === "string") {
|
|
1751
|
-
element.insertAdjacentHTML("beforebegin", content);
|
|
1767
|
+
element.insertAdjacentHTML("beforebegin", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
1752
1768
|
}
|
|
1753
1769
|
else {
|
|
1754
1770
|
let $parent = element.parentElement;
|