@baloise/ds-core 19.10.0 → 19.10.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.
Files changed (131) hide show
  1. package/components/index.js +1 -1
  2. package/components/svg.js +2231 -1593
  3. package/components/tokens.esm.js +1 -1
  4. package/dist/baloise-design-system/baloise-design-system.esm.js +1 -1
  5. package/dist/baloise-design-system/index.esm.js +1 -1
  6. package/dist/baloise-design-system/p--_h4j4q-.js +1 -1
  7. package/dist/baloise-design-system/{p-79d0e94ea1.entry.js → p-0cc81e6629.entry.js} +1 -1
  8. package/dist/baloise-design-system/{p-570ca4dd95.entry.js → p-0ff7f61cfb.entry.js} +1 -1
  9. package/dist/baloise-design-system/{p-397dc857c9.system.entry.js → p-1499fb8b1e.system.entry.js} +1 -1
  10. package/dist/baloise-design-system/{p-cc7d7244d4.system.entry.js → p-1a6ba1626a.system.entry.js} +1 -1
  11. package/dist/baloise-design-system/{p-bb93e69ae9.entry.js → p-208cbbcb1d.entry.js} +1 -1
  12. package/dist/baloise-design-system/{p-bf78d931bc.entry.js → p-24ccaeba21.entry.js} +1 -1
  13. package/dist/baloise-design-system/{p-fc8024a9d7.system.entry.js → p-31175f4af8.system.entry.js} +1 -1
  14. package/dist/baloise-design-system/{p-25fa360aac.system.entry.js → p-3376a1e651.system.entry.js} +1 -1
  15. package/dist/baloise-design-system/{p-02323ca1fe.entry.js → p-429bb32975.entry.js} +1 -1
  16. package/dist/baloise-design-system/{p-7d92171abe.system.entry.js → p-42d463fd3f.system.entry.js} +1 -1
  17. package/dist/baloise-design-system/{p-74b3b2823e.entry.js → p-52f625a5f7.entry.js} +1 -1
  18. package/dist/baloise-design-system/{p-50d92b35e8.system.entry.js → p-609d2320b1.system.entry.js} +1 -1
  19. package/dist/baloise-design-system/{p-d1f78ecd06.system.entry.js → p-64e141077d.system.entry.js} +1 -1
  20. package/dist/baloise-design-system/{p-0f7a033d37.system.entry.js → p-6fc739276a.system.entry.js} +1 -1
  21. package/dist/baloise-design-system/p-88ea8830b6.system.entry.js +1 -0
  22. package/dist/baloise-design-system/{p-9bed3124ac.system.entry.js → p-8927f351fd.system.entry.js} +1 -1
  23. package/dist/baloise-design-system/p-91a2e98786.entry.js +1 -0
  24. package/dist/baloise-design-system/{p-6a6bf23b35.entry.js → p-9be648ffe8.entry.js} +1 -1
  25. package/dist/baloise-design-system/{p-f561dde601.entry.js → p-9dfd29490a.entry.js} +1 -1
  26. package/dist/baloise-design-system/p-BTgSDGRr.js +2 -0
  27. package/dist/baloise-design-system/{p-DAzKMk4j.system.js → p-Bo8qDNOG.system.js} +1 -1
  28. package/dist/baloise-design-system/{p-DoUUOEu5.js → p-BqpLZmeG.js} +1 -1
  29. package/dist/baloise-design-system/{p-D8DleYVA.system.js → p-CFjc7N6P.system.js} +1 -1
  30. package/dist/baloise-design-system/{p-D49COBvb.js → p-CTkFlT9_.js} +1 -1
  31. package/dist/baloise-design-system/p-CUqH3xVz.js +1 -0
  32. package/dist/baloise-design-system/p-CVYynfS9.system.js +3 -0
  33. package/dist/baloise-design-system/p-CrCMAe2F.system.js +1 -1
  34. package/dist/baloise-design-system/{p-254FFVWk.system.js → p-CyZzYmE8.system.js} +1 -1
  35. package/dist/baloise-design-system/p-DeyNn-78.system.js +1 -1
  36. package/dist/baloise-design-system/{p-d6a6080859.entry.js → p-a117ce237f.entry.js} +1 -1
  37. package/dist/baloise-design-system/p-b0b968a148.system.entry.js +1 -0
  38. package/dist/baloise-design-system/{p-6042b3dd87.entry.js → p-ba76da9a32.entry.js} +1 -1
  39. package/dist/baloise-design-system/p-cd15fc8c69.entry.js +1 -0
  40. package/dist/baloise-design-system/{p-7e386c7e4f.system.entry.js → p-daf87a6be6.system.entry.js} +1 -1
  41. package/dist/baloise-design-system/{p-70f197258a.entry.js → p-dcd76bb03e.entry.js} +1 -1
  42. package/dist/baloise-design-system/{p-d41ca5c096.system.entry.js → p-eb1125dab4.system.entry.js} +1 -1
  43. package/dist/baloise-design-system/{p-d4416edc00.entry.js → p-ebfcd6a4b0.entry.js} +1 -1
  44. package/dist/baloise-design-system/{p-180d40dfcf.entry.js → p-efc57cd356.entry.js} +1 -1
  45. package/dist/baloise-design-system/{p-2f1467650a.system.entry.js → p-f3199b24c8.system.entry.js} +1 -1
  46. package/dist/baloise-design-system/{p-36be7b65c2.system.entry.js → p-fac5fa4bcc.system.entry.js} +1 -1
  47. package/dist/baloise-design-system/{p-BBexhGst.system.js → p-tkZtpw7B.system.js} +1 -1
  48. package/dist/cjs/bal-carousel_2.cjs.entry.js +4 -5
  49. package/dist/cjs/bal-field_5.cjs.entry.js +3 -3
  50. package/dist/cjs/bal-footer.cjs.entry.js +1 -1
  51. package/dist/cjs/bal-hint_5.cjs.entry.js +3 -3
  52. package/dist/cjs/bal-icon.cjs.entry.js +1 -1
  53. package/dist/cjs/bal-list_8.cjs.entry.js +3 -3
  54. package/dist/cjs/bal-logo.cjs.entry.js +3 -3
  55. package/dist/cjs/bal-nav_8.cjs.entry.js +4 -5
  56. package/dist/cjs/bal-navbar_5.cjs.entry.js +3 -3
  57. package/dist/cjs/bal-pagination.cjs.entry.js +3 -3
  58. package/dist/cjs/bal-progress-bar.cjs.entry.js +4 -4
  59. package/dist/cjs/bal-segment_2.cjs.entry.js +4 -4
  60. package/dist/cjs/bal-shape.cjs.entry.js +1 -1
  61. package/dist/cjs/bal-steps.cjs.entry.js +3 -3
  62. package/dist/cjs/bal-tab-item_2.cjs.entry.js +3 -3
  63. package/dist/cjs/{breakpoints.decorator-C7C_2t01.js → breakpoints.decorator-Dh3Bo-Yu.js} +1 -1
  64. package/dist/cjs/{breakpoints.subject-CXJYXMpo.js → breakpoints.subject-CzZMSmUO.js} +1 -1
  65. package/dist/cjs/index.cjs.js +2 -2
  66. package/dist/cjs/initialize-7J6n8lOv.js +1 -1
  67. package/dist/cjs/svg-DqzoyBUW.js +2245 -0
  68. package/dist/cjs/{tokens.esm-wVc8fBNC.js → tokens.esm-DI0zgU1M.js} +1 -1
  69. package/dist/cjs/{window-resize.decorator-CFAzpxMB.js → window-resize.decorator-CBrnxH3J.js} +1 -1
  70. package/dist/collection/utils/constants/version.constant.js +1 -1
  71. package/dist/esm/bal-carousel_2.entry.js +4 -5
  72. package/dist/esm/bal-field_5.entry.js +3 -3
  73. package/dist/esm/bal-footer.entry.js +1 -1
  74. package/dist/esm/bal-hint_5.entry.js +3 -3
  75. package/dist/esm/bal-icon.entry.js +1 -1
  76. package/dist/esm/bal-list_8.entry.js +3 -3
  77. package/dist/esm/bal-logo.entry.js +3 -3
  78. package/dist/esm/bal-nav_8.entry.js +4 -5
  79. package/dist/esm/bal-navbar_5.entry.js +3 -3
  80. package/dist/esm/bal-pagination.entry.js +3 -3
  81. package/dist/esm/bal-progress-bar.entry.js +4 -4
  82. package/dist/esm/bal-segment_2.entry.js +4 -4
  83. package/dist/esm/bal-shape.entry.js +1 -1
  84. package/dist/esm/bal-steps.entry.js +3 -3
  85. package/dist/esm/bal-tab-item_2.entry.js +3 -3
  86. package/dist/esm/{breakpoints.decorator-Da-lbVYy.js → breakpoints.decorator-BvzrUw7f.js} +1 -1
  87. package/dist/esm/{breakpoints.subject-C32mP6rF.js → breakpoints.subject-BugBexTF.js} +1 -1
  88. package/dist/esm/index.js +3 -3
  89. package/dist/esm/initialize-BS5FhjDS.js +1 -1
  90. package/dist/esm/svg-BTgSDGRr.js +2243 -0
  91. package/dist/esm/{tokens.esm-C22U88Bg.js → tokens.esm-B32RYUT0.js} +1 -1
  92. package/dist/esm/{window-resize.decorator-DSoPWN6q.js → window-resize.decorator-DK5kMpPN.js} +1 -1
  93. package/dist/esm-es5/bal-carousel_2.entry.js +1 -1
  94. package/dist/esm-es5/bal-field_5.entry.js +1 -1
  95. package/dist/esm-es5/bal-footer.entry.js +1 -1
  96. package/dist/esm-es5/bal-hint_5.entry.js +1 -1
  97. package/dist/esm-es5/bal-icon.entry.js +1 -1
  98. package/dist/esm-es5/bal-list_8.entry.js +1 -1
  99. package/dist/esm-es5/bal-logo.entry.js +1 -1
  100. package/dist/esm-es5/bal-nav_8.entry.js +1 -1
  101. package/dist/esm-es5/bal-navbar_5.entry.js +1 -1
  102. package/dist/esm-es5/bal-pagination.entry.js +1 -1
  103. package/dist/esm-es5/bal-progress-bar.entry.js +1 -1
  104. package/dist/esm-es5/bal-segment_2.entry.js +1 -1
  105. package/dist/esm-es5/bal-shape.entry.js +1 -1
  106. package/dist/esm-es5/bal-steps.entry.js +1 -1
  107. package/dist/esm-es5/bal-tab-item_2.entry.js +1 -1
  108. package/dist/esm-es5/breakpoints.decorator-BvzrUw7f.js +1 -0
  109. package/dist/esm-es5/{breakpoints.subject-C32mP6rF.js → breakpoints.subject-BugBexTF.js} +1 -1
  110. package/dist/esm-es5/index.js +1 -1
  111. package/dist/esm-es5/initialize-BS5FhjDS.js +1 -1
  112. package/dist/esm-es5/svg-BTgSDGRr.js +2 -0
  113. package/dist/esm-es5/{window-resize.decorator-DSoPWN6q.js → window-resize.decorator-DK5kMpPN.js} +1 -1
  114. package/dist/types/utils/mask/__test__/mask-component.mock.d.ts +6 -6
  115. package/dist/types/utils/mask/__test__/mask.mock.d.ts +9 -9
  116. package/dist/types/utils/svg.d.ts +1 -1
  117. package/package.json +7 -10
  118. package/dist/baloise-design-system/p-77c8017da1.system.entry.js +0 -1
  119. package/dist/baloise-design-system/p-909e9da161.entry.js +0 -1
  120. package/dist/baloise-design-system/p-CGYi6koW.js +0 -1
  121. package/dist/baloise-design-system/p-Ck7YRry-.system.js +0 -2
  122. package/dist/baloise-design-system/p-DojUs2K8.js +0 -2
  123. package/dist/baloise-design-system/p-a3e46a8705.system.entry.js +0 -1
  124. package/dist/baloise-design-system/p-a5a17d36fd.entry.js +0 -1
  125. package/dist/cjs/svg-qEvvK3mS.js +0 -1607
  126. package/dist/esm/svg-DhNz-XmR.js +0 -1605
  127. package/dist/esm-es5/breakpoints.decorator-Da-lbVYy.js +0 -1
  128. package/dist/esm-es5/svg-DhNz-XmR.js +0 -2
  129. /package/dist/baloise-design-system/{p-C22U88Bg.js → p-B32RYUT0.js} +0 -0
  130. /package/dist/baloise-design-system/{p-DQy9pRj5.system.js → p-D0HQAsaT.system.js} +0 -0
  131. /package/dist/esm-es5/{tokens.esm-C22U88Bg.js → tokens.esm-B32RYUT0.js} +0 -0
@@ -0,0 +1,2245 @@
1
+ 'use strict';
2
+
3
+ /*! @license DOMPurify 3.4.11 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.11/LICENSE */
4
+
5
+ function _arrayLikeToArray(r, a) {
6
+ (null == a || a > r.length) && (a = r.length);
7
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
8
+ return n;
9
+ }
10
+ function _arrayWithHoles(r) {
11
+ if (Array.isArray(r)) return r;
12
+ }
13
+ function _iterableToArrayLimit(r, l) {
14
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
15
+ if (null != t) {
16
+ var e,
17
+ n,
18
+ i,
19
+ u,
20
+ a = [],
21
+ f = true,
22
+ o = false;
23
+ try {
24
+ if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true);
25
+ } catch (r) {
26
+ o = true, n = r;
27
+ } finally {
28
+ try {
29
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
30
+ } finally {
31
+ if (o) throw n;
32
+ }
33
+ }
34
+ return a;
35
+ }
36
+ }
37
+ function _nonIterableRest() {
38
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
39
+ }
40
+ function _slicedToArray(r, e) {
41
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
42
+ }
43
+ function _unsupportedIterableToArray(r, a) {
44
+ if (r) {
45
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
46
+ var t = {}.toString.call(r).slice(8, -1);
47
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
48
+ }
49
+ }
50
+
51
+ const entries = Object.entries,
52
+ setPrototypeOf = Object.setPrototypeOf,
53
+ isFrozen = Object.isFrozen,
54
+ getPrototypeOf = Object.getPrototypeOf,
55
+ getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
56
+ let freeze = Object.freeze,
57
+ seal = Object.seal,
58
+ create = Object.create; // eslint-disable-line import/no-mutable-exports
59
+ let _ref = typeof Reflect !== 'undefined' && Reflect,
60
+ apply = _ref.apply,
61
+ construct = _ref.construct;
62
+ if (!freeze) {
63
+ freeze = function freeze(x) {
64
+ return x;
65
+ };
66
+ }
67
+ if (!seal) {
68
+ seal = function seal(x) {
69
+ return x;
70
+ };
71
+ }
72
+ if (!apply) {
73
+ apply = function apply(func, thisArg) {
74
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
75
+ args[_key - 2] = arguments[_key];
76
+ }
77
+ return func.apply(thisArg, args);
78
+ };
79
+ }
80
+ if (!construct) {
81
+ construct = function construct(Func) {
82
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
83
+ args[_key2 - 1] = arguments[_key2];
84
+ }
85
+ return new Func(...args);
86
+ };
87
+ }
88
+ const arrayForEach = unapply(Array.prototype.forEach);
89
+ const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
90
+ const arrayPop = unapply(Array.prototype.pop);
91
+ const arrayPush = unapply(Array.prototype.push);
92
+ const arraySplice = unapply(Array.prototype.splice);
93
+ const arrayIsArray = Array.isArray;
94
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
95
+ const stringToString = unapply(String.prototype.toString);
96
+ const stringMatch = unapply(String.prototype.match);
97
+ const stringReplace = unapply(String.prototype.replace);
98
+ const stringIndexOf = unapply(String.prototype.indexOf);
99
+ const stringTrim = unapply(String.prototype.trim);
100
+ const numberToString = unapply(Number.prototype.toString);
101
+ const booleanToString = unapply(Boolean.prototype.toString);
102
+ const bigintToString = typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);
103
+ const symbolToString = typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);
104
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
105
+ const objectToString = unapply(Object.prototype.toString);
106
+ const regExpTest = unapply(RegExp.prototype.test);
107
+ const typeErrorCreate = unconstruct(TypeError);
108
+ /**
109
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
110
+ *
111
+ * @param func - The function to be wrapped and called.
112
+ * @returns A new function that calls the given function with a specified thisArg and arguments.
113
+ */
114
+ function unapply(func) {
115
+ return function (thisArg) {
116
+ if (thisArg instanceof RegExp) {
117
+ thisArg.lastIndex = 0;
118
+ }
119
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
120
+ args[_key3 - 1] = arguments[_key3];
121
+ }
122
+ return apply(func, thisArg, args);
123
+ };
124
+ }
125
+ /**
126
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
127
+ *
128
+ * @param func - The constructor function to be wrapped and called.
129
+ * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
130
+ */
131
+ function unconstruct(Func) {
132
+ return function () {
133
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
134
+ args[_key4] = arguments[_key4];
135
+ }
136
+ return construct(Func, args);
137
+ };
138
+ }
139
+ /**
140
+ * Add properties to a lookup table
141
+ *
142
+ * @param set - The set to which elements will be added.
143
+ * @param array - The array containing elements to be added to the set.
144
+ * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
145
+ * @returns The modified set with added elements.
146
+ */
147
+ function addToSet(set, array) {
148
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
149
+ if (setPrototypeOf) {
150
+ // Make 'in' and truthy checks like Boolean(set.constructor)
151
+ // independent of any properties defined on Object.prototype.
152
+ // Prevent prototype setters from intercepting set as a this value.
153
+ setPrototypeOf(set, null);
154
+ }
155
+ if (!arrayIsArray(array)) {
156
+ return set;
157
+ }
158
+ let l = array.length;
159
+ while (l--) {
160
+ let element = array[l];
161
+ if (typeof element === 'string') {
162
+ const lcElement = transformCaseFunc(element);
163
+ if (lcElement !== element) {
164
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
165
+ if (!isFrozen(array)) {
166
+ array[l] = lcElement;
167
+ }
168
+ element = lcElement;
169
+ }
170
+ }
171
+ set[element] = true;
172
+ }
173
+ return set;
174
+ }
175
+ /**
176
+ * Clean up an array to harden against CSPP
177
+ *
178
+ * @param array - The array to be cleaned.
179
+ * @returns The cleaned version of the array
180
+ */
181
+ function cleanArray(array) {
182
+ for (let index = 0; index < array.length; index++) {
183
+ const isPropertyExist = objectHasOwnProperty(array, index);
184
+ if (!isPropertyExist) {
185
+ array[index] = null;
186
+ }
187
+ }
188
+ return array;
189
+ }
190
+ /**
191
+ * Shallow clone an object
192
+ *
193
+ * @param object - The object to be cloned.
194
+ * @returns A new object that copies the original.
195
+ */
196
+ function clone(object) {
197
+ const newObject = create(null);
198
+ for (const _ref2 of entries(object)) {
199
+ var _ref3 = _slicedToArray(_ref2, 2);
200
+ const property = _ref3[0];
201
+ const value = _ref3[1];
202
+ const isPropertyExist = objectHasOwnProperty(object, property);
203
+ if (isPropertyExist) {
204
+ if (arrayIsArray(value)) {
205
+ newObject[property] = cleanArray(value);
206
+ } else if (value && typeof value === 'object' && value.constructor === Object) {
207
+ newObject[property] = clone(value);
208
+ } else {
209
+ newObject[property] = value;
210
+ }
211
+ }
212
+ }
213
+ return newObject;
214
+ }
215
+ /**
216
+ * Convert non-node values into strings without depending on direct property access.
217
+ *
218
+ * @param value - The value to stringify.
219
+ * @returns A string representation of the provided value.
220
+ */
221
+ function stringifyValue(value) {
222
+ switch (typeof value) {
223
+ case 'string':
224
+ {
225
+ return value;
226
+ }
227
+ case 'number':
228
+ {
229
+ return numberToString(value);
230
+ }
231
+ case 'boolean':
232
+ {
233
+ return booleanToString(value);
234
+ }
235
+ case 'bigint':
236
+ {
237
+ return bigintToString ? bigintToString(value) : '0';
238
+ }
239
+ case 'symbol':
240
+ {
241
+ return symbolToString ? symbolToString(value) : 'Symbol()';
242
+ }
243
+ case 'undefined':
244
+ {
245
+ return objectToString(value);
246
+ }
247
+ case 'function':
248
+ case 'object':
249
+ {
250
+ if (value === null) {
251
+ return objectToString(value);
252
+ }
253
+ const valueAsRecord = value;
254
+ const valueToString = lookupGetter(valueAsRecord, 'toString');
255
+ if (typeof valueToString === 'function') {
256
+ const stringified = valueToString(valueAsRecord);
257
+ return typeof stringified === 'string' ? stringified : objectToString(stringified);
258
+ }
259
+ return objectToString(value);
260
+ }
261
+ default:
262
+ {
263
+ return objectToString(value);
264
+ }
265
+ }
266
+ }
267
+ /**
268
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
269
+ *
270
+ * @param object - The object to look up the getter function in its prototype chain.
271
+ * @param prop - The property name for which to find the getter function.
272
+ * @returns The getter function found in the prototype chain or a fallback function.
273
+ */
274
+ function lookupGetter(object, prop) {
275
+ while (object !== null) {
276
+ const desc = getOwnPropertyDescriptor(object, prop);
277
+ if (desc) {
278
+ if (desc.get) {
279
+ return unapply(desc.get);
280
+ }
281
+ if (typeof desc.value === 'function') {
282
+ return unapply(desc.value);
283
+ }
284
+ }
285
+ object = getPrototypeOf(object);
286
+ }
287
+ function fallbackValue() {
288
+ return null;
289
+ }
290
+ return fallbackValue;
291
+ }
292
+ function isRegex(value) {
293
+ try {
294
+ regExpTest(value, '');
295
+ return true;
296
+ } catch (_unused) {
297
+ return false;
298
+ }
299
+ }
300
+
301
+ const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
302
+ const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
303
+ const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
304
+ // List of SVG elements that are disallowed by default.
305
+ // We still need to know them so that we can do namespace
306
+ // checks properly in case one wants to add them to
307
+ // allow-list.
308
+ const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
309
+ const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);
310
+ // Similarly to SVG, we want to know all MathML elements,
311
+ // even those that we disallow by default.
312
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
313
+ const text = freeze(['#text']);
314
+
315
+ const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'command', 'commandfor', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns']);
316
+ const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
317
+ const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnalign', 'columnlines', 'columnspacing', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lquote', 'lspace', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
318
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
319
+
320
+ const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
321
+ const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
322
+ const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
323
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
324
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
325
+ const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
326
+ );
327
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
328
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
329
+ );
330
+ const DOCTYPE_NAME = seal(/^html$/i);
331
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
332
+ // Markup-significant character probes used by _sanitizeElements.
333
+ // Shared module-level instances are safe despite the sticky /g flags:
334
+ // unapply() resets lastIndex for RegExp receivers before every call.
335
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
336
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
337
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
338
+ const SELF_CLOSING_TAG = seal(/\/>/i);
339
+
340
+ // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
341
+ const NODE_TYPE = {
342
+ element: 1,
343
+ text: 3,
344
+ // Deprecated
345
+ processingInstruction: 7,
346
+ comment: 8,
347
+ document: 9,
348
+ documentFragment: 11};
349
+ const getGlobal = function getGlobal() {
350
+ return typeof window === 'undefined' ? null : window;
351
+ };
352
+ /**
353
+ * Creates a no-op policy for internal use only.
354
+ * Don't export this function outside this module!
355
+ * @param trustedTypes The policy factory.
356
+ * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
357
+ * @return The policy created (or null, if Trusted Types
358
+ * are not supported or creating the policy failed).
359
+ */
360
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
361
+ if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
362
+ return null;
363
+ }
364
+ // Allow the callers to control the unique policy name
365
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
366
+ // Policy creation with duplicate names throws in Trusted Types.
367
+ let suffix = null;
368
+ const ATTR_NAME = 'data-tt-policy-suffix';
369
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
370
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
371
+ }
372
+ const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
373
+ try {
374
+ return trustedTypes.createPolicy(policyName, {
375
+ createHTML(html) {
376
+ return html;
377
+ },
378
+ createScriptURL(scriptUrl) {
379
+ return scriptUrl;
380
+ }
381
+ });
382
+ } catch (_) {
383
+ // Policy creation failed (most likely another DOMPurify script has
384
+ // already run). Skip creating the policy, as this will only cause errors
385
+ // if TT are enforced.
386
+ console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
387
+ return null;
388
+ }
389
+ };
390
+ const _createHooksMap = function _createHooksMap() {
391
+ return {
392
+ afterSanitizeAttributes: [],
393
+ afterSanitizeElements: [],
394
+ afterSanitizeShadowDOM: [],
395
+ beforeSanitizeAttributes: [],
396
+ beforeSanitizeElements: [],
397
+ beforeSanitizeShadowDOM: [],
398
+ uponSanitizeAttribute: [],
399
+ uponSanitizeElement: [],
400
+ uponSanitizeShadowNode: []
401
+ };
402
+ };
403
+ /**
404
+ * Resolve a set-valued configuration option: a fresh set built from
405
+ * cfg[key] when it is an own array property (seeded with a clone of
406
+ * options.base when given, case-normalized via options.transform),
407
+ * the fallback set otherwise.
408
+ *
409
+ * @param cfg the cloned, prototype-free configuration object
410
+ * @param key the configuration property to read
411
+ * @param fallback the set to use when the option is absent or not an array
412
+ * @param options transform and optional base set to merge into
413
+ * @returns the resolved set
414
+ */
415
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
416
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
417
+ };
418
+ function createDOMPurify() {
419
+ let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
420
+ const DOMPurify = root => createDOMPurify(root);
421
+ DOMPurify.version = '3.4.11';
422
+ DOMPurify.removed = [];
423
+ if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
424
+ // Not running in a browser, provide a factory function
425
+ // so that you can pass your own Window
426
+ DOMPurify.isSupported = false;
427
+ return DOMPurify;
428
+ }
429
+ let document = window.document;
430
+ const originalDocument = document;
431
+ const currentScript = originalDocument.currentScript;
432
+ const HTMLTemplateElement = window.HTMLTemplateElement,
433
+ Node = window.Node,
434
+ Element = window.Element,
435
+ NodeFilter = window.NodeFilter;
436
+ const DOMParser = window.DOMParser,
437
+ trustedTypes = window.trustedTypes;
438
+ const ElementPrototype = Element.prototype;
439
+ const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
440
+ const remove = lookupGetter(ElementPrototype, 'remove');
441
+ const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
442
+ const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
443
+ const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
444
+ const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
445
+ const getAttributes = lookupGetter(ElementPrototype, 'attributes');
446
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
447
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
448
+ // As per issue #47, the web-components registry is inherited by a
449
+ // new document created via createHTMLDocument. As per the spec
450
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
451
+ // a new empty registry is used when creating a template contents owner
452
+ // document, so we use that as our parent document to ensure nothing
453
+ // is inherited.
454
+ if (typeof HTMLTemplateElement === 'function') {
455
+ const template = document.createElement('template');
456
+ if (template.content && template.content.ownerDocument) {
457
+ document = template.content.ownerDocument;
458
+ }
459
+ }
460
+ let trustedTypesPolicy;
461
+ let emptyHTML = '';
462
+ // The instance's own internal Trusted Types policy. Unlike a caller-supplied
463
+ // `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
464
+ // on duplicate policy names — and is the only policy allowed to persist
465
+ // across configurations and survive `clearConfig()`.
466
+ let defaultTrustedTypesPolicy;
467
+ let defaultTrustedTypesPolicyResolved = false;
468
+ // Tracks whether we are already inside a call to the configured Trusted Types
469
+ // policy (`createHTML` or `createScriptURL`). If a supplied policy callback
470
+ // itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
471
+ // re-enter the policy and recurse until the stack overflows. We detect that
472
+ // re-entry and throw a clear, actionable error instead. The guard is shared
473
+ // across both callbacks, because either one re-entering `sanitize` triggers
474
+ // the same unbounded recursion.
475
+ let IN_TRUSTED_TYPES_POLICY = 0;
476
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
477
+ if (IN_TRUSTED_TYPES_POLICY > 0) {
478
+ throw typeErrorCreate('A configured TRUSTED_TYPES_POLICY callback (createHTML or ' + 'createScriptURL) must not call DOMPurify.sanitize, as that causes ' + 'infinite recursion. Do not pass a policy whose callbacks wrap ' + 'DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted ' + 'Types" section of the README.');
479
+ }
480
+ };
481
+ const _createTrustedHTML = function _createTrustedHTML(html) {
482
+ _assertNotInTrustedTypesPolicy();
483
+ IN_TRUSTED_TYPES_POLICY++;
484
+ try {
485
+ return trustedTypesPolicy.createHTML(html);
486
+ } finally {
487
+ IN_TRUSTED_TYPES_POLICY--;
488
+ }
489
+ };
490
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
491
+ _assertNotInTrustedTypesPolicy();
492
+ IN_TRUSTED_TYPES_POLICY++;
493
+ try {
494
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
495
+ } finally {
496
+ IN_TRUSTED_TYPES_POLICY--;
497
+ }
498
+ };
499
+ // Lazily resolve (and cache) the instance's internal default policy.
500
+ // Resolution is attempted at most once: a successful `createPolicy` cannot be
501
+ // repeated (Trusted Types throws on duplicate names), and a failed or
502
+ // unsupported attempt must not be retried on every parse.
503
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
504
+ if (!defaultTrustedTypesPolicyResolved) {
505
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
506
+ defaultTrustedTypesPolicyResolved = true;
507
+ }
508
+ return defaultTrustedTypesPolicy;
509
+ };
510
+ const _document = document,
511
+ implementation = _document.implementation,
512
+ createNodeIterator = _document.createNodeIterator,
513
+ createDocumentFragment = _document.createDocumentFragment,
514
+ getElementsByTagName = _document.getElementsByTagName;
515
+ const importNode = originalDocument.importNode;
516
+ let hooks = _createHooksMap();
517
+ /**
518
+ * Expose whether this browser supports running the full DOMPurify.
519
+ */
520
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
521
+ const MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
522
+ ERB_EXPR$1 = ERB_EXPR,
523
+ TMPLIT_EXPR$1 = TMPLIT_EXPR,
524
+ DATA_ATTR$1 = DATA_ATTR,
525
+ ARIA_ATTR$1 = ARIA_ATTR,
526
+ IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
527
+ ATTR_WHITESPACE$1 = ATTR_WHITESPACE,
528
+ CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
529
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
530
+ /**
531
+ * We consider the elements and attributes below to be safe. Ideally
532
+ * don't add any new ones but feel free to remove unwanted ones.
533
+ */
534
+ /* allowed element names */
535
+ let ALLOWED_TAGS = null;
536
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
537
+ /* Allowed attribute names */
538
+ let ALLOWED_ATTR = null;
539
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
540
+ /*
541
+ * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
542
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
543
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
544
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
545
+ */
546
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
547
+ tagNameCheck: {
548
+ writable: true,
549
+ configurable: false,
550
+ enumerable: true,
551
+ value: null
552
+ },
553
+ attributeNameCheck: {
554
+ writable: true,
555
+ configurable: false,
556
+ enumerable: true,
557
+ value: null
558
+ },
559
+ allowCustomizedBuiltInElements: {
560
+ writable: true,
561
+ configurable: false,
562
+ enumerable: true,
563
+ value: false
564
+ }
565
+ }));
566
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
567
+ let FORBID_TAGS = null;
568
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
569
+ let FORBID_ATTR = null;
570
+ /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */
571
+ const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
572
+ tagCheck: {
573
+ writable: true,
574
+ configurable: false,
575
+ enumerable: true,
576
+ value: null
577
+ },
578
+ attributeCheck: {
579
+ writable: true,
580
+ configurable: false,
581
+ enumerable: true,
582
+ value: null
583
+ }
584
+ }));
585
+ /* Decide if ARIA attributes are okay */
586
+ let ALLOW_ARIA_ATTR = true;
587
+ /* Decide if custom data attributes are okay */
588
+ let ALLOW_DATA_ATTR = true;
589
+ /* Decide if unknown protocols are okay */
590
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
591
+ /* Decide if self-closing tags in attributes are allowed.
592
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
593
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
594
+ /* Output should be safe for common template engines.
595
+ * This means, DOMPurify removes data attributes, mustaches and ERB
596
+ */
597
+ let SAFE_FOR_TEMPLATES = false;
598
+ /* Output should be safe even for XML used within HTML and alike.
599
+ * This means, DOMPurify removes comments when containing risky content.
600
+ */
601
+ let SAFE_FOR_XML = true;
602
+ /* Decide if document with <html>... should be returned */
603
+ let WHOLE_DOCUMENT = false;
604
+ /* Track whether config is already set on this instance of DOMPurify. */
605
+ let SET_CONFIG = false;
606
+ /* Pristine allowlist bindings captured at setConfig() time. On the
607
+ * persistent-config path sanitize() restores the sets from these before
608
+ * the per-walk hook clone-guard, so a hook's in-call widening cannot
609
+ * carry across calls. Null until setConfig() is called; reset by
610
+ * clearConfig(). */
611
+ let SET_CONFIG_ALLOWED_TAGS = null;
612
+ let SET_CONFIG_ALLOWED_ATTR = null;
613
+ /* Decide if all elements (e.g. style, script) must be children of
614
+ * document.body. By default, browsers might move them to document.head */
615
+ let FORCE_BODY = false;
616
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
617
+ * string (or a TrustedHTML object if Trusted Types are supported).
618
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
619
+ */
620
+ let RETURN_DOM = false;
621
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
622
+ * string (or a TrustedHTML object if Trusted Types are supported) */
623
+ let RETURN_DOM_FRAGMENT = false;
624
+ /* Try to return a Trusted Type object instead of a string, return a string in
625
+ * case Trusted Types are not supported */
626
+ let RETURN_TRUSTED_TYPE = false;
627
+ /* Output should be free from DOM clobbering attacks?
628
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
629
+ */
630
+ let SANITIZE_DOM = true;
631
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
632
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
633
+ *
634
+ * HTML/DOM spec rules that enable DOM Clobbering:
635
+ * - Named Access on Window (§7.3.3)
636
+ * - DOM Tree Accessors (§3.1.5)
637
+ * - Form Element Parent-Child Relations (§4.10.3)
638
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
639
+ * - HTMLCollection (§4.2.10.2)
640
+ *
641
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
642
+ * with a constant string, i.e., `user-content-`
643
+ */
644
+ let SANITIZE_NAMED_PROPS = false;
645
+ const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
646
+ /* Keep element content when removing element? */
647
+ let KEEP_CONTENT = true;
648
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
649
+ * of importing it into a new Document and returning a sanitized copy */
650
+ let IN_PLACE = false;
651
+ /* Allow usage of profiles like html, svg and mathMl */
652
+ let USE_PROFILES = {};
653
+ /* Tags to ignore content of when KEEP_CONTENT is true */
654
+ let FORBID_CONTENTS = null;
655
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
656
+ // <selectedcontent> mirrors the selected <option>'s subtree, cloned by
657
+ // the UA (customizable <select>) — including any on* handlers — and the
658
+ // engine re-mirrors synchronously whenever a removal changes which
659
+ // option/selectedcontent is current, even inside DOMPurify's inert
660
+ // DOMParser document. Hoisting its children on removal re-inserts a fresh
661
+ // mirror target ahead of the walk, which the engine refills, looping
662
+ // forever (DoS) and amplifying output. Dropping its content on removal
663
+ // (rather than hoisting) breaks that cascade; the content is a duplicate
664
+ // of the option, which is sanitized on its own. See campaign-3 F1/F6.
665
+ 'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
666
+ /* Tags that are safe for data: URIs */
667
+ let DATA_URI_TAGS = null;
668
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
669
+ /* Attributes safe for values like "javascript:" */
670
+ let URI_SAFE_ATTRIBUTES = null;
671
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
672
+ const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
673
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
674
+ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
675
+ /* Document namespace */
676
+ let NAMESPACE = HTML_NAMESPACE;
677
+ let IS_EMPTY_INPUT = false;
678
+ /* Allowed XHTML+XML namespaces */
679
+ let ALLOWED_NAMESPACES = null;
680
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
681
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
682
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
683
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
684
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
685
+ // Certain elements are allowed in both SVG and HTML
686
+ // namespace. We need to specify them explicitly
687
+ // so that they don't get erroneously deleted from
688
+ // HTML namespace.
689
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
690
+ /* Parsing of strict XHTML documents */
691
+ let PARSER_MEDIA_TYPE = null;
692
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
693
+ const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
694
+ let transformCaseFunc = null;
695
+ /* Keep a reference to config to pass to hooks */
696
+ let CONFIG = null;
697
+ /* Ideally, do not touch anything below this line */
698
+ /* ______________________________________________ */
699
+ const formElement = document.createElement('form');
700
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
701
+ return testValue instanceof RegExp || testValue instanceof Function;
702
+ };
703
+ /**
704
+ * _parseConfig
705
+ *
706
+ * @param cfg optional config literal
707
+ */
708
+ // eslint-disable-next-line complexity
709
+ const _parseConfig = function _parseConfig() {
710
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
711
+ if (CONFIG && CONFIG === cfg) {
712
+ return;
713
+ }
714
+ /* Shield configuration object from tampering */
715
+ if (!cfg || typeof cfg !== 'object') {
716
+ cfg = {};
717
+ }
718
+ /* Shield configuration object from prototype pollution */
719
+ cfg = clone(cfg);
720
+ PARSER_MEDIA_TYPE =
721
+ // eslint-disable-next-line unicorn/prefer-includes
722
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
723
+ // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
724
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
725
+ /* Set configuration parameters */
726
+ ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
727
+ transform: transformCaseFunc
728
+ });
729
+ ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
730
+ transform: transformCaseFunc
731
+ });
732
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
733
+ transform: stringToString
734
+ });
735
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
736
+ transform: transformCaseFunc,
737
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
738
+ });
739
+ DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
740
+ transform: transformCaseFunc,
741
+ base: DEFAULT_DATA_URI_TAGS
742
+ });
743
+ FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
744
+ transform: transformCaseFunc
745
+ });
746
+ FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
747
+ transform: transformCaseFunc
748
+ });
749
+ FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
750
+ transform: transformCaseFunc
751
+ });
752
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
753
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
754
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
755
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
756
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
757
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
758
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
759
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
760
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
761
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
762
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
763
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
764
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
765
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
766
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
767
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
768
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
769
+ NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
770
+ MATHML_TEXT_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'MATHML_TEXT_INTEGRATION_POINTS') && cfg.MATHML_TEXT_INTEGRATION_POINTS && typeof cfg.MATHML_TEXT_INTEGRATION_POINTS === 'object' ? clone(cfg.MATHML_TEXT_INTEGRATION_POINTS) : addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS); // Default built-in map
771
+ HTML_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'HTML_INTEGRATION_POINTS') && cfg.HTML_INTEGRATION_POINTS && typeof cfg.HTML_INTEGRATION_POINTS === 'object' ? clone(cfg.HTML_INTEGRATION_POINTS) : addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS); // Default built-in map
772
+ const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
773
+ CUSTOM_ELEMENT_HANDLING = create(null);
774
+ if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
775
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
776
+ }
777
+ if (objectHasOwnProperty(customElementHandling, 'attributeNameCheck') && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
778
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck; // Default undefined
779
+ }
780
+ if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
781
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
782
+ }
783
+ seal(CUSTOM_ELEMENT_HANDLING);
784
+ if (SAFE_FOR_TEMPLATES) {
785
+ ALLOW_DATA_ATTR = false;
786
+ }
787
+ if (RETURN_DOM_FRAGMENT) {
788
+ RETURN_DOM = true;
789
+ }
790
+ /* Parse profile info */
791
+ if (USE_PROFILES) {
792
+ ALLOWED_TAGS = addToSet({}, text);
793
+ ALLOWED_ATTR = create(null);
794
+ if (USE_PROFILES.html === true) {
795
+ addToSet(ALLOWED_TAGS, html$1);
796
+ addToSet(ALLOWED_ATTR, html);
797
+ }
798
+ if (USE_PROFILES.svg === true) {
799
+ addToSet(ALLOWED_TAGS, svg$1);
800
+ addToSet(ALLOWED_ATTR, svg);
801
+ addToSet(ALLOWED_ATTR, xml);
802
+ }
803
+ if (USE_PROFILES.svgFilters === true) {
804
+ addToSet(ALLOWED_TAGS, svgFilters);
805
+ addToSet(ALLOWED_ATTR, svg);
806
+ addToSet(ALLOWED_ATTR, xml);
807
+ }
808
+ if (USE_PROFILES.mathMl === true) {
809
+ addToSet(ALLOWED_TAGS, mathMl$1);
810
+ addToSet(ALLOWED_ATTR, mathMl);
811
+ addToSet(ALLOWED_ATTR, xml);
812
+ }
813
+ }
814
+ /* Always reset function-based ADD_TAGS / ADD_ATTR checks to prevent
815
+ * leaking across calls when switching from function to array config */
816
+ EXTRA_ELEMENT_HANDLING.tagCheck = null;
817
+ EXTRA_ELEMENT_HANDLING.attributeCheck = null;
818
+ /* Merge configuration parameters */
819
+ if (objectHasOwnProperty(cfg, 'ADD_TAGS')) {
820
+ if (typeof cfg.ADD_TAGS === 'function') {
821
+ EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
822
+ } else if (arrayIsArray(cfg.ADD_TAGS)) {
823
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
824
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
825
+ }
826
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
827
+ }
828
+ }
829
+ if (objectHasOwnProperty(cfg, 'ADD_ATTR')) {
830
+ if (typeof cfg.ADD_ATTR === 'function') {
831
+ EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
832
+ } else if (arrayIsArray(cfg.ADD_ATTR)) {
833
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
834
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
835
+ }
836
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
837
+ }
838
+ }
839
+ if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
840
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
841
+ }
842
+ if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
843
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
844
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
845
+ }
846
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
847
+ }
848
+ if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
849
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
850
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
851
+ }
852
+ addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
853
+ }
854
+ /* Add #text in case KEEP_CONTENT is set to true */
855
+ if (KEEP_CONTENT) {
856
+ ALLOWED_TAGS['#text'] = true;
857
+ }
858
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
859
+ if (WHOLE_DOCUMENT) {
860
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
861
+ }
862
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
863
+ if (ALLOWED_TAGS.table) {
864
+ addToSet(ALLOWED_TAGS, ['tbody']);
865
+ delete FORBID_TAGS.tbody;
866
+ }
867
+ // Re-derive the active Trusted Types policy from this configuration on
868
+ // every parse. The active policy must never be sticky closure state that
869
+ // outlives the config that set it: a caller-supplied policy left in place
870
+ // after `clearConfig()` — or after a later call that supplied none, or
871
+ // `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
872
+ // `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
873
+ // See GHSA-vxr8-fq34-vvx9.
874
+ if (cfg.TRUSTED_TYPES_POLICY) {
875
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
876
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
877
+ }
878
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
879
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
880
+ }
881
+ // A caller-supplied policy applies to this configuration only.
882
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
883
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
884
+ // Sign local variables required by `sanitize`. If the supplied policy's
885
+ // `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
886
+ // throws via the re-entrancy guard. Restore the previous policy first so
887
+ // the instance is not left in a poisoned state. See #1422.
888
+ try {
889
+ emptyHTML = _createTrustedHTML('');
890
+ } catch (error) {
891
+ trustedTypesPolicy = previousTrustedTypesPolicy;
892
+ throw error;
893
+ }
894
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
895
+ // Explicit opt-out for this call: perform no Trusted Types signing and
896
+ // create nothing (so a strict `trusted-types` CSP that disallows a
897
+ // `dompurify` policy can still call `sanitize` from inside its own
898
+ // policy — see #1422). Resetting to `undefined` rather than a sticky
899
+ // `null` also drops any previously retained caller policy, so it cannot
900
+ // resurface on a later call, while still allowing the next config-less
901
+ // call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
902
+ trustedTypesPolicy = undefined;
903
+ emptyHTML = '';
904
+ } else {
905
+ // No policy supplied: keep the currently active policy if one is set — a
906
+ // previously supplied policy is intentionally sticky across config-less
907
+ // calls — otherwise fall back to the instance's own internal policy,
908
+ // created at most once. (A policy supplied for a *single* call still
909
+ // lingers by design; what must not linger is a policy whose configuration
910
+ // has been torn down via `clearConfig()`, which restores the default.)
911
+ if (trustedTypesPolicy === undefined) {
912
+ trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
913
+ }
914
+ // Sign internal variables only when a policy is active. A falsy policy
915
+ // (Trusted Types unsupported, creation failed, or an explicit opt-out)
916
+ // leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
917
+ // a non-policy and throw. See #1422.
918
+ if (trustedTypesPolicy && typeof emptyHTML === 'string') {
919
+ emptyHTML = _createTrustedHTML('');
920
+ }
921
+ }
922
+ // Prevent further manipulation of configuration.
923
+ // Not available in IE8, Safari 5, etc.
924
+ if (freeze) {
925
+ freeze(cfg);
926
+ }
927
+ CONFIG = cfg;
928
+ };
929
+ /* Keep track of all possible SVG and MathML tags
930
+ * so that we can perform the namespace checks
931
+ * correctly. */
932
+ const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
933
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
934
+ /**
935
+ * Namespace rules for an element in the SVG namespace.
936
+ *
937
+ * @param tagName the element's lowercase tag name
938
+ * @param parent the (possibly simulated) parent node
939
+ * @param parentTagName the parent's lowercase tag name
940
+ * @returns true if a spec-compliant parser could produce this element
941
+ */
942
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
943
+ // The only way to switch from HTML namespace to SVG
944
+ // is via <svg>. If it happens via any other tag, then
945
+ // it should be killed.
946
+ if (parent.namespaceURI === HTML_NAMESPACE) {
947
+ return tagName === 'svg';
948
+ }
949
+ // The only way to switch from MathML to SVG is via <svg>
950
+ // if the parent is either <annotation-xml> or a MathML
951
+ // text integration point.
952
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
953
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
954
+ }
955
+ // We only allow elements that are defined in SVG
956
+ // spec. All others are disallowed in SVG namespace.
957
+ return Boolean(ALL_SVG_TAGS[tagName]);
958
+ };
959
+ /**
960
+ * Namespace rules for an element in the MathML namespace.
961
+ *
962
+ * @param tagName the element's lowercase tag name
963
+ * @param parent the (possibly simulated) parent node
964
+ * @param parentTagName the parent's lowercase tag name
965
+ * @returns true if a spec-compliant parser could produce this element
966
+ */
967
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
968
+ // The only way to switch from HTML namespace to MathML
969
+ // is via <math>. If it happens via any other tag, then
970
+ // it should be killed.
971
+ if (parent.namespaceURI === HTML_NAMESPACE) {
972
+ return tagName === 'math';
973
+ }
974
+ // The only way to switch from SVG to MathML is via
975
+ // <math> and HTML integration points
976
+ if (parent.namespaceURI === SVG_NAMESPACE) {
977
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
978
+ }
979
+ // We only allow elements that are defined in MathML
980
+ // spec. All others are disallowed in MathML namespace.
981
+ return Boolean(ALL_MATHML_TAGS[tagName]);
982
+ };
983
+ /**
984
+ * Namespace rules for an element in the HTML namespace.
985
+ *
986
+ * @param tagName the element's lowercase tag name
987
+ * @param parent the (possibly simulated) parent node
988
+ * @param parentTagName the parent's lowercase tag name
989
+ * @returns true if a spec-compliant parser could produce this element
990
+ */
991
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
992
+ // The only way to switch from SVG to HTML is via
993
+ // HTML integration points, and from MathML to HTML
994
+ // is via MathML text integration points
995
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
996
+ return false;
997
+ }
998
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
999
+ return false;
1000
+ }
1001
+ // We disallow tags that are specific for MathML
1002
+ // or SVG and should never appear in HTML namespace
1003
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1004
+ };
1005
+ /**
1006
+ * @param element a DOM element whose namespace is being checked
1007
+ * @returns Return false if the element has a
1008
+ * namespace that a spec-compliant parser would never
1009
+ * return. Return true otherwise.
1010
+ */
1011
+ const _checkValidNamespace = function _checkValidNamespace(element) {
1012
+ let parent = getParentNode(element);
1013
+ // In JSDOM, if we're inside shadow DOM, then parentNode
1014
+ // can be null. We just simulate parent in this case.
1015
+ if (!parent || !parent.tagName) {
1016
+ parent = {
1017
+ namespaceURI: NAMESPACE,
1018
+ tagName: 'template'
1019
+ };
1020
+ }
1021
+ const tagName = stringToLowerCase(element.tagName);
1022
+ const parentTagName = stringToLowerCase(parent.tagName);
1023
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
1024
+ return false;
1025
+ }
1026
+ if (element.namespaceURI === SVG_NAMESPACE) {
1027
+ return _checkSvgNamespace(tagName, parent, parentTagName);
1028
+ }
1029
+ if (element.namespaceURI === MATHML_NAMESPACE) {
1030
+ return _checkMathMlNamespace(tagName, parent, parentTagName);
1031
+ }
1032
+ if (element.namespaceURI === HTML_NAMESPACE) {
1033
+ return _checkHtmlNamespace(tagName, parent, parentTagName);
1034
+ }
1035
+ // For XHTML and XML documents that support custom namespaces
1036
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
1037
+ return true;
1038
+ }
1039
+ // The code should never reach this place (this means
1040
+ // that the element somehow got namespace that is not
1041
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
1042
+ // Return false just in case.
1043
+ return false;
1044
+ };
1045
+ /**
1046
+ * _forceRemove
1047
+ *
1048
+ * @param node a DOM node
1049
+ */
1050
+ const _forceRemove = function _forceRemove(node) {
1051
+ arrayPush(DOMPurify.removed, {
1052
+ element: node
1053
+ });
1054
+ try {
1055
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
1056
+ getParentNode(node).removeChild(node);
1057
+ } catch (_) {
1058
+ /* The normal detach failed — this is reached for a parentless node
1059
+ (getParentNode() is null, so .removeChild throws). Element.prototype
1060
+ .remove() is itself a spec no-op on a parentless node, so a recorded
1061
+ "removal" would otherwise hand the caller back an intact,
1062
+ payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
1063
+ the style-with-element-child rule decided to kill). Fail closed by
1064
+ throwing — exactly as a clobbered root does at the IN_PLACE entry —
1065
+ rather than trying to "neutralize" the node via its own methods.
1066
+ Neutralizing would mean calling getAttributeNames()/removeAttribute()
1067
+ on the node, both of which a <form> root can clobber via a named child
1068
+ (and _isClobbered does not even probe getAttributeNames), so the
1069
+ neutralize step could itself be silently defeated, leaving the payload
1070
+ intact. A throw touches only the cached, clobber-safe remove() and
1071
+ getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
1072
+ to every root-kill reason. REPORT-3.
1073
+ This lives inside the catch, so it never fires for a normally-removed
1074
+ in-tree node: those have a parent, removeChild() succeeds, and the
1075
+ catch is not entered. Only a kept (parentless) root reaches here. */
1076
+ remove(node);
1077
+ if (!getParentNode(node)) {
1078
+ throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
1079
+ }
1080
+ }
1081
+ };
1082
+ /**
1083
+ * _neutralizeRoot
1084
+ *
1085
+ * Fail-closed teardown of an in-place root after the sanitize walk aborts
1086
+ * (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
1087
+ * custom element's reaction detaches a node so `_forceRemove`'s deliberate
1088
+ * parentless guard throws, or any other re-entrant engine mutation — would
1089
+ * otherwise leave the caller's *live* tree half-sanitized, with everything
1090
+ * after the abort point still carrying its handlers. There is no safe way
1091
+ * to resume the walk (the tree mutated under us), so we strip the root bare:
1092
+ * remove every child and every attribute, then let the caller's catch see
1093
+ * the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
1094
+ * getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
1095
+ *
1096
+ * @param root the in-place root to empty
1097
+ */
1098
+ const _neutralizeRoot = function _neutralizeRoot(root) {
1099
+ const childNodes = getChildNodes(root);
1100
+ if (childNodes) {
1101
+ const snapshot = [];
1102
+ arrayForEach(childNodes, child => {
1103
+ arrayPush(snapshot, child);
1104
+ });
1105
+ arrayForEach(snapshot, child => {
1106
+ try {
1107
+ remove(child);
1108
+ } catch (_) {
1109
+ /* Best-effort teardown; a still-attached child is handled below */
1110
+ }
1111
+ });
1112
+ }
1113
+ const attributes = getAttributes(root);
1114
+ if (attributes) {
1115
+ for (let i = attributes.length - 1; i >= 0; --i) {
1116
+ const attribute = attributes[i];
1117
+ const name = attribute && attribute.name;
1118
+ if (typeof name === 'string') {
1119
+ try {
1120
+ root.removeAttribute(name);
1121
+ } catch (_) {
1122
+ /* Clobbered removeAttribute — ignore (fail-closed best effort) */
1123
+ }
1124
+ }
1125
+ }
1126
+ }
1127
+ };
1128
+ /**
1129
+ * _removeAttribute
1130
+ *
1131
+ * @param name an Attribute name
1132
+ * @param element a DOM node
1133
+ */
1134
+ const _removeAttribute = function _removeAttribute(name, element) {
1135
+ try {
1136
+ arrayPush(DOMPurify.removed, {
1137
+ attribute: element.getAttributeNode(name),
1138
+ from: element
1139
+ });
1140
+ } catch (_) {
1141
+ arrayPush(DOMPurify.removed, {
1142
+ attribute: null,
1143
+ from: element
1144
+ });
1145
+ }
1146
+ element.removeAttribute(name);
1147
+ // We void attribute values for unremovable "is" attributes
1148
+ if (name === 'is') {
1149
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
1150
+ try {
1151
+ _forceRemove(element);
1152
+ } catch (_) {}
1153
+ } else {
1154
+ try {
1155
+ element.setAttribute(name, '');
1156
+ } catch (_) {}
1157
+ }
1158
+ }
1159
+ };
1160
+ /**
1161
+ * _stripDisallowedAttributes
1162
+ *
1163
+ * Removes every attribute the active configuration does not allow from a
1164
+ * single element, using the same allowlist as the main attribute pass (so
1165
+ * `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
1166
+ * neutralise nodes that are being discarded from an in-place tree.
1167
+ *
1168
+ * @param element the element to strip
1169
+ */
1170
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
1171
+ const attributes = getAttributes(element);
1172
+ if (!attributes) {
1173
+ return;
1174
+ }
1175
+ for (let i = attributes.length - 1; i >= 0; --i) {
1176
+ const attribute = attributes[i];
1177
+ const name = attribute && attribute.name;
1178
+ if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
1179
+ continue;
1180
+ }
1181
+ try {
1182
+ element.removeAttribute(name);
1183
+ } catch (_) {
1184
+ /* Clobbered removeAttribute on a doomed node — ignore */
1185
+ }
1186
+ }
1187
+ };
1188
+ /**
1189
+ * _neutralizeSubtree
1190
+ *
1191
+ * Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
1192
+ * move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
1193
+ * namespace, comment, processing-instruction and KEEP_CONTENT:false removals
1194
+ * all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
1195
+ * those dropped nodes are detached from the caller's LIVE tree but a
1196
+ * handler-bearing original among them (an `<img onerror>`/`<video>` that was
1197
+ * loading) keeps its queued resource event, which fires in page scope after
1198
+ * sanitize returns. This walks a removed subtree and strips every attribute
1199
+ * the active configuration does not allow — so `on*` handlers are cancelled
1200
+ * through the SAME allowlist that governs kept nodes, not a separate `/^on/`
1201
+ * blocklist. Run synchronously before sanitize returns, i.e. before any
1202
+ * queued event can fire. Hook-free by design: these nodes leave the output,
1203
+ * so firing attribute hooks for them would be surprising. Clobber-safe reads;
1204
+ * a doomed clobbered node may shadow `removeAttribute` (its own attributes are
1205
+ * irrelevant — it is discarded — while its non-clobbered descendants, e.g.
1206
+ * the `<img>`, are reached and scrubbed).
1207
+ *
1208
+ * @param root the root of a removed subtree to neutralise
1209
+ */
1210
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
1211
+ const stack = [root];
1212
+ while (stack.length > 0) {
1213
+ const node = stack.pop();
1214
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
1215
+ if (nodeType === NODE_TYPE.element) {
1216
+ _stripDisallowedAttributes(node);
1217
+ }
1218
+ const childNodes = getChildNodes(node);
1219
+ if (childNodes) {
1220
+ for (let i = childNodes.length - 1; i >= 0; --i) {
1221
+ stack.push(childNodes[i]);
1222
+ }
1223
+ }
1224
+ }
1225
+ };
1226
+ /**
1227
+ * _initDocument
1228
+ *
1229
+ * @param dirty - a string of dirty markup
1230
+ * @return a DOM, filled with the dirty markup
1231
+ */
1232
+ const _initDocument = function _initDocument(dirty) {
1233
+ /* Create a HTML document */
1234
+ let doc = null;
1235
+ let leadingWhitespace = null;
1236
+ if (FORCE_BODY) {
1237
+ dirty = '<remove></remove>' + dirty;
1238
+ } else {
1239
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
1240
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
1241
+ leadingWhitespace = matches && matches[0];
1242
+ }
1243
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
1244
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
1245
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
1246
+ }
1247
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
1248
+ /*
1249
+ * Use the DOMParser API by default, fallback later if needs be
1250
+ * DOMParser not work for svg when has multiple root element.
1251
+ */
1252
+ if (NAMESPACE === HTML_NAMESPACE) {
1253
+ try {
1254
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
1255
+ } catch (_) {}
1256
+ }
1257
+ /* Use createHTMLDocument in case DOMParser is not available */
1258
+ if (!doc || !doc.documentElement) {
1259
+ doc = implementation.createDocument(NAMESPACE, 'template', null);
1260
+ try {
1261
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
1262
+ } catch (_) {
1263
+ // Syntax error if dirtyPayload is invalid xml
1264
+ }
1265
+ }
1266
+ const body = doc.body || doc.documentElement;
1267
+ if (dirty && leadingWhitespace) {
1268
+ body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
1269
+ }
1270
+ /* Work on whole document or just its body */
1271
+ if (NAMESPACE === HTML_NAMESPACE) {
1272
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
1273
+ }
1274
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
1275
+ };
1276
+ /**
1277
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
1278
+ *
1279
+ * @param root The root element or node to start traversing on.
1280
+ * @return The created NodeIterator
1281
+ */
1282
+ const _createNodeIterator = function _createNodeIterator(root) {
1283
+ return createNodeIterator.call(root.ownerDocument || root, root,
1284
+ // eslint-disable-next-line no-bitwise
1285
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
1286
+ };
1287
+ /**
1288
+ * Replace template expression syntax (mustache, ERB, template
1289
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
1290
+ * sites. Order matters: mustache, then ERB, then template literal.
1291
+ *
1292
+ * @param value the string to scrub
1293
+ * @returns the scrubbed string
1294
+ */
1295
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
1296
+ value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
1297
+ value = stringReplace(value, ERB_EXPR$1, ' ');
1298
+ value = stringReplace(value, TMPLIT_EXPR$1, ' ');
1299
+ return value;
1300
+ };
1301
+ /**
1302
+ * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
1303
+ * character data of an element subtree. Used as the final safety net for
1304
+ * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
1305
+ * which only form after text-node normalization (e.g. fragments split across
1306
+ * stripped elements) cannot survive into a template-evaluating framework.
1307
+ *
1308
+ * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
1309
+ * in place rather than round-tripping through innerHTML. This preserves
1310
+ * descendant node references (important for IN_PLACE callers), avoids a
1311
+ * serialize/reparse cycle, and reads literal character data — which means
1312
+ * `<%...%>` in text content matches the ERB regex against its real bytes
1313
+ * instead of the HTML-entity-escaped form innerHTML would produce.
1314
+ *
1315
+ * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
1316
+ * attributes is performed during the per-node `_sanitizeAttributes` pass.
1317
+ *
1318
+ * @param node The root element whose character data should be scrubbed.
1319
+ */
1320
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
1321
+ var _node$querySelectorAl;
1322
+ node.normalize();
1323
+ const walker = createNodeIterator.call(node.ownerDocument || node, node,
1324
+ // eslint-disable-next-line no-bitwise
1325
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
1326
+ let currentNode = walker.nextNode();
1327
+ while (currentNode) {
1328
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
1329
+ currentNode = walker.nextNode();
1330
+ }
1331
+ // NodeIterator does not descend into <template>.content per the DOM spec,
1332
+ // so we must explicitly recurse into each template's content fragment,
1333
+ // mirroring the approach used by _sanitizeShadowDOM.
1334
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
1335
+ if (templates) {
1336
+ arrayForEach(templates, tmpl => {
1337
+ if (_isDocumentFragment(tmpl.content)) {
1338
+ _scrubTemplateExpressions2(tmpl.content);
1339
+ }
1340
+ });
1341
+ }
1342
+ };
1343
+ /**
1344
+ * _isClobbered
1345
+ *
1346
+ * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
1347
+ * interface with [LegacyOverrideBuiltIns]; a descendant element with a
1348
+ * `name` attribute matching a prototype property shadows that property
1349
+ * on direct reads. We use this check at the IN_PLACE entry-point and
1350
+ * during attribute sanitization to refuse clobbered forms.
1351
+ *
1352
+ * @param element element to check for clobbering attacks
1353
+ * @return true if clobbered, false if safe
1354
+ */
1355
+ const _isClobbered = function _isClobbered(element) {
1356
+ // Realm-independent tag-name probe. If we can't determine the tag
1357
+ // name at all, we can't reason about clobbering — return false
1358
+ // (the caller's other defences still apply).
1359
+ const realTagName = getNodeName ? getNodeName(element) : null;
1360
+ if (typeof realTagName !== 'string') {
1361
+ return false;
1362
+ }
1363
+ if (transformCaseFunc(realTagName) !== 'form') {
1364
+ return false;
1365
+ }
1366
+ return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
1367
+ // Realm-safe NamedNodeMap detection: equality against the cached
1368
+ // prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
1369
+ // makes the direct read diverge from the cached read; a clean form
1370
+ // (same-realm OR foreign-realm) has both reads pointing at the same
1371
+ // canonical NamedNodeMap.
1372
+ element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
1373
+ // NodeType clobbering probe. Cached Node.prototype.nodeType getter
1374
+ // returns the integer 1 for any Element regardless of realm; direct
1375
+ // read on a clobbered form (e.g. <input name="nodeType">) returns
1376
+ // the named child element. Cheap addition — nodeType is read from
1377
+ // an internal slot, no serialization cost — and removes a residual
1378
+ // clobbering surface used by several mXSS / PI / comment branches
1379
+ // in _sanitizeElements that compare currentNode.nodeType directly.
1380
+ element.nodeType !== getNodeType(element) ||
1381
+ // HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
1382
+ // "childNodes" shadows the prototype getter. Direct reads of
1383
+ // form.childNodes from a clobbered form return the named child
1384
+ // instead of the real NodeList, so any walk that reads it directly
1385
+ // skips the form's real children. Compare the direct read to the
1386
+ // cached Node.prototype getter — when the form's named-property
1387
+ // getter intercepts the read, the two values differ and we flag
1388
+ // the form. This catches every clobbering child type (input,
1389
+ // select, etc.) regardless of whether the named child happens to
1390
+ // carry a numeric .length, which a typeof-based probe would miss
1391
+ // (e.g. HTMLSelectElement.length is a defined unsigned-long).
1392
+ element.childNodes !== getChildNodes(element);
1393
+ };
1394
+ /**
1395
+ * Checks whether the given value is a DocumentFragment from any realm.
1396
+ *
1397
+ * The realm-independent replacement reads `nodeType` through the cached
1398
+ * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
1399
+ * constant (11). nodeType is a numeric value resolved from the node's
1400
+ * internal slot, identical across realms for the same kind of node.
1401
+ *
1402
+ * @param value object to check
1403
+ * @return true if value is a DocumentFragment-shaped node from any realm
1404
+ */
1405
+ const _isDocumentFragment = function _isDocumentFragment(value) {
1406
+ if (!getNodeType || typeof value !== 'object' || value === null) {
1407
+ return false;
1408
+ }
1409
+ try {
1410
+ return getNodeType(value) === NODE_TYPE.documentFragment;
1411
+ } catch (_) {
1412
+ return false;
1413
+ }
1414
+ };
1415
+ /**
1416
+ * Checks whether the given object is a DOM node, including nodes that
1417
+ * originate from a different window/realm (e.g. an iframe's
1418
+ * contentDocument). The previous `value instanceof Node` check was
1419
+ * realm-bound: nodes from a different window failed it, causing
1420
+ * sanitize() to silently stringify them and reset IN_PLACE to false,
1421
+ * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
1422
+ *
1423
+ * @param value object to check whether it's a DOM node
1424
+ * @return true if value is a DOM node from any realm
1425
+ */
1426
+ const _isNode = function _isNode(value) {
1427
+ if (!getNodeType || typeof value !== 'object' || value === null) {
1428
+ return false;
1429
+ }
1430
+ try {
1431
+ return typeof getNodeType(value) === 'number';
1432
+ } catch (_) {
1433
+ return false;
1434
+ }
1435
+ };
1436
+ function _executeHooks(hooks, currentNode, data) {
1437
+ if (hooks.length === 0) {
1438
+ return;
1439
+ }
1440
+ arrayForEach(hooks, hook => {
1441
+ hook.call(DOMPurify, currentNode, data, CONFIG);
1442
+ });
1443
+ }
1444
+ /**
1445
+ * Structural-threat checks that condemn a node regardless of the
1446
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
1447
+ * processing instructions, markup-bearing comments. Pure predicate;
1448
+ * the caller removes. Check order is load-bearing.
1449
+ *
1450
+ * @param currentNode the node to inspect
1451
+ * @param tagName the node's transformCaseFunc'd tag name
1452
+ * @return true if the node must be removed
1453
+ */
1454
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
1455
+ /* Detect mXSS attempts abusing namespace confusion */
1456
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
1457
+ return true;
1458
+ }
1459
+ /* Remove risky CSS construction leading to mXSS */
1460
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
1461
+ return true;
1462
+ }
1463
+ /* Remove any occurrence of processing instructions */
1464
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
1465
+ return true;
1466
+ }
1467
+ /* Remove any kind of possibly harmful comments */
1468
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
1469
+ return true;
1470
+ }
1471
+ return false;
1472
+ };
1473
+ /**
1474
+ * Handle a node whose tag is forbidden or not allowlisted: keep
1475
+ * allowed custom elements (false return exits _sanitizeElements
1476
+ * early - namespace/fallback checks and the afterSanitizeElements
1477
+ * hook are intentionally skipped for kept custom elements), else
1478
+ * hoist content per KEEP_CONTENT and remove.
1479
+ *
1480
+ * @param currentNode the disallowed node
1481
+ * @param tagName the node's transformCaseFunc'd tag name
1482
+ * @return true if the node was removed, false if kept
1483
+ */
1484
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
1485
+ /* Check if we have a custom element to handle */
1486
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
1487
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
1488
+ return false;
1489
+ }
1490
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
1491
+ return false;
1492
+ }
1493
+ }
1494
+ /* Keep content except for bad-listed elements.
1495
+ Use the cached prototype getters exclusively — the previous code
1496
+ had `|| currentNode.parentNode` / `|| currentNode.childNodes`
1497
+ fallbacks, but the cached getters always return the canonical
1498
+ value (or null for a real parent-less node), so the fallback
1499
+ path was dead in safe cases and a clobbering surface in unsafe
1500
+ ones. Falsy cached results stay falsy; the `if (childNodes &&
1501
+ parentNode)` check already gates correctly. */
1502
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1503
+ const parentNode = getParentNode(currentNode);
1504
+ const childNodes = getChildNodes(currentNode);
1505
+ if (childNodes && parentNode) {
1506
+ const childCount = childNodes.length;
1507
+ /* In-place: hoist the *original* children so the iterator visits
1508
+ and sanitises them through the same allowlist pass as every other
1509
+ node. The caller built the tree in the live document, so the
1510
+ originals carry already-queued resource events (`<img onerror>`,
1511
+ `<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
1512
+ those originals detached but still armed, firing in page scope
1513
+ while the returned tree looked clean. Moving is safe in-place: the
1514
+ root is pre-validated as an allowed tag and so is never the node
1515
+ being removed, which keeps `parentNode` inside the iterator root
1516
+ and the relocated child inside the serialised tree.
1517
+ Otherwise (string / DOM-copy paths): clone. The iterator is rooted
1518
+ at — and the result serialised from — `body`, so a restrictive
1519
+ ALLOWED_TAGS that removes `body` itself must leave its content in
1520
+ place, which only cloning does; and those paths parse into an
1521
+ inert document, so their discarded originals never had a queued
1522
+ event to neutralise.
1523
+ `childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
1524
+ valid whether we move (drops the trailing entry) or clone (leaves
1525
+ the list intact). */
1526
+ for (let i = childCount - 1; i >= 0; --i) {
1527
+ const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
1528
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
1529
+ }
1530
+ }
1531
+ }
1532
+ _forceRemove(currentNode);
1533
+ return true;
1534
+ };
1535
+ /**
1536
+ * _sanitizeElements
1537
+ *
1538
+ * @protect nodeName
1539
+ * @protect textContent
1540
+ * @protect removeChild
1541
+ * @param currentNode to check for permission to exist
1542
+ * @return true if node was killed, false if left alive
1543
+ */
1544
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
1545
+ /* Execute a hook if present */
1546
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
1547
+ /* Check if element is clobbered or can clobber */
1548
+ if (_isClobbered(currentNode)) {
1549
+ _forceRemove(currentNode);
1550
+ return true;
1551
+ }
1552
+ /* Now let's check the element's type and name */
1553
+ const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
1554
+ /* Execute a hook if present */
1555
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
1556
+ tagName,
1557
+ allowedTags: ALLOWED_TAGS
1558
+ });
1559
+ /* Remove mXSS vectors, processing instructions and risky comments */
1560
+ if (_isUnsafeNode(currentNode, tagName)) {
1561
+ _forceRemove(currentNode);
1562
+ return true;
1563
+ }
1564
+ /* Remove element if anything forbids its presence */
1565
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
1566
+ return _sanitizeDisallowedNode(currentNode, tagName);
1567
+ }
1568
+ /* Check whether element has a valid namespace.
1569
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
1570
+ nodeType getter rather than `instanceof Element`, which is realm-
1571
+ bound and short-circuits to false for any node minted in a different
1572
+ realm — letting a foreign-realm element with a forbidden namespace
1573
+ slip past the namespace check entirely. */
1574
+ const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
1575
+ if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
1576
+ _forceRemove(currentNode);
1577
+ return true;
1578
+ }
1579
+ /* Make sure that older browsers don't get fallback-tag mXSS */
1580
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
1581
+ _forceRemove(currentNode);
1582
+ return true;
1583
+ }
1584
+ /* Sanitize element content to be template-safe */
1585
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
1586
+ /* Get the element's text content */
1587
+ const content = _stripTemplateExpressions(currentNode.textContent);
1588
+ if (currentNode.textContent !== content) {
1589
+ arrayPush(DOMPurify.removed, {
1590
+ element: currentNode.cloneNode()
1591
+ });
1592
+ currentNode.textContent = content;
1593
+ }
1594
+ }
1595
+ /* Execute a hook if present */
1596
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
1597
+ return false;
1598
+ };
1599
+ /**
1600
+ * _isValidAttribute
1601
+ *
1602
+ * @param lcTag Lowercase tag name of containing element.
1603
+ * @param lcName Lowercase attribute name.
1604
+ * @param value Attribute value.
1605
+ * @return Returns true if `value` is valid, otherwise false.
1606
+ */
1607
+ // eslint-disable-next-line complexity
1608
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1609
+ /* FORBID_ATTR must always win, even if ADD_ATTR predicate would allow it */
1610
+ if (FORBID_ATTR[lcName]) {
1611
+ return false;
1612
+ }
1613
+ /* Make sure attribute cannot clobber */
1614
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1615
+ return false;
1616
+ }
1617
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
1618
+ /* Allow valid data-* attributes: At least one character after "-"
1619
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1620
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1621
+ We don't need to check the value; it's always URI safe. */
1622
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
1623
+ if (
1624
+ // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1625
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1626
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1627
+ _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) ||
1628
+ // Alternative, second condition checks if it's an `is`-attribute, AND
1629
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1630
+ lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
1631
+ return false;
1632
+ }
1633
+ /* Check value is safe. First, is attr inert? If so, is safe */
1634
+ } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if (value) {
1635
+ return false;
1636
+ } else ;
1637
+ return true;
1638
+ };
1639
+ /* Names the HTML spec reserves from valid-custom-element-name; these must
1640
+ * never be treated as basic custom elements even when a permissive
1641
+ * CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
1642
+ const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, ['annotation-xml', 'color-profile', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'missing-glyph']);
1643
+ /**
1644
+ * _isBasicCustomElement
1645
+ * checks if at least one dash is included in tagName, and it's not the first char
1646
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1647
+ *
1648
+ * @param tagName name of the tag of the node to sanitize
1649
+ * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1650
+ */
1651
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1652
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
1653
+ };
1654
+ /**
1655
+ * Wrap an attribute value in the matching Trusted Types object when
1656
+ * the active policy requires it. Namespaced attributes pass through
1657
+ * unchanged (no TT support yet, see
1658
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
1659
+ *
1660
+ * @param lcTag lowercase tag name of the containing element
1661
+ * @param lcName lowercase attribute name
1662
+ * @param namespaceURI the attribute's namespace, if any
1663
+ * @param value the attribute value to wrap
1664
+ * @return the value, wrapped when Trusted Types demand it
1665
+ */
1666
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
1667
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
1668
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1669
+ case 'TrustedHTML':
1670
+ {
1671
+ return _createTrustedHTML(value);
1672
+ }
1673
+ case 'TrustedScriptURL':
1674
+ {
1675
+ return _createTrustedScriptURL(value);
1676
+ }
1677
+ }
1678
+ }
1679
+ return value;
1680
+ };
1681
+ /**
1682
+ * Write a modified attribute value back onto the element. On
1683
+ * success, re-probe for clobbering introduced by the new value and
1684
+ * remove the element when found; otherwise pop the removal entry
1685
+ * recorded by the earlier _removeAttribute (long-standing pairing
1686
+ * with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
1687
+ * failure, remove the attribute instead.
1688
+ *
1689
+ * @param currentNode the element carrying the attribute
1690
+ * @param name the attribute name as present on the element
1691
+ * @param namespaceURI the attribute's namespace, if any
1692
+ * @param value the new attribute value
1693
+ */
1694
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
1695
+ try {
1696
+ if (namespaceURI) {
1697
+ currentNode.setAttributeNS(namespaceURI, name, value);
1698
+ } else {
1699
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1700
+ currentNode.setAttribute(name, value);
1701
+ }
1702
+ if (_isClobbered(currentNode)) {
1703
+ _forceRemove(currentNode);
1704
+ } else {
1705
+ arrayPop(DOMPurify.removed);
1706
+ }
1707
+ } catch (_) {
1708
+ _removeAttribute(name, currentNode);
1709
+ }
1710
+ };
1711
+ /**
1712
+ * _sanitizeAttributes
1713
+ *
1714
+ * @protect attributes
1715
+ * @protect nodeName
1716
+ * @protect removeAttribute
1717
+ * @protect setAttribute
1718
+ *
1719
+ * @param currentNode to sanitize
1720
+ */
1721
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1722
+ /* Execute a hook if present */
1723
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1724
+ const attributes = currentNode.attributes;
1725
+ /* Check if we have attributes; if not we might have a text node */
1726
+ if (!attributes || _isClobbered(currentNode)) {
1727
+ return;
1728
+ }
1729
+ const hookEvent = {
1730
+ attrName: '',
1731
+ attrValue: '',
1732
+ keepAttr: true,
1733
+ allowedAttributes: ALLOWED_ATTR,
1734
+ forceKeepAttr: undefined
1735
+ };
1736
+ let l = attributes.length;
1737
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1738
+ /* Go backwards over all attributes; safely remove bad ones */
1739
+ while (l--) {
1740
+ const attr = attributes[l];
1741
+ const name = attr.name,
1742
+ namespaceURI = attr.namespaceURI,
1743
+ attrValue = attr.value;
1744
+ const lcName = transformCaseFunc(name);
1745
+ const initValue = attrValue;
1746
+ let value = name === 'value' ? initValue : stringTrim(initValue);
1747
+ /* Execute a hook if present */
1748
+ hookEvent.attrName = lcName;
1749
+ hookEvent.attrValue = value;
1750
+ hookEvent.keepAttr = true;
1751
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1752
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
1753
+ value = hookEvent.attrValue;
1754
+ /* Full DOM Clobbering protection via namespace isolation,
1755
+ * Prefix id and name attributes with `user-content-`
1756
+ */
1757
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
1758
+ // Remove the attribute with this value
1759
+ _removeAttribute(name, currentNode);
1760
+ // Prefix the value and later re-create the attribute with the sanitized value
1761
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
1762
+ }
1763
+ // Else: already prefixed, leave the attribute alone — the prefix is
1764
+ // itself the clobbering protection, and re-applying it is incorrect.
1765
+ /* Work around a security issue with comments inside attributes */
1766
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
1767
+ _removeAttribute(name, currentNode);
1768
+ continue;
1769
+ }
1770
+ /* Make sure we cannot easily use animated hrefs, even if animations are allowed */
1771
+ if (lcName === 'attributename' && stringMatch(value, 'href')) {
1772
+ _removeAttribute(name, currentNode);
1773
+ continue;
1774
+ }
1775
+ /* Did the hooks force-keep the attribute? */
1776
+ if (hookEvent.forceKeepAttr) {
1777
+ continue;
1778
+ }
1779
+ /* Did the hooks approve of the attribute? */
1780
+ if (!hookEvent.keepAttr) {
1781
+ _removeAttribute(name, currentNode);
1782
+ continue;
1783
+ }
1784
+ /* Work around a security issue in jQuery 3.0 */
1785
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
1786
+ _removeAttribute(name, currentNode);
1787
+ continue;
1788
+ }
1789
+ /* Sanitize attribute content to be template-safe */
1790
+ if (SAFE_FOR_TEMPLATES) {
1791
+ value = _stripTemplateExpressions(value);
1792
+ }
1793
+ /* Is `value` valid for this attribute? */
1794
+ if (!_isValidAttribute(lcTag, lcName, value)) {
1795
+ _removeAttribute(name, currentNode);
1796
+ continue;
1797
+ }
1798
+ /* Handle attributes that require Trusted Types */
1799
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
1800
+ /* Handle invalid data-* attribute set by try-catching it */
1801
+ if (value !== initValue) {
1802
+ _setAttributeValue(currentNode, name, namespaceURI, value);
1803
+ }
1804
+ }
1805
+ /* Execute a hook if present */
1806
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
1807
+ };
1808
+ /**
1809
+ * _sanitizeShadowDOM
1810
+ *
1811
+ * @param fragment to iterate over recursively
1812
+ */
1813
+ const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
1814
+ let shadowNode = null;
1815
+ const shadowIterator = _createNodeIterator(fragment);
1816
+ /* Execute a hook if present */
1817
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
1818
+ while (shadowNode = shadowIterator.nextNode()) {
1819
+ /* Execute a hook if present */
1820
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
1821
+ /* Sanitize tags and elements */
1822
+ _sanitizeElements(shadowNode);
1823
+ /* Check attributes next */
1824
+ _sanitizeAttributes(shadowNode);
1825
+ /* Deep shadow DOM detected.
1826
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
1827
+ DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
1828
+ recurse into <template>.content from foreign realms too. */
1829
+ if (_isDocumentFragment(shadowNode.content)) {
1830
+ _sanitizeShadowDOM2(shadowNode.content);
1831
+ }
1832
+ /* An element iterated here may itself host an attached
1833
+ shadow root. The default NodeIterator does not enter shadow
1834
+ trees, so a shadow root nested inside template.content was
1835
+ previously reached by no walk at all (the pre-pass at
1836
+ _sanitizeAttachedShadowRoots descends via childNodes, which
1837
+ doesn't enter template.content; the template-content recursion
1838
+ above iterates the content but never inspected shadowRoot).
1839
+ Walk it explicitly. The nodeType guard avoids reading
1840
+ shadowRoot off text / comment / CDATA / PI nodes that the
1841
+ iterator also surfaces. */
1842
+ const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
1843
+ if (shadowNodeType === NODE_TYPE.element) {
1844
+ const innerSr = getShadowRoot(shadowNode);
1845
+ if (_isDocumentFragment(innerSr)) {
1846
+ _sanitizeAttachedShadowRoots(innerSr);
1847
+ _sanitizeShadowDOM2(innerSr);
1848
+ }
1849
+ }
1850
+ }
1851
+ /* Execute a hook if present */
1852
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1853
+ };
1854
+ /**
1855
+ * _sanitizeAttachedShadowRoots
1856
+ *
1857
+ * Walks `root` and feeds every attached shadow root we encounter into
1858
+ * the existing _sanitizeShadowDOM pipeline. The default node iterator
1859
+ * does not descend into shadow trees, so nodes inside an attached
1860
+ * shadow root would otherwise be skipped entirely.
1861
+ *
1862
+ * Two real input paths put attached shadow roots in front of us:
1863
+ * 1. IN_PLACE on a DOM node that already has shadow roots attached.
1864
+ * 2. DOM-node input where importNode(dirty, true) deep-clones the
1865
+ * shadow root because it was created with `clonable: true`.
1866
+ *
1867
+ * This pass runs once, up front, so the main iteration loop (and the
1868
+ * existing _sanitizeShadowDOM template-content recursion) stay
1869
+ * untouched — string-input paths are not affected.
1870
+ *
1871
+ * @param root the subtree root to walk for attached shadow roots
1872
+ */
1873
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
1874
+ /* Iterative (explicit stack) rather than per-child recursion. DOM APIs
1875
+ impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
1876
+ built straight into the DOM — the IN_PLACE surface) deeper than the JS
1877
+ call-stack budget would otherwise overflow native recursion here and
1878
+ throw at the IN_PLACE entry pre-pass, before a single node is
1879
+ sanitized, leaving the caller's live tree untouched (fail-open). See
1880
+ campaign-3 F4. A heap stack keeps depth off the call stack.
1881
+ Each work item is either a node to descend into, or a deferred
1882
+ `_sanitizeShadowDOM` for an already-walked shadow root. The deferred
1883
+ form preserves the original post-order discipline: a shadow root's
1884
+ nested shadow roots are discovered before the outer shadow is
1885
+ sanitized (which may remove hosts). Pushes are in reverse of the
1886
+ desired processing order (LIFO): template content, then children, then
1887
+ the shadow-sanitize, then the shadow walk — so the order matches the
1888
+ previous recursion exactly. */
1889
+ const stack = [{
1890
+ node: root,
1891
+ shadow: null
1892
+ }];
1893
+ while (stack.length > 0) {
1894
+ const item = stack.pop();
1895
+ /* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
1896
+ if (item.shadow) {
1897
+ _sanitizeShadowDOM2(item.shadow);
1898
+ continue;
1899
+ }
1900
+ const node = item.node;
1901
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
1902
+ const isElement = nodeType === NODE_TYPE.element;
1903
+ /* (pushed last → processed first) Children, snapshotted in reverse so
1904
+ the first child is processed first. Snapshotting matters because a
1905
+ hook may detach siblings mid-walk. */
1906
+ const childNodes = getChildNodes(node);
1907
+ if (childNodes) {
1908
+ for (let i = childNodes.length - 1; i >= 0; --i) {
1909
+ stack.push({
1910
+ node: childNodes[i],
1911
+ shadow: null
1912
+ });
1913
+ }
1914
+ }
1915
+ /* (pushed before children → processed after them, matching the old
1916
+ "template content last" order) When the node is a <template>,
1917
+ descend into its content. */
1918
+ if (isElement) {
1919
+ const rootName = getNodeName ? getNodeName(node) : null;
1920
+ if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
1921
+ const content = node.content;
1922
+ if (_isDocumentFragment(content)) {
1923
+ stack.push({
1924
+ node: content,
1925
+ shadow: null
1926
+ });
1927
+ }
1928
+ }
1929
+ }
1930
+ /* Shadow root (processed first): walk its subtree, then sanitise it.
1931
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
1932
+ rather than `instanceof DocumentFragment`, which is realm-bound and
1933
+ silently skipped foreign-realm shadow roots (e.g.
1934
+ iframe.contentDocument attachShadow). */
1935
+ if (isElement) {
1936
+ const sr = getShadowRoot(node);
1937
+ if (_isDocumentFragment(sr)) {
1938
+ /* Push the deferred sanitise first so it pops after the shadow
1939
+ walk we push next, i.e. nested shadow roots are discovered
1940
+ before this one is sanitised. */
1941
+ stack.push({
1942
+ node: null,
1943
+ shadow: sr
1944
+ }, {
1945
+ node: sr,
1946
+ shadow: null
1947
+ });
1948
+ }
1949
+ }
1950
+ }
1951
+ };
1952
+ // eslint-disable-next-line complexity
1953
+ DOMPurify.sanitize = function (dirty) {
1954
+ let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1955
+ let body = null;
1956
+ let importedNode = null;
1957
+ let currentNode = null;
1958
+ let returnNode = null;
1959
+ /* Make sure we have a string to sanitize.
1960
+ DO NOT return early, as this will return the wrong type if
1961
+ the user has requested a DOM object rather than a string */
1962
+ IS_EMPTY_INPUT = !dirty;
1963
+ if (IS_EMPTY_INPUT) {
1964
+ dirty = '<!-->';
1965
+ }
1966
+ /* Stringify, in case dirty is an object */
1967
+ if (typeof dirty !== 'string' && !_isNode(dirty)) {
1968
+ dirty = stringifyValue(dirty);
1969
+ if (typeof dirty !== 'string') {
1970
+ throw typeErrorCreate('dirty is not a string, aborting');
1971
+ }
1972
+ }
1973
+ /* Return dirty HTML if DOMPurify cannot run */
1974
+ if (!DOMPurify.isSupported) {
1975
+ return dirty;
1976
+ }
1977
+ /* Assign config vars */
1978
+ if (SET_CONFIG) {
1979
+ /* Persistent setConfig() path: _parseConfig is skipped, so the sets are
1980
+ * not re-derived per call. Restore them from the pristine bindings
1981
+ * captured at setConfig() time so a previous call's hook clone (mutated
1982
+ * below) does not carry over. */
1983
+ ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
1984
+ ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
1985
+ } else {
1986
+ _parseConfig(cfg);
1987
+ }
1988
+ /* Clone the hook-mutable allowlists before the walk whenever an
1989
+ * uponSanitize* hook is registered. The hook event exposes ALLOWED_TAGS
1990
+ * and ALLOWED_ATTR by reference (as allowedTags / allowedAttributes), so
1991
+ * a hook that widens them would otherwise mutate the shared set
1992
+ * permanently: across later calls and across every element. Cloning per
1993
+ * walk keeps documented in-call widening working while scoping it to the
1994
+ * call. A single guard for both config paths - the per-call path rebinds
1995
+ * the sets in _parseConfig each call, the persistent path restores them
1996
+ * from the captured bindings just above - so the two cannot diverge. */
1997
+ if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) {
1998
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
1999
+ }
2000
+ if (hooks.uponSanitizeAttribute.length > 0) {
2001
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
2002
+ }
2003
+ /* Clean up removed elements */
2004
+ DOMPurify.removed = [];
2005
+ /* Resolve IN_PLACE for this call without mutating persistent config.
2006
+ Writing the IN_PLACE closure variable here leaks under setConfig(),
2007
+ where _parseConfig is skipped on later calls: a single string call would
2008
+ disable in-place mode for every subsequent node call, returning a
2009
+ sanitized copy while leaving the caller's node — which in-place callers
2010
+ keep using and whose return value they ignore — unsanitized. REPORT-2. */
2011
+ const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
2012
+ if (inPlace) {
2013
+ /* Do some early pre-sanitization to avoid unsafe root nodes.
2014
+ Read nodeName through the cached prototype getter — a clobbering
2015
+ child named "nodeName" on the form root would otherwise shadow
2016
+ the property and let this check skip the root-allowlist
2017
+ validation entirely. */
2018
+ const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
2019
+ if (typeof nn === 'string') {
2020
+ const tagName = transformCaseFunc(nn);
2021
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
2022
+ throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
2023
+ }
2024
+ }
2025
+ /* Pre-flight the root through _isClobbered. The iterator-driven
2026
+ removal path can not detach a parent-less root: _forceRemove
2027
+ falls through to Element.prototype.remove(), which per spec
2028
+ is a no-op on a node with no parent. A clobbered root would
2029
+ then survive the main loop with its attributes uninspected,
2030
+ because _sanitizeAttributes early-returns on _isClobbered. The
2031
+ result would be an attacker-controlled form, complete with any
2032
+ event-handler attributes the caller passed in, handed back to
2033
+ the application unsanitized. Refuse to sanitize such a root
2034
+ the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
2035
+ if (_isClobbered(dirty)) {
2036
+ throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
2037
+ }
2038
+ /* Sanitize attached shadow roots before the main iterator runs.
2039
+ The iterator does not descend into shadow trees. Same fail-closed
2040
+ barrier as the main walk (campaign-3 F2): a custom-element reaction
2041
+ inside a shadow root could abort this pre-pass before the walk runs,
2042
+ which would otherwise leave the entire live tree unsanitized. */
2043
+ try {
2044
+ _sanitizeAttachedShadowRoots(dirty);
2045
+ } catch (error) {
2046
+ _neutralizeRoot(dirty);
2047
+ throw error;
2048
+ }
2049
+ } else if (_isNode(dirty)) {
2050
+ /* If dirty is a DOM element, append to an empty document to avoid
2051
+ elements being stripped by the parser */
2052
+ body = _initDocument('<!---->');
2053
+ importedNode = body.ownerDocument.importNode(dirty, true);
2054
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
2055
+ /* Node is already a body, use as is */
2056
+ body = importedNode;
2057
+ } else if (importedNode.nodeName === 'HTML') {
2058
+ body = importedNode;
2059
+ } else {
2060
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
2061
+ body.appendChild(importedNode);
2062
+ }
2063
+ /* Clonable shadow roots are deep-cloned by importNode(); sanitize
2064
+ them before the main iterator runs, since the iterator does not
2065
+ descend into shadow trees. The walk routes every read through a
2066
+ cached prototype getter so clobbering descendants on a form root
2067
+ cannot hide a shadow host from this pass. */
2068
+ _sanitizeAttachedShadowRoots(importedNode);
2069
+ } else {
2070
+ /* Exit directly if we have nothing to do */
2071
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
2072
+ // eslint-disable-next-line unicorn/prefer-includes
2073
+ dirty.indexOf('<') === -1) {
2074
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
2075
+ }
2076
+ /* Initialize the document to work on */
2077
+ body = _initDocument(dirty);
2078
+ /* Check we have a DOM node from the data */
2079
+ if (!body) {
2080
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
2081
+ }
2082
+ }
2083
+ /* Remove first element node (ours) if FORCE_BODY is set */
2084
+ if (body && FORCE_BODY) {
2085
+ _forceRemove(body.firstChild);
2086
+ }
2087
+ /* Get node iterator */
2088
+ const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
2089
+ /* Now start iterating over the created document.
2090
+ The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
2091
+ engine/custom-element mutation can detach a node mid-walk so
2092
+ `_forceRemove`'s parentless guard throws, aborting the loop. Without the
2093
+ barrier the caller's in-place tree would be left half-sanitized with the
2094
+ unvisited tail still armed. On any throw we fail closed — strip the
2095
+ in-place root bare — then rethrow so the existing throw contract is
2096
+ preserved. (String/DOM-copy paths never return the partial body, so the
2097
+ propagating throw is already fail-closed there.) */
2098
+ try {
2099
+ while (currentNode = nodeIterator.nextNode()) {
2100
+ /* Sanitize tags and elements */
2101
+ _sanitizeElements(currentNode);
2102
+ /* Check attributes next */
2103
+ _sanitizeAttributes(currentNode);
2104
+ /* Shadow DOM detected, sanitize it.
2105
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
2106
+ instead of instanceof, so foreign-realm <template>.content is
2107
+ walked correctly. */
2108
+ if (_isDocumentFragment(currentNode.content)) {
2109
+ _sanitizeShadowDOM2(currentNode.content);
2110
+ }
2111
+ }
2112
+ } catch (error) {
2113
+ if (inPlace) {
2114
+ _neutralizeRoot(dirty);
2115
+ }
2116
+ throw error;
2117
+ }
2118
+ /* If we sanitized `dirty` in-place, return it. */
2119
+ if (inPlace) {
2120
+ /* Fail-closed completion of the audit-5 F1 fix: every node removed from
2121
+ the caller's live tree is detached but may still hold a queued
2122
+ resource-event handler that fires in page scope after we return. The
2123
+ move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
2124
+ non-allow-listed attributes off every other removed subtree (clobber,
2125
+ mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
2126
+ cancelled before any event can fire. Runs synchronously, pre-return. */
2127
+ arrayForEach(DOMPurify.removed, entry => {
2128
+ if (entry.element) {
2129
+ _neutralizeSubtree(entry.element);
2130
+ }
2131
+ });
2132
+ if (SAFE_FOR_TEMPLATES) {
2133
+ _scrubTemplateExpressions2(dirty);
2134
+ }
2135
+ return dirty;
2136
+ }
2137
+ /* Return sanitized string or DOM */
2138
+ if (RETURN_DOM) {
2139
+ if (SAFE_FOR_TEMPLATES) {
2140
+ _scrubTemplateExpressions2(body);
2141
+ }
2142
+ if (RETURN_DOM_FRAGMENT) {
2143
+ returnNode = createDocumentFragment.call(body.ownerDocument);
2144
+ while (body.firstChild) {
2145
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
2146
+ returnNode.appendChild(body.firstChild);
2147
+ }
2148
+ } else {
2149
+ returnNode = body;
2150
+ }
2151
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
2152
+ /*
2153
+ AdoptNode() is not used because internal state is not reset
2154
+ (e.g. the past names map of a HTMLFormElement), this is safe
2155
+ in theory but we would rather not risk another attack vector.
2156
+ The state that is cloned by importNode() is explicitly defined
2157
+ by the specs.
2158
+ */
2159
+ returnNode = importNode.call(originalDocument, returnNode, true);
2160
+ }
2161
+ return returnNode;
2162
+ }
2163
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
2164
+ /* Serialize doctype if allowed */
2165
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
2166
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
2167
+ }
2168
+ /* Sanitize final string template-safe */
2169
+ if (SAFE_FOR_TEMPLATES) {
2170
+ serializedHTML = _stripTemplateExpressions(serializedHTML);
2171
+ }
2172
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
2173
+ };
2174
+ DOMPurify.setConfig = function () {
2175
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2176
+ _parseConfig(cfg);
2177
+ SET_CONFIG = true;
2178
+ SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
2179
+ SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
2180
+ };
2181
+ DOMPurify.clearConfig = function () {
2182
+ CONFIG = null;
2183
+ SET_CONFIG = false;
2184
+ SET_CONFIG_ALLOWED_TAGS = null;
2185
+ SET_CONFIG_ALLOWED_ATTR = null;
2186
+ // Drop any caller-supplied Trusted Types policy so it cannot poison later
2187
+ // `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
2188
+ // never recreated — Trusted Types throws on duplicate names) is restored by
2189
+ // the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
2190
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
2191
+ emptyHTML = '';
2192
+ };
2193
+ DOMPurify.isValidAttribute = function (tag, attr, value) {
2194
+ /* Initialize shared config vars if necessary. */
2195
+ if (!CONFIG) {
2196
+ _parseConfig({});
2197
+ }
2198
+ const lcTag = transformCaseFunc(tag);
2199
+ const lcName = transformCaseFunc(attr);
2200
+ return _isValidAttribute(lcTag, lcName, value);
2201
+ };
2202
+ DOMPurify.addHook = function (entryPoint, hookFunction) {
2203
+ if (typeof hookFunction !== 'function') {
2204
+ return;
2205
+ }
2206
+ /* Reject unknown entry points. Without this, a non-hook key (e.g.
2207
+ * '__proto__') indexes off the prototype chain rather than a real
2208
+ * hook array, and arrayPush then writes to Object.prototype. Guard
2209
+ * with an own-property check against the known hook names. */
2210
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2211
+ return;
2212
+ }
2213
+ arrayPush(hooks[entryPoint], hookFunction);
2214
+ };
2215
+ DOMPurify.removeHook = function (entryPoint, hookFunction) {
2216
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2217
+ return undefined;
2218
+ }
2219
+ if (hookFunction !== undefined) {
2220
+ const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
2221
+ return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
2222
+ }
2223
+ return arrayPop(hooks[entryPoint]);
2224
+ };
2225
+ DOMPurify.removeHooks = function (entryPoint) {
2226
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
2227
+ return;
2228
+ }
2229
+ hooks[entryPoint] = [];
2230
+ };
2231
+ DOMPurify.removeAllHooks = function () {
2232
+ hooks = _createHooksMap();
2233
+ };
2234
+ return DOMPurify;
2235
+ }
2236
+ var purify = createDOMPurify();
2237
+
2238
+ const sanitizeSvg = (svg) => {
2239
+ return purify.sanitize(svg, {
2240
+ USE_PROFILES: { svg: true },
2241
+ FORBID_ATTR: ['height', 'width'],
2242
+ });
2243
+ };
2244
+
2245
+ exports.sanitizeSvg = sanitizeSvg;