@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.system.js
CHANGED
|
@@ -60,6 +60,22 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
60
60
|
isShow(element) {
|
|
61
61
|
return Boolean(element.getClientRects().length);
|
|
62
62
|
},
|
|
63
|
+
/**
|
|
64
|
+
* 获取安全的html
|
|
65
|
+
*/
|
|
66
|
+
getSafeHTML(text) {
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
if (globalThis.trustedTypes) {
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
const policy = globalThis.trustedTypes.createPolicy("safe-innerHTML", {
|
|
71
|
+
createHTML: (html) => html,
|
|
72
|
+
});
|
|
73
|
+
return policy.createHTML(text);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
return text;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
63
79
|
/**
|
|
64
80
|
* 在CSP策略下设置innerHTML
|
|
65
81
|
* @param $el 元素
|
|
@@ -1629,7 +1645,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1629
1645
|
}
|
|
1630
1646
|
function elementAppendChild(ele, text) {
|
|
1631
1647
|
if (typeof content === "string") {
|
|
1632
|
-
ele.insertAdjacentHTML("beforeend", text);
|
|
1648
|
+
ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text));
|
|
1633
1649
|
}
|
|
1634
1650
|
else {
|
|
1635
1651
|
ele.appendChild(text);
|
|
@@ -1675,7 +1691,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1675
1691
|
return;
|
|
1676
1692
|
}
|
|
1677
1693
|
if (typeof content === "string") {
|
|
1678
|
-
element.insertAdjacentHTML("afterbegin", content);
|
|
1694
|
+
element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
1679
1695
|
}
|
|
1680
1696
|
else {
|
|
1681
1697
|
let $firstChild = element.firstChild;
|
|
@@ -1712,7 +1728,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1712
1728
|
return;
|
|
1713
1729
|
}
|
|
1714
1730
|
if (typeof content === "string") {
|
|
1715
|
-
element.insertAdjacentHTML("afterend", content);
|
|
1731
|
+
element.insertAdjacentHTML("afterend", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
1716
1732
|
}
|
|
1717
1733
|
else {
|
|
1718
1734
|
let $parent = element.parentElement;
|
|
@@ -1751,7 +1767,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1751
1767
|
return;
|
|
1752
1768
|
}
|
|
1753
1769
|
if (typeof content === "string") {
|
|
1754
|
-
element.insertAdjacentHTML("beforebegin", content);
|
|
1770
|
+
element.insertAdjacentHTML("beforebegin", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
1755
1771
|
}
|
|
1756
1772
|
else {
|
|
1757
1773
|
let $parent = element.parentElement;
|