@lango-project/lango-client 0.2.1 → 0.4.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 (240) hide show
  1. package/LICENSE +1 -0
  2. package/NOTICE +5 -1
  3. package/README.md +603 -906
  4. package/cli/.lango/localization.mjs +108 -0
  5. package/{dist/node → cli}/.lango/runtime.mjs +120 -20
  6. package/cli/.lango/vendor/i18next.LICENSE +21 -0
  7. package/cli/.lango/vendor/i18next.mjs +2434 -0
  8. package/cli/create.mjs +62 -0
  9. package/cli/create.mjs.map +1 -0
  10. package/dist/.lango/localization.mjs +108 -0
  11. package/dist/.lango/runtime.mjs +120 -20
  12. package/dist/.lango/vendor/i18next.LICENSE +21 -0
  13. package/dist/.lango/vendor/i18next.mjs +2434 -0
  14. package/dist/accordion.mjs +277 -0
  15. package/dist/accordion.mjs.map +1 -0
  16. package/dist/activities.mjs +185 -0
  17. package/dist/activities.mjs.map +1 -0
  18. package/dist/app.mjs +671 -0
  19. package/dist/app.mjs.map +1 -0
  20. package/dist/boot.mjs +24 -0
  21. package/dist/boot.mjs.map +1 -0
  22. package/dist/bootstrap-LICENSE +21 -0
  23. package/dist/bootstrap.min.css +6 -0
  24. package/dist/bootstrap.min.css.map +1 -0
  25. package/dist/button.mjs +77 -0
  26. package/dist/button.mjs.map +1 -0
  27. package/dist/chip.mjs +134 -0
  28. package/dist/chip.mjs.map +1 -0
  29. package/dist/client.css +102 -0
  30. package/dist/collections.mjs +77 -0
  31. package/dist/collections.mjs.map +1 -0
  32. package/dist/combo_box.mjs +408 -0
  33. package/dist/combo_box.mjs.map +1 -0
  34. package/dist/content.mjs +123 -0
  35. package/dist/content.mjs.map +1 -0
  36. package/dist/control.mjs +141 -0
  37. package/dist/control.mjs.map +1 -0
  38. package/dist/date_input.mjs +242 -0
  39. package/dist/date_input.mjs.map +1 -0
  40. package/dist/dimensions.mjs +102 -0
  41. package/dist/dimensions.mjs.map +1 -0
  42. package/dist/error_reporter.mjs +136 -0
  43. package/dist/error_reporter.mjs.map +1 -0
  44. package/dist/fields.mjs +454 -0
  45. package/dist/fields.mjs.map +1 -0
  46. package/dist/file_input.mjs +227 -0
  47. package/dist/file_input.mjs.map +1 -0
  48. package/dist/form.mjs +272 -0
  49. package/dist/form.mjs.map +1 -0
  50. package/dist/heartbeat.mjs +167 -254
  51. package/dist/heartbeat.mjs.map +1 -1
  52. package/dist/index.html +18 -0
  53. package/dist/indicators.mjs +127 -0
  54. package/dist/indicators.mjs.map +1 -0
  55. package/dist/input_changes.mjs +58 -0
  56. package/dist/input_changes.mjs.map +1 -0
  57. package/dist/input_group.mjs +38 -0
  58. package/dist/input_group.mjs.map +1 -0
  59. package/dist/layouts.mjs +195 -0
  60. package/dist/layouts.mjs.map +1 -0
  61. package/dist/library.mjs +130 -807
  62. package/dist/library.mjs.map +1 -1
  63. package/dist/longpoll.mjs +254 -0
  64. package/dist/longpoll.mjs.map +1 -0
  65. package/dist/main.mjs +147 -0
  66. package/dist/main.mjs.map +1 -0
  67. package/dist/markdown.mjs +61 -0
  68. package/dist/markdown.mjs.map +1 -0
  69. package/dist/menus.mjs +468 -0
  70. package/dist/menus.mjs.map +1 -0
  71. package/dist/navigation.mjs +260 -410
  72. package/dist/navigation.mjs.map +1 -1
  73. package/dist/numeric_input.mjs +181 -0
  74. package/dist/numeric_input.mjs.map +1 -0
  75. package/dist/otp_input.mjs +113 -0
  76. package/dist/otp_input.mjs.map +1 -0
  77. package/dist/presentations.mjs +852 -0
  78. package/dist/presentations.mjs.map +1 -0
  79. package/dist/renderer.mjs +295 -0
  80. package/dist/renderer.mjs.map +1 -0
  81. package/dist/rich_content.mjs +99 -0
  82. package/dist/rich_content.mjs.map +1 -0
  83. package/dist/table_scope.mjs +166 -0
  84. package/dist/table_scope.mjs.map +1 -0
  85. package/dist/tables.mjs +1052 -0
  86. package/dist/tables.mjs.map +1 -0
  87. package/dist/tabs.mjs +205 -0
  88. package/dist/tabs.mjs.map +1 -0
  89. package/dist/templates.mjs +46 -0
  90. package/dist/templates.mjs.map +1 -0
  91. package/dist/vendor/DOMPurify-LICENSE +202 -0
  92. package/dist/vendor/dompurify.mjs +2454 -0
  93. package/dist/vendor/flatpickr-LICENSE.md +21 -0
  94. package/dist/vendor/flatpickr.min.css +13 -0
  95. package/dist/vendor/flatpickr.mjs +2340 -0
  96. package/dist/vendor/flatpickr.mjs.map +7 -0
  97. package/dist/vendor/marked-LICENSE.md +44 -0
  98. package/dist/vendor/marked.esm.js.map +7 -0
  99. package/dist/vendor/marked.mjs +85 -0
  100. package/dist/vendor/purify.es.mjs.map +1 -0
  101. package/dist/widgets.mjs +197 -0
  102. package/dist/widgets.mjs.map +1 -0
  103. package/docs/implementation.md +93 -0
  104. package/package.json +25 -43
  105. package/src/accordion.lango +198 -0
  106. package/src/activities.lango +132 -0
  107. package/src/app.lango +540 -0
  108. package/src/boot.lango +12 -0
  109. package/src/button.lango +49 -0
  110. package/src/chip.lango +94 -0
  111. package/src/collections.lango +46 -0
  112. package/src/combo_box.lango +298 -0
  113. package/src/content.lango +75 -0
  114. package/src/control.lango +103 -0
  115. package/src/create.lango +42 -0
  116. package/src/date_input.lango +215 -0
  117. package/src/dimensions.lango +65 -0
  118. package/src/error_reporter.lango +95 -0
  119. package/src/fields.lango +327 -0
  120. package/src/file_input.lango +175 -0
  121. package/src/form.lango +195 -0
  122. package/src/heartbeat.lango +136 -199
  123. package/src/indicators.lango +94 -0
  124. package/src/input_changes.lango +33 -0
  125. package/src/input_group.lango +22 -0
  126. package/src/layouts.lango +137 -0
  127. package/src/library.lango +194 -599
  128. package/src/longpoll.lango +187 -0
  129. package/src/main.lango +118 -0
  130. package/src/markdown.lango +48 -0
  131. package/src/menus.lango +336 -0
  132. package/src/navigation.lango +209 -299
  133. package/src/numeric_input.lango +131 -0
  134. package/src/otp_input.lango +83 -0
  135. package/src/presentations.lango +617 -0
  136. package/src/renderer.lango +296 -0
  137. package/src/rich_content.lango +66 -0
  138. package/src/table_scope.lango +119 -0
  139. package/src/tables.lango +786 -0
  140. package/src/tabs.lango +144 -0
  141. package/src/templates.lango +29 -0
  142. package/src/widgets.lango +141 -0
  143. package/web/client.css +102 -0
  144. package/web/index.html +18 -0
  145. package/dist/application.mjs +0 -429
  146. package/dist/application.mjs.map +0 -1
  147. package/dist/coordinator.mjs +0 -91
  148. package/dist/coordinator.mjs.map +0 -1
  149. package/dist/demo.mjs +0 -110
  150. package/dist/demo.mjs.map +0 -1
  151. package/dist/demo_controls.mjs +0 -59
  152. package/dist/demo_controls.mjs.map +0 -1
  153. package/dist/errors.mjs +0 -201
  154. package/dist/errors.mjs.map +0 -1
  155. package/dist/form_state.mjs +0 -266
  156. package/dist/form_state.mjs.map +0 -1
  157. package/dist/inheritance.mjs +0 -240
  158. package/dist/inheritance.mjs.map +0 -1
  159. package/dist/input_values.mjs +0 -65
  160. package/dist/input_values.mjs.map +0 -1
  161. package/dist/node/.lango/xmldom/conventions.js +0 -429
  162. package/dist/node/.lango/xmldom/dom-parser.js +0 -591
  163. package/dist/node/.lango/xmldom/dom.js +0 -3759
  164. package/dist/node/.lango/xmldom/entities.js +0 -2171
  165. package/dist/node/.lango/xmldom/errors.js +0 -205
  166. package/dist/node/.lango/xmldom/grammar.js +0 -559
  167. package/dist/node/.lango/xmldom/index.js +0 -41
  168. package/dist/node/.lango/xmldom/package.json +0 -1
  169. package/dist/node/.lango/xmldom/sax.js +0 -983
  170. package/dist/node/.lango/xmldom.LICENSE.md +0 -8
  171. package/dist/node/browser_host.mjs +0 -351
  172. package/dist/node/browser_host.mjs.map +0 -1
  173. package/dist/node/create_app.mjs +0 -118
  174. package/dist/node/create_app.mjs.map +0 -1
  175. package/dist/presentation.mjs +0 -89
  176. package/dist/presentation.mjs.map +0 -1
  177. package/dist/protocol.mjs +0 -706
  178. package/dist/protocol.mjs.map +0 -1
  179. package/dist/session.mjs +0 -471
  180. package/dist/session.mjs.map +0 -1
  181. package/dist/tokens.mjs +0 -298
  182. package/dist/tokens.mjs.map +0 -1
  183. package/examples/contacts.lango +0 -293
  184. package/examples/contacts_flow.lango +0 -174
  185. package/examples/contacts_store.lango +0 -109
  186. package/examples/contacts_store_test.lango +0 -65
  187. package/examples/demo.css +0 -87
  188. package/examples/demo_test.lango +0 -356
  189. package/examples/index.html +0 -32
  190. package/examples/pages.lango +0 -174
  191. package/examples/server.lango +0 -189
  192. package/examples/worker.lango +0 -142
  193. package/src/application.lango +0 -327
  194. package/src/browser_host.lango +0 -276
  195. package/src/coordinator.lango +0 -57
  196. package/src/demo.lango +0 -110
  197. package/src/demo_controls.lango +0 -53
  198. package/src/errors.lango +0 -149
  199. package/src/errors_test.lango +0 -157
  200. package/src/form_state.lango +0 -168
  201. package/src/heartbeat_test.lango +0 -479
  202. package/src/inheritance.lango +0 -167
  203. package/src/input_values.lango +0 -37
  204. package/src/logout_test.lango +0 -564
  205. package/src/navigation_test.lango +0 -556
  206. package/src/presentation.lango +0 -55
  207. package/src/protocol.lango +0 -787
  208. package/src/renderer_test.lango +0 -2047
  209. package/src/session.lango +0 -343
  210. package/src/session_test.lango +0 -455
  211. package/src/tabs_test.lango +0 -216
  212. package/src/tokens.lango +0 -215
  213. package/template/.vscode/extensions.json +0 -3
  214. package/template/.vscode/settings.json +0 -9
  215. package/template/README.md +0 -44
  216. package/template/gitignore +0 -4
  217. package/template/package.json +0 -22
  218. package/template/public/app.css +0 -10
  219. package/template/public/index.html +0 -24
  220. package/template/src/client.lango +0 -78
  221. package/template/src/pages.lango +0 -55
  222. package/template/src/server.lango +0 -24
  223. package/template/src/worker.lango +0 -77
  224. package/template/test/app.lango +0 -9
  225. package/tools/browser_runner.lango +0 -32
  226. package/tools/browser_test.lango +0 -343
  227. package/tools/create_app.lango +0 -88
  228. package/tools/create_app_test.lango +0 -43
  229. package/tools/starter_test.lango +0 -227
  230. /package/{dist/node → cli}/.lango/bignumber.mjs +0 -0
  231. /package/{dist → cli}/.lango/xmldom/conventions.js +0 -0
  232. /package/{dist → cli}/.lango/xmldom/dom-parser.js +0 -0
  233. /package/{dist → cli}/.lango/xmldom/dom.js +0 -0
  234. /package/{dist → cli}/.lango/xmldom/entities.js +0 -0
  235. /package/{dist → cli}/.lango/xmldom/errors.js +0 -0
  236. /package/{dist → cli}/.lango/xmldom/grammar.js +0 -0
  237. /package/{dist → cli}/.lango/xmldom/index.js +0 -0
  238. /package/{dist → cli}/.lango/xmldom/package.json +0 -0
  239. /package/{dist → cli}/.lango/xmldom/sax.js +0 -0
  240. /package/{dist → cli}/.lango/xmldom.LICENSE.md +0 -0
@@ -0,0 +1,2454 @@
1
+ /*! @license DOMPurify 3.4.18 | (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.18/LICENSE */
2
+ function _OverloadYield(e, d) {
3
+ this.v = e, this.k = d;
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, n, i, u, a = [], f = !0, o = !1;
17
+ try {
18
+ if (i = (t = t.call(r)).next, 0 === l) {
19
+ if (Object(t) !== t) return;
20
+ f = !1;
21
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
22
+ } catch (r) {
23
+ o = !0, n = r;
24
+ } finally {
25
+ try {
26
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
27
+ } finally {
28
+ if (o) throw n;
29
+ }
30
+ }
31
+ return a;
32
+ }
33
+ }
34
+ function _nonIterableRest() {
35
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
36
+ }
37
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
38
+ function _slicedToArray(r, e) {
39
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
40
+ }
41
+ function _unsupportedIterableToArray(r, a) {
42
+ if (r) {
43
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
44
+ var t = {}.toString.call(r).slice(8, -1);
45
+ 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;
46
+ }
47
+ }
48
+ function AsyncGenerator(e) {
49
+ var t, n;
50
+ function resume(t, n) {
51
+ try {
52
+ var r = e[t](n), o = r.value, u = o instanceof _OverloadYield;
53
+ Promise.resolve(u ? o.v : o).then(function(n) {
54
+ if (u) {
55
+ var i = "return" === t && o.k ? t : "next";
56
+ if (!o.k || n.done) return resume(i, n);
57
+ n = e[i](n).value;
58
+ }
59
+ settle(!!r.done, n);
60
+ }, function(e) {
61
+ resume("throw", e);
62
+ });
63
+ } catch (e) {
64
+ settle(2, e);
65
+ }
66
+ }
67
+ function settle(e, r) {
68
+ 2 === e ? t.reject(r) : t.resolve({
69
+ value: r,
70
+ done: e
71
+ }), (t = t.next) ? resume(t.key, t.arg) : n = null;
72
+ }
73
+ this._invoke = function(e, r) {
74
+ return new Promise(function(o, u) {
75
+ var i = {
76
+ key: e,
77
+ arg: r,
78
+ resolve: o,
79
+ reject: u,
80
+ next: null
81
+ };
82
+ n ? n = n.next = i : (t = n = i, resume(e, r));
83
+ });
84
+ }, "function" != typeof e.return && (this.return = void 0);
85
+ }
86
+ AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function() {
87
+ return this;
88
+ }, AsyncGenerator.prototype.next = function(e) {
89
+ return this._invoke("next", e);
90
+ }, AsyncGenerator.prototype.throw = function(e) {
91
+ return this._invoke("throw", e);
92
+ }, AsyncGenerator.prototype.return = function(e) {
93
+ return this._invoke("return", e);
94
+ };
95
+ const entries = Object.entries;
96
+ const objectKeys = Object.keys;
97
+ const setPrototypeOf = Object.setPrototypeOf;
98
+ const isFrozen = Object.isFrozen;
99
+ const getPrototypeOf = Object.getPrototypeOf;
100
+ const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
101
+ let freeze = Object.freeze;
102
+ let seal = Object.seal;
103
+ let create = Object.create;
104
+ let _ref = typeof Reflect !== "undefined" && Reflect;
105
+ let apply = _ref.apply;
106
+ let construct = _ref.construct;
107
+ if (!freeze) freeze = function freeze(x) {
108
+ return x;
109
+ };
110
+ if (!seal) seal = function seal(x) {
111
+ return x;
112
+ };
113
+ if (!apply) apply = function apply(func, thisArg) {
114
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) args[_key - 2] = arguments[_key];
115
+ return func.apply(thisArg, args);
116
+ };
117
+ if (!construct) construct = function construct(Func) {
118
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) args[_key2 - 1] = arguments[_key2];
119
+ return new Func(...args);
120
+ };
121
+ const arrayForEach = unapply(Array.prototype.forEach);
122
+ const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
123
+ const arrayPop = unapply(Array.prototype.pop);
124
+ const arrayPush = unapply(Array.prototype.push);
125
+ const arraySlice = unapply(Array.prototype.slice);
126
+ const arraySplice = unapply(Array.prototype.splice);
127
+ const arrayIsArray = Array.isArray;
128
+ const setCreate = unconstruct(Set);
129
+ const setAdd = unapply(Set.prototype.add);
130
+ const setHas = unapply(Set.prototype.has);
131
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
132
+ const stringToString = unapply(String.prototype.toString);
133
+ const stringMatch = unapply(String.prototype.match);
134
+ const stringReplace = unapply(String.prototype.replace);
135
+ const stringIndexOf = unapply(String.prototype.indexOf);
136
+ const stringTrim = unapply(String.prototype.trim);
137
+ const numberToString = unapply(Number.prototype.toString);
138
+ const booleanToString = unapply(Boolean.prototype.toString);
139
+ const bigintToString = typeof BigInt === "undefined" ? null : unapply(BigInt.prototype.toString);
140
+ const symbolToString = typeof Symbol === "undefined" ? null : unapply(Symbol.prototype.toString);
141
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
142
+ const objectToString = unapply(Object.prototype.toString);
143
+ const regExpTestRaw = RegExp.prototype.test;
144
+ const regExpTest = function regExpTest(regExp, value) {
145
+ if (regExp instanceof RegExp) regExp.lastIndex = 0;
146
+ return apply(regExpTestRaw, regExp, [value]);
147
+ };
148
+ const typeErrorCreate = unconstruct(TypeError);
149
+ /**
150
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
151
+ *
152
+ * @param func - The function to be wrapped and called.
153
+ * @returns A new function that calls the given function with a specified thisArg and arguments.
154
+ */
155
+ function unapply(func) {
156
+ return function(thisArg) {
157
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) args[_key3 - 1] = arguments[_key3];
158
+ return apply(func, thisArg, args);
159
+ };
160
+ }
161
+ /**
162
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
163
+ *
164
+ * @param func - The constructor function to be wrapped and called.
165
+ * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
166
+ */
167
+ function unconstruct(Func) {
168
+ return function() {
169
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) args[_key4] = arguments[_key4];
170
+ return construct(Func, args);
171
+ };
172
+ }
173
+ /**
174
+ * Add properties to a lookup table
175
+ *
176
+ * @param set - The set to which elements will be added.
177
+ * @param array - The array containing elements to be added to the set.
178
+ * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
179
+ * @returns The modified set with added elements.
180
+ */
181
+ function addToSet(set, array) {
182
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
183
+ if (setPrototypeOf) setPrototypeOf(set, null);
184
+ if (!arrayIsArray(array)) return set;
185
+ let l = array.length;
186
+ while (l--) {
187
+ let element = array[l];
188
+ if (typeof element === "string") {
189
+ const lcElement = transformCaseFunc(element);
190
+ if (lcElement !== element) {
191
+ if (!isFrozen(array)) array[l] = lcElement;
192
+ element = lcElement;
193
+ }
194
+ }
195
+ set[element] = true;
196
+ }
197
+ return set;
198
+ }
199
+ /**
200
+ * Clean up an array to harden against CSPP
201
+ *
202
+ * @param array - The array to be cleaned.
203
+ * @returns The cleaned version of the array
204
+ */
205
+ function cleanArray(array) {
206
+ for (let index = 0; index < array.length; index++) if (!objectHasOwnProperty(array, index)) array[index] = null;
207
+ return array;
208
+ }
209
+ /**
210
+ * Shallow clone an object
211
+ *
212
+ * @param object - The object to be cloned.
213
+ * @returns A new object that copies the original.
214
+ */
215
+ function clone(object) {
216
+ const newObject = create(null);
217
+ for (const _ref2 of entries(object)) {
218
+ var _ref3 = _slicedToArray(_ref2, 2);
219
+ const property = _ref3[0];
220
+ const value = _ref3[1];
221
+ if (objectHasOwnProperty(object, property)) {
222
+ if (arrayIsArray(value)) newObject[property] = cleanArray(value);
223
+ else if (value && typeof value === "object" && value.constructor === Object) newObject[property] = clone(value);
224
+ else newObject[property] = value;
225
+ }
226
+ }
227
+ return newObject;
228
+ }
229
+ /**
230
+ * Copy a flat lookup table
231
+ *
232
+ * @param set - The set to copy.
233
+ * @returns A new prototype-free set with the same entries.
234
+ */
235
+ function cloneSet(set) {
236
+ const newSet = create(null);
237
+ const keys = objectKeys(set);
238
+ let l = keys.length;
239
+ while (l--) newSet[keys[l]] = set[keys[l]];
240
+ return newSet;
241
+ }
242
+ /**
243
+ * Convert non-node values into strings without depending on direct property access.
244
+ *
245
+ * @param value - The value to stringify.
246
+ * @returns A string representation of the provided value.
247
+ */
248
+ function stringifyValue(value) {
249
+ switch (typeof value) {
250
+ case "string": return value;
251
+ case "number": return numberToString(value);
252
+ case "boolean": return booleanToString(value);
253
+ case "bigint": return bigintToString ? bigintToString(value) : "0";
254
+ case "symbol": return symbolToString ? symbolToString(value) : "Symbol()";
255
+ case "undefined": return objectToString(value);
256
+ case "function":
257
+ case "object": {
258
+ if (value === null) return objectToString(value);
259
+ const valueAsRecord = value;
260
+ const valueToString = lookupGetter(valueAsRecord, "toString");
261
+ if (typeof valueToString === "function") {
262
+ const stringified = valueToString(valueAsRecord);
263
+ return typeof stringified === "string" ? stringified : objectToString(stringified);
264
+ }
265
+ return objectToString(value);
266
+ }
267
+ default: return objectToString(value);
268
+ }
269
+ }
270
+ /**
271
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
272
+ *
273
+ * @param object - The object to look up the getter function in its prototype chain.
274
+ * @param prop - The property name for which to find the getter function.
275
+ * @returns The getter function found in the prototype chain or a fallback function.
276
+ */
277
+ function lookupGetter(object, prop) {
278
+ while (object !== null) {
279
+ const desc = getOwnPropertyDescriptor(object, prop);
280
+ if (desc) {
281
+ if (desc.get) return unapply(desc.get);
282
+ if (typeof desc.value === "function") return unapply(desc.value);
283
+ }
284
+ object = getPrototypeOf(object);
285
+ }
286
+ function fallbackValue() {
287
+ return null;
288
+ }
289
+ return fallbackValue;
290
+ }
291
+ /**
292
+ * Like lookupGetter, but for accessor properties only, and returns null
293
+ * instead of a null-returning fallback when no getter exists on the chain.
294
+ * Lets a caller fall back to a direct property read in environments that
295
+ * lack the getter, where a fallback returning null would be indistinguishable
296
+ * from a legitimate null value (e.g. namespaceURI of a no-namespace element).
297
+ *
298
+ * @param object - The object (usually a prototype) to start the lookup at.
299
+ * @param prop - The accessor property name.
300
+ * @returns The unapplied getter, or null if none was found.
301
+ */
302
+ function lookupAccessor(object, prop) {
303
+ while (object !== null) {
304
+ const desc = getOwnPropertyDescriptor(object, prop);
305
+ if (desc) return desc.get ? unapply(desc.get) : null;
306
+ object = getPrototypeOf(object);
307
+ }
308
+ return null;
309
+ }
310
+ function isRegex(value) {
311
+ if (!value) return false;
312
+ try {
313
+ regExpTest(value, "");
314
+ return true;
315
+ } catch (_unused) {
316
+ return false;
317
+ }
318
+ }
319
+ const html$1 = freeze([
320
+ "a",
321
+ "abbr",
322
+ "acronym",
323
+ "address",
324
+ "area",
325
+ "article",
326
+ "aside",
327
+ "audio",
328
+ "b",
329
+ "bdi",
330
+ "bdo",
331
+ "big",
332
+ "blink",
333
+ "blockquote",
334
+ "body",
335
+ "br",
336
+ "button",
337
+ "canvas",
338
+ "caption",
339
+ "center",
340
+ "cite",
341
+ "code",
342
+ "col",
343
+ "colgroup",
344
+ "content",
345
+ "data",
346
+ "datalist",
347
+ "dd",
348
+ "decorator",
349
+ "del",
350
+ "details",
351
+ "dfn",
352
+ "dialog",
353
+ "dir",
354
+ "div",
355
+ "dl",
356
+ "dt",
357
+ "element",
358
+ "em",
359
+ "fieldset",
360
+ "figcaption",
361
+ "figure",
362
+ "font",
363
+ "footer",
364
+ "form",
365
+ "h1",
366
+ "h2",
367
+ "h3",
368
+ "h4",
369
+ "h5",
370
+ "h6",
371
+ "head",
372
+ "header",
373
+ "hgroup",
374
+ "hr",
375
+ "html",
376
+ "i",
377
+ "img",
378
+ "input",
379
+ "ins",
380
+ "kbd",
381
+ "label",
382
+ "legend",
383
+ "li",
384
+ "main",
385
+ "map",
386
+ "mark",
387
+ "marquee",
388
+ "menu",
389
+ "menuitem",
390
+ "meter",
391
+ "nav",
392
+ "nobr",
393
+ "ol",
394
+ "optgroup",
395
+ "option",
396
+ "output",
397
+ "p",
398
+ "picture",
399
+ "pre",
400
+ "progress",
401
+ "q",
402
+ "rp",
403
+ "rt",
404
+ "ruby",
405
+ "s",
406
+ "samp",
407
+ "search",
408
+ "section",
409
+ "select",
410
+ "shadow",
411
+ "slot",
412
+ "small",
413
+ "source",
414
+ "spacer",
415
+ "span",
416
+ "strike",
417
+ "strong",
418
+ "style",
419
+ "sub",
420
+ "summary",
421
+ "sup",
422
+ "table",
423
+ "tbody",
424
+ "td",
425
+ "template",
426
+ "textarea",
427
+ "tfoot",
428
+ "th",
429
+ "thead",
430
+ "time",
431
+ "tr",
432
+ "track",
433
+ "tt",
434
+ "u",
435
+ "ul",
436
+ "var",
437
+ "video",
438
+ "wbr"
439
+ ]);
440
+ const svg$1 = freeze([
441
+ "svg",
442
+ "a",
443
+ "altglyph",
444
+ "altglyphdef",
445
+ "altglyphitem",
446
+ "animatecolor",
447
+ "animatemotion",
448
+ "animatetransform",
449
+ "circle",
450
+ "clippath",
451
+ "defs",
452
+ "desc",
453
+ "ellipse",
454
+ "filter",
455
+ "font",
456
+ "g",
457
+ "glyph",
458
+ "glyphref",
459
+ "hkern",
460
+ "image",
461
+ "line",
462
+ "lineargradient",
463
+ "marker",
464
+ "mask",
465
+ "metadata",
466
+ "mpath",
467
+ "path",
468
+ "pattern",
469
+ "polygon",
470
+ "polyline",
471
+ "radialgradient",
472
+ "rect",
473
+ "stop",
474
+ "style",
475
+ "switch",
476
+ "symbol",
477
+ "text",
478
+ "textpath",
479
+ "title",
480
+ "tref",
481
+ "tspan",
482
+ "view",
483
+ "vkern"
484
+ ]);
485
+ const svgFilters = freeze([
486
+ "feBlend",
487
+ "feColorMatrix",
488
+ "feComponentTransfer",
489
+ "feComposite",
490
+ "feConvolveMatrix",
491
+ "feDiffuseLighting",
492
+ "feDisplacementMap",
493
+ "feDistantLight",
494
+ "feDropShadow",
495
+ "feFlood",
496
+ "feFuncA",
497
+ "feFuncB",
498
+ "feFuncG",
499
+ "feFuncR",
500
+ "feGaussianBlur",
501
+ "feImage",
502
+ "feMerge",
503
+ "feMergeNode",
504
+ "feMorphology",
505
+ "feOffset",
506
+ "fePointLight",
507
+ "feSpecularLighting",
508
+ "feSpotLight",
509
+ "feTile",
510
+ "feTurbulence"
511
+ ]);
512
+ const svgDisallowed = freeze([
513
+ "animate",
514
+ "color-profile",
515
+ "cursor",
516
+ "discard",
517
+ "font-face",
518
+ "font-face-format",
519
+ "font-face-name",
520
+ "font-face-src",
521
+ "font-face-uri",
522
+ "foreignobject",
523
+ "hatch",
524
+ "hatchpath",
525
+ "mesh",
526
+ "meshgradient",
527
+ "meshpatch",
528
+ "meshrow",
529
+ "missing-glyph",
530
+ "script",
531
+ "set",
532
+ "solidcolor",
533
+ "unknown",
534
+ "use"
535
+ ]);
536
+ const mathMl$1 = freeze([
537
+ "math",
538
+ "menclose",
539
+ "merror",
540
+ "mfenced",
541
+ "mfrac",
542
+ "mglyph",
543
+ "mi",
544
+ "mlabeledtr",
545
+ "mmultiscripts",
546
+ "mn",
547
+ "mo",
548
+ "mover",
549
+ "mpadded",
550
+ "mphantom",
551
+ "mroot",
552
+ "mrow",
553
+ "ms",
554
+ "mspace",
555
+ "msqrt",
556
+ "mstyle",
557
+ "msub",
558
+ "msup",
559
+ "msubsup",
560
+ "mtable",
561
+ "mtd",
562
+ "mtext",
563
+ "mtr",
564
+ "munder",
565
+ "munderover",
566
+ "mprescripts"
567
+ ]);
568
+ const mathMlDisallowed = freeze([
569
+ "maction",
570
+ "maligngroup",
571
+ "malignmark",
572
+ "mlongdiv",
573
+ "mscarries",
574
+ "mscarry",
575
+ "msgroup",
576
+ "mstack",
577
+ "msline",
578
+ "msrow",
579
+ "semantics",
580
+ "annotation",
581
+ "annotation-xml",
582
+ "mprescripts",
583
+ "none"
584
+ ]);
585
+ const text = freeze(["#text"]);
586
+ const html = freeze([
587
+ "accept",
588
+ "action",
589
+ "align",
590
+ "alt",
591
+ "autocapitalize",
592
+ "autocomplete",
593
+ "autopictureinpicture",
594
+ "autoplay",
595
+ "background",
596
+ "bgcolor",
597
+ "border",
598
+ "capture",
599
+ "cellpadding",
600
+ "cellspacing",
601
+ "checked",
602
+ "cite",
603
+ "class",
604
+ "clear",
605
+ "color",
606
+ "cols",
607
+ "colspan",
608
+ "command",
609
+ "commandfor",
610
+ "controls",
611
+ "controlslist",
612
+ "coords",
613
+ "crossorigin",
614
+ "datetime",
615
+ "decoding",
616
+ "default",
617
+ "dir",
618
+ "disabled",
619
+ "disablepictureinpicture",
620
+ "disableremoteplayback",
621
+ "download",
622
+ "draggable",
623
+ "enctype",
624
+ "enterkeyhint",
625
+ "exportparts",
626
+ "face",
627
+ "for",
628
+ "headers",
629
+ "height",
630
+ "hidden",
631
+ "high",
632
+ "href",
633
+ "hreflang",
634
+ "id",
635
+ "inert",
636
+ "inputmode",
637
+ "integrity",
638
+ "ismap",
639
+ "kind",
640
+ "label",
641
+ "lang",
642
+ "list",
643
+ "loading",
644
+ "loop",
645
+ "low",
646
+ "max",
647
+ "maxlength",
648
+ "media",
649
+ "method",
650
+ "min",
651
+ "minlength",
652
+ "multiple",
653
+ "muted",
654
+ "name",
655
+ "nonce",
656
+ "noshade",
657
+ "novalidate",
658
+ "nowrap",
659
+ "open",
660
+ "optimum",
661
+ "part",
662
+ "pattern",
663
+ "placeholder",
664
+ "playsinline",
665
+ "popover",
666
+ "popovertarget",
667
+ "popovertargetaction",
668
+ "poster",
669
+ "preload",
670
+ "pubdate",
671
+ "radiogroup",
672
+ "readonly",
673
+ "rel",
674
+ "required",
675
+ "rev",
676
+ "reversed",
677
+ "role",
678
+ "rows",
679
+ "rowspan",
680
+ "spellcheck",
681
+ "scope",
682
+ "selected",
683
+ "shape",
684
+ "size",
685
+ "sizes",
686
+ "slot",
687
+ "span",
688
+ "srclang",
689
+ "start",
690
+ "src",
691
+ "srcset",
692
+ "step",
693
+ "style",
694
+ "summary",
695
+ "tabindex",
696
+ "title",
697
+ "translate",
698
+ "type",
699
+ "usemap",
700
+ "valign",
701
+ "value",
702
+ "width",
703
+ "wrap",
704
+ "xmlns"
705
+ ]);
706
+ const svg = freeze([
707
+ "accent-height",
708
+ "accumulate",
709
+ "additive",
710
+ "alignment-baseline",
711
+ "amplitude",
712
+ "ascent",
713
+ "attributename",
714
+ "attributetype",
715
+ "azimuth",
716
+ "basefrequency",
717
+ "baseline-shift",
718
+ "begin",
719
+ "bias",
720
+ "by",
721
+ "class",
722
+ "clip",
723
+ "clippathunits",
724
+ "clip-path",
725
+ "clip-rule",
726
+ "color",
727
+ "color-interpolation",
728
+ "color-interpolation-filters",
729
+ "color-profile",
730
+ "color-rendering",
731
+ "cx",
732
+ "cy",
733
+ "d",
734
+ "dx",
735
+ "dy",
736
+ "diffuseconstant",
737
+ "direction",
738
+ "display",
739
+ "divisor",
740
+ "dominant-baseline",
741
+ "dur",
742
+ "edgemode",
743
+ "elevation",
744
+ "end",
745
+ "exponent",
746
+ "fill",
747
+ "fill-opacity",
748
+ "fill-rule",
749
+ "filter",
750
+ "filterunits",
751
+ "flood-color",
752
+ "flood-opacity",
753
+ "font-family",
754
+ "font-size",
755
+ "font-size-adjust",
756
+ "font-stretch",
757
+ "font-style",
758
+ "font-variant",
759
+ "font-weight",
760
+ "fx",
761
+ "fy",
762
+ "g1",
763
+ "g2",
764
+ "glyph-name",
765
+ "glyphref",
766
+ "gradientunits",
767
+ "gradienttransform",
768
+ "height",
769
+ "href",
770
+ "id",
771
+ "image-rendering",
772
+ "in",
773
+ "in2",
774
+ "intercept",
775
+ "k",
776
+ "k1",
777
+ "k2",
778
+ "k3",
779
+ "k4",
780
+ "kerning",
781
+ "keypoints",
782
+ "keysplines",
783
+ "keytimes",
784
+ "lang",
785
+ "lengthadjust",
786
+ "letter-spacing",
787
+ "kernelmatrix",
788
+ "kernelunitlength",
789
+ "lighting-color",
790
+ "local",
791
+ "marker-end",
792
+ "marker-mid",
793
+ "marker-start",
794
+ "markerheight",
795
+ "markerunits",
796
+ "markerwidth",
797
+ "maskcontentunits",
798
+ "maskunits",
799
+ "max",
800
+ "mask",
801
+ "mask-type",
802
+ "media",
803
+ "method",
804
+ "mode",
805
+ "min",
806
+ "name",
807
+ "numoctaves",
808
+ "offset",
809
+ "operator",
810
+ "opacity",
811
+ "order",
812
+ "orient",
813
+ "orientation",
814
+ "origin",
815
+ "overflow",
816
+ "paint-order",
817
+ "path",
818
+ "pathlength",
819
+ "patterncontentunits",
820
+ "patterntransform",
821
+ "patternunits",
822
+ "pointer-events",
823
+ "points",
824
+ "preservealpha",
825
+ "preserveaspectratio",
826
+ "primitiveunits",
827
+ "r",
828
+ "rx",
829
+ "ry",
830
+ "radius",
831
+ "refx",
832
+ "refy",
833
+ "repeatcount",
834
+ "repeatdur",
835
+ "restart",
836
+ "result",
837
+ "rotate",
838
+ "scale",
839
+ "seed",
840
+ "shape-rendering",
841
+ "slope",
842
+ "specularconstant",
843
+ "specularexponent",
844
+ "spreadmethod",
845
+ "startoffset",
846
+ "stddeviation",
847
+ "stitchtiles",
848
+ "stop-color",
849
+ "stop-opacity",
850
+ "stroke-dasharray",
851
+ "stroke-dashoffset",
852
+ "stroke-linecap",
853
+ "stroke-linejoin",
854
+ "stroke-miterlimit",
855
+ "stroke-opacity",
856
+ "stroke",
857
+ "stroke-width",
858
+ "style",
859
+ "surfacescale",
860
+ "systemlanguage",
861
+ "tabindex",
862
+ "tablevalues",
863
+ "targetx",
864
+ "targety",
865
+ "transform",
866
+ "transform-origin",
867
+ "text-anchor",
868
+ "text-decoration",
869
+ "text-orientation",
870
+ "text-rendering",
871
+ "textlength",
872
+ "type",
873
+ "u1",
874
+ "u2",
875
+ "unicode",
876
+ "values",
877
+ "vector-effect",
878
+ "viewbox",
879
+ "visibility",
880
+ "version",
881
+ "vert-adv-y",
882
+ "vert-origin-x",
883
+ "vert-origin-y",
884
+ "width",
885
+ "word-spacing",
886
+ "wrap",
887
+ "writing-mode",
888
+ "xchannelselector",
889
+ "ychannelselector",
890
+ "x",
891
+ "x1",
892
+ "x2",
893
+ "xmlns",
894
+ "y",
895
+ "y1",
896
+ "y2",
897
+ "z",
898
+ "zoomandpan"
899
+ ]);
900
+ const mathMl = freeze([
901
+ "accent",
902
+ "accentunder",
903
+ "align",
904
+ "bevelled",
905
+ "close",
906
+ "columnalign",
907
+ "columnlines",
908
+ "columnspacing",
909
+ "columnspan",
910
+ "denomalign",
911
+ "depth",
912
+ "dir",
913
+ "display",
914
+ "displaystyle",
915
+ "encoding",
916
+ "fence",
917
+ "frame",
918
+ "height",
919
+ "href",
920
+ "id",
921
+ "largeop",
922
+ "length",
923
+ "linethickness",
924
+ "lquote",
925
+ "lspace",
926
+ "mathbackground",
927
+ "mathcolor",
928
+ "mathsize",
929
+ "mathvariant",
930
+ "maxsize",
931
+ "minsize",
932
+ "movablelimits",
933
+ "notation",
934
+ "numalign",
935
+ "open",
936
+ "rowalign",
937
+ "rowlines",
938
+ "rowspacing",
939
+ "rowspan",
940
+ "rspace",
941
+ "rquote",
942
+ "scriptlevel",
943
+ "scriptminsize",
944
+ "scriptsizemultiplier",
945
+ "selection",
946
+ "separator",
947
+ "separators",
948
+ "stretchy",
949
+ "subscriptshift",
950
+ "supscriptshift",
951
+ "symmetric",
952
+ "voffset",
953
+ "width",
954
+ "xmlns"
955
+ ]);
956
+ const xml = freeze([
957
+ "xlink:href",
958
+ "xml:id",
959
+ "xlink:title",
960
+ "xml:space",
961
+ "xmlns:xlink"
962
+ ]);
963
+ const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
964
+ const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
965
+ const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
966
+ const TMPL_MARKER_SERIALIZED = seal(/{{|}}|\${|<%|%>|&lt;%|%&gt;/);
967
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
968
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/);
969
+ const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
970
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
971
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g);
972
+ const DOCTYPE_NAME = seal(/^html$/i);
973
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
974
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
975
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
976
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
977
+ const SELF_CLOSING_TAG = seal(/\/>/i);
978
+ const ATTR_VALUE_BREAKOUT = seal(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i);
979
+ const LEADING_WHITESPACE = seal(/^[\r\n\t ]+/);
980
+ const NODE_TYPE = {
981
+ element: 1,
982
+ text: 3,
983
+ processingInstruction: 7,
984
+ comment: 8,
985
+ document: 9,
986
+ documentFragment: 11
987
+ };
988
+ const LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, [
989
+ "style",
990
+ "script",
991
+ "xmp",
992
+ "iframe",
993
+ "noembed",
994
+ "noframes",
995
+ "plaintext",
996
+ "noscript"
997
+ ]));
998
+ const getGlobal = function getGlobal() {
999
+ return typeof window === "undefined" ? null : window;
1000
+ };
1001
+ /**
1002
+ * Creates a no-op policy for internal use only.
1003
+ * Don't export this function outside this module!
1004
+ * @param trustedTypes The policy factory.
1005
+ * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
1006
+ * @return The policy created (or null, if Trusted Types
1007
+ * are not supported or creating the policy failed).
1008
+ */
1009
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
1010
+ if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") return null;
1011
+ let suffix = null;
1012
+ const ATTR_NAME = "data-tt-policy-suffix";
1013
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) suffix = purifyHostElement.getAttribute(ATTR_NAME);
1014
+ const policyName = "dompurify" + (suffix ? "#" + suffix : "");
1015
+ try {
1016
+ return trustedTypes.createPolicy(policyName, {
1017
+ createHTML(html) {
1018
+ return html;
1019
+ },
1020
+ createScriptURL(scriptUrl) {
1021
+ return scriptUrl;
1022
+ }
1023
+ });
1024
+ } catch (_) {
1025
+ console.warn("TrustedTypes policy " + policyName + " could not be created.");
1026
+ return null;
1027
+ }
1028
+ };
1029
+ const _createHooksMap = function _createHooksMap() {
1030
+ return {
1031
+ afterSanitizeAttributes: [],
1032
+ afterSanitizeElements: [],
1033
+ afterSanitizeShadowDOM: [],
1034
+ beforeSanitizeAttributes: [],
1035
+ beforeSanitizeElements: [],
1036
+ beforeSanitizeShadowDOM: [],
1037
+ uponSanitizeAttribute: [],
1038
+ uponSanitizeElement: [],
1039
+ uponSanitizeShadowNode: []
1040
+ };
1041
+ };
1042
+ /**
1043
+ * Resolve a set-valued configuration option.
1044
+ *
1045
+ * @param cfg the cloned, prototype-free configuration object
1046
+ * @param key the configuration property to read
1047
+ * @param fallback the set to use when the option is absent or not an array
1048
+ * @param options case transform, and an optional base set to extend a copy of
1049
+ * @returns a fresh set built from cfg[key], or the fallback
1050
+ */
1051
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
1052
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? cloneSet(options.base) : {}, cfg[key], options.transform) : fallback;
1053
+ };
1054
+ /**
1055
+ * Resolve an object-valued configuration option.
1056
+ *
1057
+ * @param cfg the cloned, prototype-free configuration object
1058
+ * @param key the configuration property to read
1059
+ * @param fallback the read-only value to use when the option is absent
1060
+ * @returns a prototype-free clone of cfg[key], or the fallback
1061
+ */
1062
+ const _resolveObjectOption = function _resolveObjectOption(cfg, key, fallback) {
1063
+ const value = objectHasOwnProperty(cfg, key) ? cfg[key] : void 0;
1064
+ return value && typeof value === "object" ? clone(value) : fallback;
1065
+ };
1066
+ function createDOMPurify() {
1067
+ let window = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
1068
+ const DOMPurify = (root) => createDOMPurify(root);
1069
+ DOMPurify.version = "3.4.18";
1070
+ DOMPurify.removed = [];
1071
+ if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
1072
+ DOMPurify.isSupported = false;
1073
+ return DOMPurify;
1074
+ }
1075
+ let document = window.document;
1076
+ const originalDocument = document;
1077
+ const currentScript = originalDocument.currentScript;
1078
+ const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter, DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
1079
+ const ElementPrototype = Element.prototype;
1080
+ const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
1081
+ const remove = lookupGetter(ElementPrototype, "remove");
1082
+ const removeAttributeNode = lookupGetter(ElementPrototype, "removeAttributeNode");
1083
+ const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
1084
+ const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
1085
+ const getParentNode = lookupGetter(ElementPrototype, "parentNode");
1086
+ const getShadowRoot = lookupGetter(ElementPrototype, "shadowRoot");
1087
+ const getAttributes = lookupGetter(ElementPrototype, "attributes");
1088
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeType") : null;
1089
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeName") : null;
1090
+ const getOwnerDocument = Node && Node.prototype ? lookupGetter(Node.prototype, "ownerDocument") : null;
1091
+ const _readNodeType = function _readNodeType(node) {
1092
+ return getNodeType ? getNodeType(node) : node.nodeType;
1093
+ };
1094
+ const _readNodeName = function _readNodeName(node) {
1095
+ return getNodeName ? getNodeName(node) : node.nodeName;
1096
+ };
1097
+ const getNamespaceURI = lookupAccessor(ElementPrototype, "namespaceURI");
1098
+ const _readNamespaceURI = function _readNamespaceURI(element) {
1099
+ return getNamespaceURI ? getNamespaceURI(element) : element.namespaceURI;
1100
+ };
1101
+ if (typeof HTMLTemplateElement === "function") {
1102
+ const template = document.createElement("template");
1103
+ if (template.content && template.content.ownerDocument) document = template.content.ownerDocument;
1104
+ }
1105
+ let trustedTypesPolicy;
1106
+ let emptyHTML = "";
1107
+ let defaultTrustedTypesPolicy;
1108
+ let defaultTrustedTypesPolicyResolved = false;
1109
+ let IN_TRUSTED_TYPES_POLICY = 0;
1110
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
1111
+ if (IN_TRUSTED_TYPES_POLICY > 0) 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.");
1112
+ };
1113
+ const _createTrustedHTML = function _createTrustedHTML(html) {
1114
+ _assertNotInTrustedTypesPolicy();
1115
+ IN_TRUSTED_TYPES_POLICY++;
1116
+ try {
1117
+ return trustedTypesPolicy.createHTML(html);
1118
+ } finally {
1119
+ IN_TRUSTED_TYPES_POLICY--;
1120
+ }
1121
+ };
1122
+ const _signOutput = function _signOutput(html) {
1123
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(html) : html;
1124
+ };
1125
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
1126
+ _assertNotInTrustedTypesPolicy();
1127
+ IN_TRUSTED_TYPES_POLICY++;
1128
+ try {
1129
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
1130
+ } finally {
1131
+ IN_TRUSTED_TYPES_POLICY--;
1132
+ }
1133
+ };
1134
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
1135
+ if (!defaultTrustedTypesPolicyResolved) {
1136
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
1137
+ defaultTrustedTypesPolicyResolved = true;
1138
+ }
1139
+ return defaultTrustedTypesPolicy;
1140
+ };
1141
+ const _document = document, implementation = _document.implementation, createNodeIterator = _document.createNodeIterator, createDocumentFragment = _document.createDocumentFragment, getElementsByTagName = _document.getElementsByTagName;
1142
+ const importNode = originalDocument.importNode;
1143
+ let hooks = _createHooksMap();
1144
+ /**
1145
+ * Expose whether this browser supports running the full DOMPurify.
1146
+ */
1147
+ DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
1148
+ const MUSTACHE_EXPR$1 = MUSTACHE_EXPR, ERB_EXPR$1 = ERB_EXPR, TMPLIT_EXPR$1 = TMPLIT_EXPR, DATA_ATTR$1 = DATA_ATTR, ARIA_ATTR$1 = ARIA_ATTR, IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA, ATTR_WHITESPACE$1 = ATTR_WHITESPACE, CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
1149
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
1150
+ /**
1151
+ * We consider the elements and attributes below to be safe. Ideally
1152
+ * don't add any new ones but feel free to remove unwanted ones.
1153
+ */
1154
+ let ALLOWED_TAGS = null;
1155
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [
1156
+ ...html$1,
1157
+ ...svg$1,
1158
+ ...svgFilters,
1159
+ ...mathMl$1,
1160
+ ...text
1161
+ ]);
1162
+ let ALLOWED_ATTR = null;
1163
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [
1164
+ ...html,
1165
+ ...svg,
1166
+ ...mathMl,
1167
+ ...xml
1168
+ ]);
1169
+ let CUSTOM_ELEMENT_HANDLING = null;
1170
+ let FORBID_TAGS = null;
1171
+ let FORBID_ATTR = null;
1172
+ const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
1173
+ tagCheck: {
1174
+ writable: true,
1175
+ configurable: false,
1176
+ enumerable: true,
1177
+ value: null
1178
+ },
1179
+ attributeCheck: {
1180
+ writable: true,
1181
+ configurable: false,
1182
+ enumerable: true,
1183
+ value: null
1184
+ }
1185
+ }));
1186
+ let ALLOW_ARIA_ATTR = true;
1187
+ let ALLOW_DATA_ATTR = true;
1188
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
1189
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
1190
+ let SAFE_FOR_TEMPLATES = false;
1191
+ let SAFE_FOR_XML = true;
1192
+ let WHOLE_DOCUMENT = false;
1193
+ let SET_CONFIG = false;
1194
+ let SET_CONFIG_ALLOWED_TAGS = null;
1195
+ let SET_CONFIG_ALLOWED_ATTR = null;
1196
+ let FORCE_BODY = false;
1197
+ let RETURN_DOM = false;
1198
+ let RETURN_DOM_FRAGMENT = false;
1199
+ let RETURN_TRUSTED_TYPE = false;
1200
+ let SANITIZE_DOM = true;
1201
+ let SANITIZE_NAMED_PROPS = false;
1202
+ const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
1203
+ let KEEP_CONTENT = true;
1204
+ let IN_PLACE = false;
1205
+ let IN_PLACE_VISITED = null;
1206
+ let USE_PROFILES = false;
1207
+ let FORBID_CONTENTS = null;
1208
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, [
1209
+ "annotation-xml",
1210
+ "audio",
1211
+ "colgroup",
1212
+ "desc",
1213
+ "foreignobject",
1214
+ "head",
1215
+ "iframe",
1216
+ "math",
1217
+ "mi",
1218
+ "mn",
1219
+ "mo",
1220
+ "ms",
1221
+ "mtext",
1222
+ "noembed",
1223
+ "noframes",
1224
+ "noscript",
1225
+ "plaintext",
1226
+ "script",
1227
+ "selectedcontent",
1228
+ "style",
1229
+ "svg",
1230
+ "template",
1231
+ "thead",
1232
+ "title",
1233
+ "video",
1234
+ "xmp"
1235
+ ]);
1236
+ let DATA_URI_TAGS = null;
1237
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, [
1238
+ "audio",
1239
+ "video",
1240
+ "img",
1241
+ "source",
1242
+ "image",
1243
+ "track"
1244
+ ]);
1245
+ let URI_SAFE_ATTRIBUTES = null;
1246
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
1247
+ "alt",
1248
+ "class",
1249
+ "for",
1250
+ "id",
1251
+ "label",
1252
+ "name",
1253
+ "pattern",
1254
+ "placeholder",
1255
+ "role",
1256
+ "summary",
1257
+ "title",
1258
+ "value",
1259
+ "style",
1260
+ "xmlns"
1261
+ ]);
1262
+ const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
1263
+ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
1264
+ const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
1265
+ let NAMESPACE = HTML_NAMESPACE;
1266
+ let IS_EMPTY_INPUT = false;
1267
+ let ALLOWED_NAMESPACES = null;
1268
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [
1269
+ MATHML_NAMESPACE,
1270
+ SVG_NAMESPACE,
1271
+ HTML_NAMESPACE
1272
+ ], stringToString);
1273
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(addToSet({}, [
1274
+ "mi",
1275
+ "mo",
1276
+ "mn",
1277
+ "ms",
1278
+ "mtext"
1279
+ ]));
1280
+ let MATHML_TEXT_INTEGRATION_POINTS = null;
1281
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(addToSet({}, ["annotation-xml"]));
1282
+ let HTML_INTEGRATION_POINTS = null;
1283
+ const DEFAULT_CUSTOM_ELEMENT_HANDLING = freeze(create(null));
1284
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
1285
+ "title",
1286
+ "style",
1287
+ "font",
1288
+ "a",
1289
+ "script"
1290
+ ]);
1291
+ let PARSER_MEDIA_TYPE = null;
1292
+ const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
1293
+ const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
1294
+ let transformCaseFunc = null;
1295
+ let CONFIG = null;
1296
+ const formElement = document.createElement("form");
1297
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
1298
+ return testValue instanceof RegExp || testValue instanceof Function;
1299
+ };
1300
+ /**
1301
+ * _parseConfig
1302
+ *
1303
+ * @param cfg optional config literal
1304
+ */
1305
+ const _parseConfig = function _parseConfig() {
1306
+ let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1307
+ if (!cfg || typeof cfg !== "object") cfg = {};
1308
+ cfg = clone(cfg);
1309
+ PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
1310
+ transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
1311
+ ALLOWED_TAGS = _resolveSetOption(cfg, "ALLOWED_TAGS", DEFAULT_ALLOWED_TAGS, { transform: transformCaseFunc });
1312
+ ALLOWED_ATTR = _resolveSetOption(cfg, "ALLOWED_ATTR", DEFAULT_ALLOWED_ATTR, { transform: transformCaseFunc });
1313
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, "ALLOWED_NAMESPACES", DEFAULT_ALLOWED_NAMESPACES, { transform: stringToString });
1314
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, "ADD_URI_SAFE_ATTR", DEFAULT_URI_SAFE_ATTRIBUTES, {
1315
+ transform: transformCaseFunc,
1316
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
1317
+ });
1318
+ DATA_URI_TAGS = _resolveSetOption(cfg, "ADD_DATA_URI_TAGS", DEFAULT_DATA_URI_TAGS, {
1319
+ transform: transformCaseFunc,
1320
+ base: DEFAULT_DATA_URI_TAGS
1321
+ });
1322
+ FORBID_CONTENTS = _resolveSetOption(cfg, "FORBID_CONTENTS", DEFAULT_FORBID_CONTENTS, { transform: transformCaseFunc });
1323
+ FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", create(null), { transform: transformCaseFunc });
1324
+ FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", create(null), { transform: transformCaseFunc });
1325
+ USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === "object" ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
1326
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
1327
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
1328
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
1329
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
1330
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
1331
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
1332
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
1333
+ RETURN_DOM = cfg.RETURN_DOM || false;
1334
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
1335
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
1336
+ FORCE_BODY = cfg.FORCE_BODY || false;
1337
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
1338
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
1339
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
1340
+ IN_PLACE = cfg.IN_PLACE || false;
1341
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI;
1342
+ NAMESPACE = typeof cfg.NAMESPACE === "string" ? cfg.NAMESPACE : HTML_NAMESPACE;
1343
+ MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS", DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
1344
+ HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS", DEFAULT_HTML_INTEGRATION_POINTS);
1345
+ const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", DEFAULT_CUSTOM_ELEMENT_HANDLING);
1346
+ CUSTOM_ELEMENT_HANDLING = create(null);
1347
+ if (objectHasOwnProperty(customElementHandling, "tagNameCheck") && isRegexOrFunction(customElementHandling.tagNameCheck)) CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck;
1348
+ if (objectHasOwnProperty(customElementHandling, "attributeNameCheck") && isRegexOrFunction(customElementHandling.attributeNameCheck)) CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck;
1349
+ if (objectHasOwnProperty(customElementHandling, "allowCustomizedBuiltInElements") && typeof customElementHandling.allowCustomizedBuiltInElements === "boolean") CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements;
1350
+ seal(CUSTOM_ELEMENT_HANDLING);
1351
+ if (SAFE_FOR_TEMPLATES) ALLOW_DATA_ATTR = false;
1352
+ if (RETURN_DOM_FRAGMENT) RETURN_DOM = true;
1353
+ if (USE_PROFILES) {
1354
+ if ((objectHasOwnProperty(cfg, "ALLOWED_TAGS") || objectHasOwnProperty(cfg, "ALLOWED_ATTR")) && typeof console !== "undefined" && typeof console.warn === "function") console.warn("DOMPurify: USE_PROFILES overrides ALLOWED_TAGS and ALLOWED_ATTR. Do not use these options together.");
1355
+ ALLOWED_TAGS = addToSet({}, text);
1356
+ ALLOWED_ATTR = create(null);
1357
+ if (USE_PROFILES.html === true) {
1358
+ addToSet(ALLOWED_TAGS, html$1);
1359
+ addToSet(ALLOWED_ATTR, html);
1360
+ }
1361
+ if (USE_PROFILES.svg === true) {
1362
+ addToSet(ALLOWED_TAGS, svg$1);
1363
+ addToSet(ALLOWED_ATTR, svg);
1364
+ addToSet(ALLOWED_ATTR, xml);
1365
+ }
1366
+ if (USE_PROFILES.svgFilters === true) {
1367
+ addToSet(ALLOWED_TAGS, svgFilters);
1368
+ addToSet(ALLOWED_ATTR, svg);
1369
+ addToSet(ALLOWED_ATTR, xml);
1370
+ }
1371
+ if (USE_PROFILES.mathMl === true) {
1372
+ addToSet(ALLOWED_TAGS, mathMl$1);
1373
+ addToSet(ALLOWED_ATTR, mathMl);
1374
+ addToSet(ALLOWED_ATTR, xml);
1375
+ }
1376
+ }
1377
+ EXTRA_ELEMENT_HANDLING.tagCheck = null;
1378
+ EXTRA_ELEMENT_HANDLING.attributeCheck = null;
1379
+ if (objectHasOwnProperty(cfg, "ADD_TAGS")) {
1380
+ if (typeof cfg.ADD_TAGS === "function") EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
1381
+ else if (arrayIsArray(cfg.ADD_TAGS)) {
1382
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = cloneSet(ALLOWED_TAGS);
1383
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
1384
+ }
1385
+ }
1386
+ if (objectHasOwnProperty(cfg, "ADD_ATTR")) {
1387
+ if (typeof cfg.ADD_ATTR === "function") EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
1388
+ else if (arrayIsArray(cfg.ADD_ATTR)) {
1389
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = cloneSet(ALLOWED_ATTR);
1390
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
1391
+ }
1392
+ }
1393
+ if (objectHasOwnProperty(cfg, "ADD_FORBID_CONTENTS") && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
1394
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = cloneSet(FORBID_CONTENTS);
1395
+ addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
1396
+ }
1397
+ if (KEEP_CONTENT) ALLOWED_TAGS["#text"] = true;
1398
+ if (WHOLE_DOCUMENT) addToSet(ALLOWED_TAGS, [
1399
+ "html",
1400
+ "head",
1401
+ "body"
1402
+ ]);
1403
+ if (ALLOWED_TAGS.table) {
1404
+ ALLOWED_TAGS.tbody = true;
1405
+ delete FORBID_TAGS.tbody;
1406
+ }
1407
+ if (cfg.TRUSTED_TYPES_POLICY) {
1408
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") throw typeErrorCreate("TRUSTED_TYPES_POLICY configuration option must provide a \"createHTML\" hook.");
1409
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") throw typeErrorCreate("TRUSTED_TYPES_POLICY configuration option must provide a \"createScriptURL\" hook.");
1410
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
1411
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
1412
+ try {
1413
+ emptyHTML = _createTrustedHTML("");
1414
+ } catch (error) {
1415
+ trustedTypesPolicy = previousTrustedTypesPolicy;
1416
+ throw error;
1417
+ }
1418
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
1419
+ trustedTypesPolicy = void 0;
1420
+ emptyHTML = "";
1421
+ } else {
1422
+ if (trustedTypesPolicy === void 0) trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
1423
+ if (trustedTypesPolicy && typeof emptyHTML === "string") emptyHTML = _createTrustedHTML("");
1424
+ }
1425
+ CONFIG = freeze(cfg);
1426
+ };
1427
+ const ALL_SVG_TAGS = addToSet({}, [
1428
+ ...svg$1,
1429
+ ...svgFilters,
1430
+ ...svgDisallowed
1431
+ ]);
1432
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
1433
+ /**
1434
+ * Namespace rules for an element in the SVG namespace.
1435
+ *
1436
+ * @param tagName the element's lowercase tag name
1437
+ * @param parentNamespace the (possibly simulated) parent's namespace
1438
+ * @param parentTagName the parent's lowercase tag name
1439
+ * @returns true if a spec-compliant parser could produce this element
1440
+ */
1441
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parentNamespace, parentTagName) {
1442
+ if (parentNamespace === HTML_NAMESPACE) return tagName === "svg";
1443
+ if (parentNamespace === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1444
+ return Boolean(ALL_SVG_TAGS[tagName]);
1445
+ };
1446
+ /**
1447
+ * Namespace rules for an element in the MathML namespace.
1448
+ *
1449
+ * @param tagName the element's lowercase tag name
1450
+ * @param parentNamespace the (possibly simulated) parent's namespace
1451
+ * @param parentTagName the parent's lowercase tag name
1452
+ * @returns true if a spec-compliant parser could produce this element
1453
+ */
1454
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parentNamespace, parentTagName) {
1455
+ if (parentNamespace === HTML_NAMESPACE) return tagName === "math";
1456
+ if (parentNamespace === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
1457
+ return Boolean(ALL_MATHML_TAGS[tagName]);
1458
+ };
1459
+ /**
1460
+ * Namespace rules for an element in the HTML namespace.
1461
+ *
1462
+ * @param tagName the element's lowercase tag name
1463
+ * @param parentNamespace the (possibly simulated) parent's namespace
1464
+ * @param parentTagName the parent's lowercase tag name
1465
+ * @returns true if a spec-compliant parser could produce this element
1466
+ */
1467
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parentNamespace, parentTagName) {
1468
+ if (parentNamespace === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
1469
+ if (parentNamespace === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
1470
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1471
+ };
1472
+ /**
1473
+ * @param element a DOM element whose namespace is being checked
1474
+ * @returns Return false if the element has a
1475
+ * namespace that a spec-compliant parser would never
1476
+ * return. Return true otherwise.
1477
+ */
1478
+ const _checkValidNamespace = function _checkValidNamespace(element) {
1479
+ const elementNamespace = _readNamespaceURI(element);
1480
+ const tagName = stringToLowerCase(_readNodeName(element));
1481
+ const parentNode = getParentNode(element);
1482
+ let parentNamespace = NAMESPACE;
1483
+ let parentTagName = "template";
1484
+ if (parentNode && _readNodeType(parentNode) === NODE_TYPE.element) {
1485
+ parentNamespace = _readNamespaceURI(parentNode);
1486
+ parentTagName = stringToLowerCase(_readNodeName(parentNode));
1487
+ }
1488
+ if (!ALLOWED_NAMESPACES[elementNamespace]) return false;
1489
+ if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parentNamespace, parentTagName);
1490
+ if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parentNamespace, parentTagName);
1491
+ if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parentNamespace, parentTagName);
1492
+ return PARSER_MEDIA_TYPE === "application/xhtml+xml";
1493
+ };
1494
+ /**
1495
+ * _forceRemove
1496
+ *
1497
+ * @param node a DOM node
1498
+ */
1499
+ const _forceRemove = function _forceRemove(node) {
1500
+ arrayPush(DOMPurify.removed, { element: node });
1501
+ try {
1502
+ getParentNode(node).removeChild(node);
1503
+ } catch (_) {
1504
+ remove(node);
1505
+ if (!getParentNode(node)) throw typeErrorCreate("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place");
1506
+ }
1507
+ };
1508
+ /**
1509
+ * Removes an Attr node as that exact node, without book-keeping. Name-based
1510
+ * removal lowercases the name in HTML documents and would miss a
1511
+ * case-preserved one such as `ONERROR`, so it is only the fallback for
1512
+ * clobbered or detached nodes.
1513
+ *
1514
+ * @param element the element to strip the attribute from
1515
+ * @param attribute the Attr node to remove
1516
+ * @param name the attribute's name, for the fallback path
1517
+ */
1518
+ const _stripAttributeNode = function _stripAttributeNode(element, attribute, name) {
1519
+ try {
1520
+ removeAttributeNode(element, attribute);
1521
+ } catch (_) {
1522
+ try {
1523
+ element.removeAttribute(name);
1524
+ } catch (_) {}
1525
+ }
1526
+ };
1527
+ /**
1528
+ * Fail-closed teardown of an in-place root: strip every disallowed attribute
1529
+ * in the subtree first, so nothing armed is left behind, then remove all
1530
+ * children and the root's own attributes.
1531
+ *
1532
+ * @param root the in-place root to empty
1533
+ */
1534
+ const _neutralizeRoot = function _neutralizeRoot(root) {
1535
+ _neutralizeSubtree(root);
1536
+ const childNodes = getChildNodes(root);
1537
+ if (childNodes) arrayForEach(arraySlice(childNodes), (child) => {
1538
+ try {
1539
+ remove(child);
1540
+ } catch (_) {}
1541
+ });
1542
+ if (_readNodeType(root) === NODE_TYPE.element) _stripAttributes(root, false);
1543
+ };
1544
+ /**
1545
+ * Removes an attribute, preferably as its exact Attr node: name-based
1546
+ * removal lowercases the name in HTML documents and misses case-preserved
1547
+ * names, e.g. from imported XHTML.
1548
+ *
1549
+ * @param name an Attribute name
1550
+ * @param element a DOM node
1551
+ * @param attr the exact Attr node to remove, when the caller has it
1552
+ */
1553
+ const _removeAttribute = function _removeAttribute(name, element, attr) {
1554
+ if (!attr) try {
1555
+ attr = element.getAttributeNode(name);
1556
+ } catch (_) {
1557
+ attr = null;
1558
+ }
1559
+ arrayPush(DOMPurify.removed, {
1560
+ attribute: attr || null,
1561
+ from: element
1562
+ });
1563
+ if (attr) _stripAttributeNode(element, attr, name);
1564
+ else try {
1565
+ element.removeAttribute(name);
1566
+ } catch (_) {}
1567
+ if (name === "is") {
1568
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) try {
1569
+ _forceRemove(element);
1570
+ } catch (_) {}
1571
+ else try {
1572
+ element.setAttribute(name, "");
1573
+ } catch (_) {}
1574
+ }
1575
+ };
1576
+ /**
1577
+ * Removes an element's attributes without book-keeping. Used to neutralize
1578
+ * nodes discarded from an in-place tree.
1579
+ *
1580
+ * @param element the element to strip
1581
+ * @param keepAllowed whether attributes on the allowlist stay
1582
+ */
1583
+ const _stripAttributes = function _stripAttributes(element, keepAllowed) {
1584
+ const attributes = getAttributes(element);
1585
+ if (!attributes) return;
1586
+ for (let i = attributes.length - 1; i >= 0; --i) {
1587
+ const attribute = attributes[i];
1588
+ const name = attribute && attribute.name;
1589
+ if (typeof name === "string" && !(keepAllowed && ALLOWED_ATTR[transformCaseFunc(name)])) _stripAttributeNode(element, attribute, name);
1590
+ }
1591
+ };
1592
+ /**
1593
+ * Iterative depth-first walk, so deep trees cannot overflow the call stack,
1594
+ * reading through the cached getters, so clobbering cannot hide children.
1595
+ * When `visit` returns false, the node's children are skipped. With
1596
+ * `intoShadow`, open shadow roots are walked after their host's children.
1597
+ *
1598
+ * @param root where to start
1599
+ * @param visit called for every node
1600
+ * @param intoShadow whether to enter open shadow roots
1601
+ */
1602
+ const _walkTree = function _walkTree(root, visit) {
1603
+ let intoShadow = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1604
+ const stack = [root];
1605
+ while (stack.length > 0) {
1606
+ const node = stack.pop();
1607
+ if (visit(node) === false) continue;
1608
+ if (intoShadow && _readNodeType(node) === NODE_TYPE.element) {
1609
+ const shadowRoot = getShadowRoot(node);
1610
+ if (_isDocumentFragment(shadowRoot)) stack.push(shadowRoot);
1611
+ }
1612
+ const childNodes = getChildNodes(node);
1613
+ if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push(childNodes[i]);
1614
+ }
1615
+ };
1616
+ /**
1617
+ * Strips disallowed attributes from every element of a discarded subtree,
1618
+ * so a handler that is already queued (a loading image) cannot fire.
1619
+ *
1620
+ * @param root the root of a removed subtree
1621
+ */
1622
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
1623
+ _walkTree(root, (node) => {
1624
+ if (_readNodeType(node) === NODE_TYPE.element) _stripAttributes(node, true);
1625
+ });
1626
+ };
1627
+ /**
1628
+ * All nodes under `root`, root first, including open shadow roots. Template
1629
+ * content is not entered, it is inert.
1630
+ *
1631
+ * @param root the in-place root
1632
+ * @return the nodes
1633
+ */
1634
+ const _collectLiveNodes = function _collectLiveNodes(root) {
1635
+ const nodes = [];
1636
+ _walkTree(root, (node) => {
1637
+ nodes.push(node);
1638
+ }, true);
1639
+ return nodes;
1640
+ };
1641
+ /**
1642
+ * Strips disallowed attributes from every element that was under the
1643
+ * in-place root when the call started and no longer is, whatever removed
1644
+ * or moved it.
1645
+ *
1646
+ * @param root the in-place root
1647
+ * @param before the root's nodes, collected before the walk
1648
+ */
1649
+ const _neutralizeEscapedElements = function _neutralizeEscapedElements(root, before) {
1650
+ const reachable = setCreate();
1651
+ arrayForEach(_collectLiveNodes(root), (node) => {
1652
+ if (_readNodeType(node) === NODE_TYPE.element) setAdd(reachable, node);
1653
+ });
1654
+ arrayForEach(before, (node) => {
1655
+ if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node)) _stripAttributes(node, true);
1656
+ });
1657
+ };
1658
+ /**
1659
+ * Neutralizes everything that left the in-place tree during the call: what
1660
+ * DOMPurify removed, and what hooks or custom elements removed or moved out.
1661
+ *
1662
+ * @param root the in-place root
1663
+ * @param before the root's nodes, collected before the walk
1664
+ * @return true if the root itself was removed
1665
+ */
1666
+ const _neutralizeDiscarded = function _neutralizeDiscarded(root, before) {
1667
+ let rootRemoved = false;
1668
+ arrayForEach(DOMPurify.removed, (entry) => {
1669
+ if (entry.element) {
1670
+ rootRemoved = rootRemoved || entry.element === root;
1671
+ _neutralizeSubtree(entry.element);
1672
+ }
1673
+ });
1674
+ _neutralizeEscapedElements(root, before);
1675
+ return rootRemoved;
1676
+ };
1677
+ const MAX_UNVISITED_ROUNDS = 8;
1678
+ /**
1679
+ * The walk only moves forward, so a node moved to a position it already
1680
+ * passed is never visited. Give every original node that is still in the
1681
+ * tree but unvisited the normal treatment, hooks included. Nodes created
1682
+ * during the call are left alone. Fails closed if the tree keeps changing.
1683
+ *
1684
+ * @param root the in-place root
1685
+ * @param before the root's nodes, collected before the walk
1686
+ */
1687
+ const _sanitizeUnvisitedNodes = function _sanitizeUnvisitedNodes(root, before) {
1688
+ const visited = IN_PLACE_VISITED;
1689
+ let original = null;
1690
+ const getOriginal = () => {
1691
+ if (!original) {
1692
+ original = setCreate();
1693
+ arrayForEach(before, (beforeNode) => {
1694
+ setAdd(original, beforeNode);
1695
+ });
1696
+ }
1697
+ return original;
1698
+ };
1699
+ for (let round = 0;; round++) {
1700
+ const live = _collectLiveNodes(root);
1701
+ const containers = [root];
1702
+ let pending = false;
1703
+ arrayForEach(live, (node) => {
1704
+ if (_readNodeType(node) === NODE_TYPE.documentFragment) arrayPush(containers, node);
1705
+ else if (!pending && !setHas(visited, node)) pending = setHas(getOriginal(), node);
1706
+ });
1707
+ if (!pending) return;
1708
+ if (round >= MAX_UNVISITED_ROUNDS) throw typeErrorCreate("the tree kept changing during in-place sanitization; refusing to return it");
1709
+ arrayForEach(containers, (container, index) => {
1710
+ _sanitizeUnvisitedIn(container, index > 0, root, getOriginal());
1711
+ });
1712
+ }
1713
+ };
1714
+ /**
1715
+ * One _sanitizeUnvisitedNodes pass over the root or an open shadow root.
1716
+ *
1717
+ * @param container the root or an open shadow root
1718
+ * @param inShadow whether container is a shadow root
1719
+ * @param root the in-place root
1720
+ * @param original the root's nodes collected before the walk, as a set
1721
+ */
1722
+ const _sanitizeUnvisitedIn = function _sanitizeUnvisitedIn(container, inShadow, root, original) {
1723
+ const iterator = _createNodeIterator(container);
1724
+ let node;
1725
+ while (node = iterator.nextNode()) {
1726
+ if (!setHas(original, node) || setHas(IN_PLACE_VISITED, node)) continue;
1727
+ if (inShadow) _executeHooks(hooks.uponSanitizeShadowNode, node, null);
1728
+ _sanitizeNode(node, root);
1729
+ }
1730
+ };
1731
+ /**
1732
+ * Records that _sanitizeElements processed `node`. No-op outside IN_PLACE.
1733
+ *
1734
+ * @param node the node being processed
1735
+ */
1736
+ const _markVisited = function _markVisited(node) {
1737
+ if (IN_PLACE_VISITED) setAdd(IN_PLACE_VISITED, node);
1738
+ };
1739
+ /**
1740
+ * Patch-linkage attributes (declarative partial updates): `patchsrc`
1741
+ * always, `for` everywhere except on <label> and <output>. Gated on
1742
+ * SAFE_FOR_XML. Shared by the IN_PLACE pre-pass and _isValidAttribute.
1743
+ *
1744
+ * @param lcName the transformCaseFunc'd attribute name
1745
+ * @param lcTag the transformCaseFunc'd tag name of the carrying element
1746
+ * @return true if the attribute is patch linkage and must be dropped
1747
+ */
1748
+ const _isPatchLinkageAttribute = function _isPatchLinkageAttribute(lcName, lcTag) {
1749
+ if (!SAFE_FOR_XML) return false;
1750
+ if (lcName === "patchsrc") return true;
1751
+ return lcName === "for" && lcTag !== "label" && lcTag !== "output";
1752
+ };
1753
+ /**
1754
+ * IN_PLACE pre-pass: sever all patch linkage before the walk, so no patch
1755
+ * can fire mid-walk into a part of the tree the walker already passed.
1756
+ * Removes range markers (processing instructions, comments with markup)
1757
+ * and strips linkage attributes. It cannot undo a patch that already fired.
1758
+ *
1759
+ * TODO: if the shipped feature can patch through `for` on <label>/<output>,
1760
+ * drop that pair here too.
1761
+ *
1762
+ * @param root the in-place root to sweep
1763
+ */
1764
+ const _neutralizePatchLinkage = function _neutralizePatchLinkage(root) {
1765
+ if (!SAFE_FOR_XML) return;
1766
+ _walkTree(root, (node) => {
1767
+ const nodeType = _readNodeType(node);
1768
+ if (nodeType === NODE_TYPE.processingInstruction || nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, node.data)) {
1769
+ try {
1770
+ remove(node);
1771
+ } catch (_) {}
1772
+ return false;
1773
+ }
1774
+ if (nodeType === NODE_TYPE.element) {
1775
+ const element = node;
1776
+ const lcTag = transformCaseFunc(_readNodeName(node));
1777
+ try {
1778
+ if (element.hasAttribute && element.hasAttribute("patchsrc")) element.removeAttribute("patchsrc");
1779
+ if (element.hasAttribute && element.hasAttribute("for") && _isPatchLinkageAttribute("for", lcTag)) element.removeAttribute("for");
1780
+ } catch (_) {}
1781
+ }
1782
+ return true;
1783
+ });
1784
+ };
1785
+ /**
1786
+ * _initDocument
1787
+ *
1788
+ * @param dirty - a string of dirty markup
1789
+ * @return a DOM, filled with the dirty markup
1790
+ */
1791
+ const _initDocument = function _initDocument(dirty) {
1792
+ let doc = null;
1793
+ let leadingWhitespace = null;
1794
+ if (FORCE_BODY) dirty = "<remove></remove>" + dirty;
1795
+ else {
1796
+ const matches = stringMatch(dirty, LEADING_WHITESPACE);
1797
+ leadingWhitespace = matches && matches[0];
1798
+ }
1799
+ if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) dirty = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body>" + dirty + "</body></html>";
1800
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
1801
+ if (NAMESPACE === HTML_NAMESPACE) try {
1802
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
1803
+ } catch (_) {}
1804
+ if (!doc || !doc.documentElement) {
1805
+ doc = implementation.createDocument(NAMESPACE, "template", null);
1806
+ try {
1807
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
1808
+ } catch (_) {}
1809
+ }
1810
+ const body = doc.body || doc.documentElement;
1811
+ if (dirty && leadingWhitespace) body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
1812
+ if (NAMESPACE === HTML_NAMESPACE) return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
1813
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
1814
+ };
1815
+ /**
1816
+ * Creates a NodeIterator over `root`. ownerDocument is read through the
1817
+ * cached getter: a form child named "ownerDocument" shadows the direct
1818
+ * read and would make createNodeIterator throw.
1819
+ *
1820
+ * @param root The node to start traversing on.
1821
+ * @param characterDataOnly whether to skip elements
1822
+ * @return The created NodeIterator
1823
+ */
1824
+ const _createNodeIterator = function _createNodeIterator(root) {
1825
+ let characterDataOnly = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1826
+ const doc = getOwnerDocument ? getOwnerDocument(root) : root.ownerDocument;
1827
+ return createNodeIterator.call(doc || root, root, (characterDataOnly ? 0 : NodeFilter.SHOW_ELEMENT) | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
1828
+ };
1829
+ /**
1830
+ * Replace template expression syntax (mustache, ERB, template
1831
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
1832
+ * sites. Order matters: mustache, then ERB, then template literal.
1833
+ *
1834
+ * @param value the string to scrub
1835
+ * @returns the scrubbed string
1836
+ */
1837
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
1838
+ value = stringReplace(value, MUSTACHE_EXPR$1, " ");
1839
+ value = stringReplace(value, ERB_EXPR$1, " ");
1840
+ value = stringReplace(value, TMPLIT_EXPR$1, " ");
1841
+ return value;
1842
+ };
1843
+ /**
1844
+ * Strips template expressions from the character data under `node`,
1845
+ * template contents included. Runs after the walk, since an expression can
1846
+ * also form when a removed element leaves two text nodes adjacent. Works on
1847
+ * the nodes rather than on markup, which keeps node references intact and
1848
+ * sees `<%` unescaped. Attribute values are handled in _sanitizeAttributes.
1849
+ *
1850
+ * @param node The root element whose character data should be scrubbed.
1851
+ */
1852
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
1853
+ var _node$querySelectorAl;
1854
+ _scrubOwnCharacterData(node);
1855
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, "template");
1856
+ if (templates) arrayForEach(templates, (tmpl) => {
1857
+ if (_isDocumentFragment(tmpl.content)) _scrubTemplateExpressions2(tmpl.content);
1858
+ });
1859
+ };
1860
+ /**
1861
+ * Normalizes `node` and strips template expressions from its own character
1862
+ * data. Template contents and shadow roots are not entered, their own
1863
+ * _sanitizeShadowDOM call scrubs them.
1864
+ *
1865
+ * @param node The root whose own character data should be scrubbed.
1866
+ */
1867
+ const _scrubOwnCharacterData = function _scrubOwnCharacterData(node) {
1868
+ node.normalize();
1869
+ const walker = _createNodeIterator(node, true);
1870
+ let currentNode = walker.nextNode();
1871
+ while (currentNode) {
1872
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
1873
+ currentNode = walker.nextNode();
1874
+ }
1875
+ };
1876
+ /**
1877
+ * Detects DOM clobbering on a form, the only element whose named children
1878
+ * shadow its own properties. Each probe compares a direct read with what
1879
+ * the property has to be.
1880
+ *
1881
+ * @param element element to check for clobbering attacks
1882
+ * @return true if clobbered, false if safe
1883
+ */
1884
+ const _isClobbered = function _isClobbered(element) {
1885
+ const realTagName = getNodeName ? getNodeName(element) : null;
1886
+ if (typeof realTagName !== "string") return false;
1887
+ if (transformCaseFunc(realTagName) !== "form") return false;
1888
+ return typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || element.attributes !== getAttributes(element) || typeof element.removeAttribute !== "function" || typeof element.removeAttributeNode !== "function" || typeof element.getAttributeNode !== "function" || typeof element.setAttribute !== "function" || typeof element.namespaceURI !== "string" || typeof element.insertBefore !== "function" || typeof element.hasChildNodes !== "function" || element.nodeType !== getNodeType(element) || element.childNodes !== getChildNodes(element);
1889
+ };
1890
+ /**
1891
+ * Reads nodeType through the cached getter, so the result holds for nodes
1892
+ * from any realm (GHSA-4w3q-35jp-p934) and cannot be clobbered.
1893
+ *
1894
+ * @param value anything
1895
+ * @return the node type, or null if value is not a DOM node
1896
+ */
1897
+ const _nodeTypeOf = function _nodeTypeOf(value) {
1898
+ if (!getNodeType || typeof value !== "object" || value === null) return null;
1899
+ try {
1900
+ const nodeType = getNodeType(value);
1901
+ return typeof nodeType === "number" ? nodeType : null;
1902
+ } catch (_) {
1903
+ return null;
1904
+ }
1905
+ };
1906
+ const _isDocumentFragment = function _isDocumentFragment(value) {
1907
+ return _nodeTypeOf(value) === NODE_TYPE.documentFragment;
1908
+ };
1909
+ const _isNode = function _isNode(value) {
1910
+ return _nodeTypeOf(value) !== null;
1911
+ };
1912
+ function _executeHooks(hooks, currentNode, data) {
1913
+ if (hooks.length === 0) return;
1914
+ arrayForEach(hooks, (hook) => {
1915
+ hook.call(DOMPurify, currentNode, data, CONFIG);
1916
+ });
1917
+ }
1918
+ /**
1919
+ * Structural-threat checks that condemn a node regardless of the
1920
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
1921
+ * processing instructions, markup-bearing comments. Pure predicate;
1922
+ * the caller removes. Check order is load-bearing.
1923
+ *
1924
+ * @param currentNode the node to inspect
1925
+ * @param tagName the node's transformCaseFunc'd tag name
1926
+ * @param nodeType the node's type, read through the cached getter
1927
+ * @return true if the node must be removed
1928
+ */
1929
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName, nodeType) {
1930
+ if (SAFE_FOR_XML && nodeType === NODE_TYPE.element && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
1931
+ if (SAFE_FOR_XML && LITERAL_TEXT_ELEMENTS[tagName] && nodeType === NODE_TYPE.element && _readNamespaceURI(currentNode) === HTML_NAMESPACE && (_isNode(currentNode.firstElementChild) || typeof currentNode.textContent === "string" && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent))) return true;
1932
+ if (nodeType === NODE_TYPE.processingInstruction) return true;
1933
+ if (SAFE_FOR_XML && nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
1934
+ return false;
1935
+ };
1936
+ /**
1937
+ * Evaluate a CUSTOM_ELEMENT_HANDLING check (a RegExp or a predicate
1938
+ * function, per the validation in _parseConfig) against a name.
1939
+ * Additional arguments are forwarded to predicate functions - the
1940
+ * attributeNameCheck predicate receives the tag name as its second
1941
+ * argument. A null/absent check never matches.
1942
+ *
1943
+ * @param check the configured tagNameCheck / attributeNameCheck value
1944
+ * @param name the name to test
1945
+ * @param args extra arguments forwarded to a predicate function
1946
+ * @return true if the check matches the name
1947
+ */
1948
+ const _matchesNameCheck = function _matchesNameCheck(check, name) {
1949
+ if (check instanceof RegExp) return regExpTest(check, name);
1950
+ if (check instanceof Function) {
1951
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) args[_key - 2] = arguments[_key];
1952
+ return Boolean(check(name, ...args));
1953
+ }
1954
+ return false;
1955
+ };
1956
+ /**
1957
+ * Handles a node whose tag is forbidden or not allowlisted: hoists its
1958
+ * content per KEEP_CONTENT and removes it. The one exception is a custom
1959
+ * element allowed via CUSTOM_ELEMENT_HANDLING, which is kept.
1960
+ *
1961
+ * @param currentNode the disallowed node
1962
+ * @param tagName the node's transformCaseFunc'd tag name
1963
+ * @return true if the node was removed, false if kept
1964
+ */
1965
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName, root) {
1966
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
1967
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName] && !FORBID_CONTENTS[stringToLowerCase(tagName)]) {
1968
+ const parentNode = getParentNode(currentNode);
1969
+ const childNodes = getChildNodes(currentNode);
1970
+ if (childNodes && parentNode) {
1971
+ const childCount = childNodes.length;
1972
+ for (let i = childCount - 1; i >= 0; --i) {
1973
+ const hoisted = currentNode === root ? cloneNode(childNodes[i], true) : childNodes[i];
1974
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
1975
+ }
1976
+ }
1977
+ }
1978
+ _forceRemove(currentNode);
1979
+ return true;
1980
+ };
1981
+ /**
1982
+ * Forks an allowlist off its shared binding (the instance default or the
1983
+ * setConfig() capture) before a hook sees it, so a hook's widening stays
1984
+ * within the call. A set that is already call-local is returned as is.
1985
+ *
1986
+ * @param hookList the uponSanitize* hook array for this event
1987
+ * @param set the current ALLOWED_TAGS / ALLOWED_ATTR binding
1988
+ * @param defaultSet the per-instance DEFAULT_ALLOWED_* constant
1989
+ * @param setConfigSet the captured setConfig() binding, or null
1990
+ * @return a call-local clone if a hook is present and set is still shared,
1991
+ * else set unchanged
1992
+ */
1993
+ const _forkSharedAllowlist = function _forkSharedAllowlist(hookList, set, defaultSet, setConfigSet) {
1994
+ if (hookList.length === 0) return set;
1995
+ return set === defaultSet || set === setConfigSet ? cloneSet(set) : set;
1996
+ };
1997
+ /**
1998
+ * A hook may have detached the node it was called for. If so, treat it as
1999
+ * removed and stop processing it; the walk root is exempt. On the IN_PLACE
2000
+ * path the detached subtree is neutralized right away.
2001
+ *
2002
+ * @param currentNode the node a hook may have detached
2003
+ * @param root the current walk root
2004
+ * @return true if the node was detached
2005
+ */
2006
+ const _handleHookDetachedNode = function _handleHookDetachedNode(currentNode, root) {
2007
+ if (currentNode === root || getParentNode(currentNode) !== null) return false;
2008
+ if (IN_PLACE) _neutralizeSubtree(currentNode);
2009
+ return true;
2010
+ };
2011
+ /**
2012
+ * _sanitizeElements
2013
+ *
2014
+ * @protect nodeName
2015
+ * @protect textContent
2016
+ * @protect removeChild
2017
+ * @param currentNode to check for permission to exist
2018
+ * @return true if node was killed, false if left alive
2019
+ */
2020
+ const _sanitizeElements = function _sanitizeElements(currentNode, root) {
2021
+ _markVisited(currentNode);
2022
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
2023
+ if (_handleHookDetachedNode(currentNode, root)) return true;
2024
+ if (_isClobbered(currentNode)) {
2025
+ _forceRemove(currentNode);
2026
+ return true;
2027
+ }
2028
+ const tagName = transformCaseFunc(_readNodeName(currentNode));
2029
+ const nodeType = _readNodeType(currentNode);
2030
+ ALLOWED_TAGS = _forkSharedAllowlist(hooks.uponSanitizeElement, ALLOWED_TAGS, DEFAULT_ALLOWED_TAGS, SET_CONFIG_ALLOWED_TAGS);
2031
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
2032
+ tagName,
2033
+ allowedTags: ALLOWED_TAGS
2034
+ });
2035
+ if (_handleHookDetachedNode(currentNode, root)) return true;
2036
+ if (_isUnsafeNode(currentNode, tagName, nodeType)) {
2037
+ _forceRemove(currentNode);
2038
+ return true;
2039
+ }
2040
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
2041
+ const removed = _sanitizeDisallowedNode(currentNode, tagName, root);
2042
+ if (removed === false) {
2043
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
2044
+ if (_handleHookDetachedNode(currentNode, root)) return true;
2045
+ }
2046
+ return removed;
2047
+ }
2048
+ if (nodeType === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
2049
+ _forceRemove(currentNode);
2050
+ return true;
2051
+ }
2052
+ if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
2053
+ _forceRemove(currentNode);
2054
+ return true;
2055
+ }
2056
+ if (SAFE_FOR_TEMPLATES && nodeType === NODE_TYPE.text) {
2057
+ const text = currentNode.textContent;
2058
+ const content = _stripTemplateExpressions(text);
2059
+ if (text !== content) {
2060
+ arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
2061
+ currentNode.textContent = content;
2062
+ }
2063
+ }
2064
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
2065
+ return _handleHookDetachedNode(currentNode, root);
2066
+ };
2067
+ /**
2068
+ * _isValidAttribute
2069
+ *
2070
+ * @param lcTag Lowercase tag name of containing element.
2071
+ * @param lcName Lowercase attribute name.
2072
+ * @param value Attribute value.
2073
+ * @return Returns true if `value` is valid, otherwise false.
2074
+ */
2075
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
2076
+ if (FORBID_ATTR[lcName]) return false;
2077
+ if (_isPatchLinkageAttribute(lcName, lcTag)) return false;
2078
+ if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document || value in formElement)) return false;
2079
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
2080
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) return true;
2081
+ if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) return true;
2082
+ if (!nameIsPermitted) return _isBasicCustomElement(lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName, lcTag) || lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value);
2083
+ if (URI_SAFE_ATTRIBUTES[lcName]) return true;
2084
+ const compactValue = stringReplace(value, ATTR_WHITESPACE$1, "");
2085
+ if (regExpTest(IS_ALLOWED_URI$1, compactValue)) return true;
2086
+ if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) return true;
2087
+ if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, compactValue)) return true;
2088
+ return !value;
2089
+ };
2090
+ const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, [
2091
+ "annotation-xml",
2092
+ "color-profile",
2093
+ "font-face",
2094
+ "font-face-format",
2095
+ "font-face-name",
2096
+ "font-face-src",
2097
+ "font-face-uri",
2098
+ "missing-glyph"
2099
+ ]);
2100
+ /**
2101
+ * _isBasicCustomElement
2102
+ * checks if at least one dash is included in tagName, and it's not the first char
2103
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
2104
+ *
2105
+ * @param tagName name of the tag of the node to sanitize
2106
+ * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
2107
+ */
2108
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
2109
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
2110
+ };
2111
+ /**
2112
+ * Wrap an attribute value in the matching Trusted Types object when
2113
+ * the active policy requires it. Namespaced attributes pass through
2114
+ * unchanged (no TT support yet, see
2115
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
2116
+ *
2117
+ * @param lcTag lowercase tag name of the containing element
2118
+ * @param lcName lowercase attribute name
2119
+ * @param namespaceURI the attribute's namespace, if any
2120
+ * @param value the attribute value to wrap
2121
+ * @return the value, wrapped when Trusted Types demand it
2122
+ */
2123
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
2124
+ if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function" && !namespaceURI) switch (trustedTypes.getAttributeType(lcTag, lcName)) {
2125
+ case "TrustedHTML": return _createTrustedHTML(value);
2126
+ case "TrustedScriptURL": return _createTrustedScriptURL(value);
2127
+ }
2128
+ return value;
2129
+ };
2130
+ /**
2131
+ * Writes a changed attribute value back. If the new value clobbers, the
2132
+ * element is removed; if the write fails, the attribute is.
2133
+ *
2134
+ * @param currentNode the element carrying the attribute
2135
+ * @param name the attribute name as present on the element
2136
+ * @param namespaceURI the attribute's namespace, if any
2137
+ * @param value the new attribute value
2138
+ * @return true if the value was written without introducing clobbering
2139
+ */
2140
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
2141
+ try {
2142
+ if (namespaceURI) currentNode.setAttributeNS(namespaceURI, name, value);
2143
+ else currentNode.setAttribute(name, value);
2144
+ if (_isClobbered(currentNode)) {
2145
+ _forceRemove(currentNode);
2146
+ return false;
2147
+ }
2148
+ return true;
2149
+ } catch (_) {
2150
+ _removeAttribute(name, currentNode);
2151
+ return false;
2152
+ }
2153
+ };
2154
+ /**
2155
+ * Value checks that apply before a hook can force-keep an attribute. Also
2156
+ * used by isValidAttribute(), so it never approves a value that sanitize()
2157
+ * would strip.
2158
+ *
2159
+ * @param name the attribute name as found on the node (case preserved)
2160
+ * @param value the attribute value
2161
+ * @returns true if the attribute must be removed because of its value
2162
+ */
2163
+ const _isUnsafeAttributeValue = function _isUnsafeAttributeValue(name, value) {
2164
+ if (SAFE_FOR_XML && regExpTest(ATTR_VALUE_BREAKOUT, value)) return true;
2165
+ return stringToLowerCase(name) === "attributename" && stringIndexOf(value, "href") !== -1;
2166
+ };
2167
+ /**
2168
+ * _sanitizeAttributes
2169
+ *
2170
+ * @protect attributes
2171
+ * @protect nodeName
2172
+ * @protect removeAttribute
2173
+ * @protect setAttribute
2174
+ *
2175
+ * @param currentNode to sanitize
2176
+ * @param root the current walk root
2177
+ */
2178
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode, root) {
2179
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
2180
+ if (_handleHookDetachedNode(currentNode, root)) return;
2181
+ const attributes = currentNode.attributes;
2182
+ if (!attributes || _isClobbered(currentNode)) return;
2183
+ ALLOWED_ATTR = _forkSharedAllowlist(hooks.uponSanitizeAttribute, ALLOWED_ATTR, DEFAULT_ALLOWED_ATTR, SET_CONFIG_ALLOWED_ATTR);
2184
+ const hookEvent = {
2185
+ attrName: "",
2186
+ attrValue: "",
2187
+ keepAttr: true,
2188
+ allowedAttributes: ALLOWED_ATTR,
2189
+ forceKeepAttr: void 0
2190
+ };
2191
+ let l = attributes.length;
2192
+ const lcTag = transformCaseFunc(_readNodeName(currentNode));
2193
+ while (l--) {
2194
+ const attr = attributes[l];
2195
+ const name = attr.name, namespaceURI = attr.namespaceURI, attrValue = attr.value;
2196
+ const lcName = transformCaseFunc(name);
2197
+ const initValue = attrValue;
2198
+ let value = name === "value" ? initValue : stringTrim(initValue);
2199
+ let recreatedNamedProp = false;
2200
+ hookEvent.attrName = lcName;
2201
+ hookEvent.attrValue = value;
2202
+ hookEvent.keepAttr = true;
2203
+ hookEvent.forceKeepAttr = void 0;
2204
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
2205
+ value = hookEvent.attrValue;
2206
+ if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name") && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
2207
+ _removeAttribute(name, currentNode, attr);
2208
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
2209
+ recreatedNamedProp = true;
2210
+ }
2211
+ if (_isUnsafeAttributeValue(name, value)) {
2212
+ _removeAttribute(name, currentNode, attr);
2213
+ continue;
2214
+ }
2215
+ if (hookEvent.forceKeepAttr) continue;
2216
+ if (!hookEvent.keepAttr) {
2217
+ _removeAttribute(name, currentNode, attr);
2218
+ continue;
2219
+ }
2220
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
2221
+ _removeAttribute(name, currentNode, attr);
2222
+ continue;
2223
+ }
2224
+ if (SAFE_FOR_TEMPLATES) value = _stripTemplateExpressions(value);
2225
+ if (!_isValidAttribute(lcTag, lcName, value)) {
2226
+ _removeAttribute(name, currentNode, attr);
2227
+ continue;
2228
+ }
2229
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
2230
+ if (value !== initValue) {
2231
+ if (_setAttributeValue(currentNode, name, namespaceURI, value) && recreatedNamedProp) arrayPop(DOMPurify.removed);
2232
+ }
2233
+ }
2234
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
2235
+ _handleHookDetachedNode(currentNode, root);
2236
+ };
2237
+ /**
2238
+ * Sanitizes one node: the node itself, its attributes and, for a
2239
+ * template, its content.
2240
+ *
2241
+ * @param node the node to sanitize
2242
+ * @param root the current walk root
2243
+ */
2244
+ const _sanitizeNode = function _sanitizeNode(node, root) {
2245
+ _sanitizeElements(node, root);
2246
+ _sanitizeAttributes(node, root);
2247
+ if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
2248
+ };
2249
+ /**
2250
+ * _sanitizeShadowDOM
2251
+ *
2252
+ * @param fragment to iterate over recursively
2253
+ */
2254
+ const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
2255
+ let shadowNode = null;
2256
+ const shadowIterator = _createNodeIterator(fragment);
2257
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
2258
+ while (shadowNode = shadowIterator.nextNode()) {
2259
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
2260
+ _sanitizeNode(shadowNode, fragment);
2261
+ if (_readNodeType(shadowNode) === NODE_TYPE.element) {
2262
+ const innerSr = getShadowRoot(shadowNode);
2263
+ if (_isDocumentFragment(innerSr)) {
2264
+ _sanitizeAttachedShadowRoots(innerSr);
2265
+ _sanitizeShadowDOM2(innerSr);
2266
+ }
2267
+ }
2268
+ }
2269
+ if (SAFE_FOR_TEMPLATES) _scrubOwnCharacterData(fragment);
2270
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
2271
+ };
2272
+ /**
2273
+ * Sanitizes every attached shadow root under `root`, since the node
2274
+ * iterator does not enter shadow trees. Needed for IN_PLACE input and for
2275
+ * DOM input whose clonable shadow roots were copied by importNode().
2276
+ *
2277
+ * @param root the subtree root to walk for attached shadow roots
2278
+ */
2279
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
2280
+ const stack = [{
2281
+ node: root,
2282
+ shadow: null
2283
+ }];
2284
+ while (stack.length > 0) {
2285
+ const item = stack.pop();
2286
+ if (item.shadow) {
2287
+ _sanitizeShadowDOM2(item.shadow);
2288
+ continue;
2289
+ }
2290
+ const node = item.node;
2291
+ const isElement = _readNodeType(node) === NODE_TYPE.element;
2292
+ const childNodes = getChildNodes(node);
2293
+ if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push({
2294
+ node: childNodes[i],
2295
+ shadow: null
2296
+ });
2297
+ if (isElement) {
2298
+ const rootName = getNodeName ? getNodeName(node) : null;
2299
+ if (typeof rootName === "string" && transformCaseFunc(rootName) === "template") {
2300
+ const content = node.content;
2301
+ if (_isDocumentFragment(content)) stack.push({
2302
+ node: content,
2303
+ shadow: null
2304
+ });
2305
+ }
2306
+ }
2307
+ if (isElement) {
2308
+ const sr = getShadowRoot(node);
2309
+ if (_isDocumentFragment(sr)) stack.push({
2310
+ node: null,
2311
+ shadow: sr
2312
+ }, {
2313
+ node: sr,
2314
+ shadow: null
2315
+ });
2316
+ }
2317
+ }
2318
+ };
2319
+ DOMPurify.sanitize = function(dirty) {
2320
+ let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2321
+ let body = null;
2322
+ let importedNode = null;
2323
+ let currentNode = null;
2324
+ let returnNode = null;
2325
+ IS_EMPTY_INPUT = !dirty;
2326
+ if (IS_EMPTY_INPUT) dirty = "<!-->";
2327
+ if (typeof dirty !== "string" && !_isNode(dirty)) {
2328
+ dirty = stringifyValue(dirty);
2329
+ if (typeof dirty !== "string") throw typeErrorCreate("dirty is not a string, aborting");
2330
+ }
2331
+ if (!DOMPurify.isSupported) return dirty;
2332
+ if (SET_CONFIG) {
2333
+ ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
2334
+ ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
2335
+ } else _parseConfig(cfg);
2336
+ DOMPurify.removed = [];
2337
+ const inPlace = IN_PLACE && typeof dirty !== "string" && _isNode(dirty);
2338
+ let inPlaceNodes = [];
2339
+ const outerVisited = IN_PLACE_VISITED;
2340
+ if (inPlace) {
2341
+ _neutralizePatchLinkage(dirty);
2342
+ const nn = _readNodeName(dirty);
2343
+ if (typeof nn === "string") {
2344
+ const tagName = transformCaseFunc(nn);
2345
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
2346
+ _neutralizeRoot(dirty);
2347
+ throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
2348
+ }
2349
+ }
2350
+ if (_isClobbered(dirty)) {
2351
+ _neutralizeRoot(dirty);
2352
+ throw typeErrorCreate("root node is clobbered and cannot be sanitized in-place");
2353
+ }
2354
+ inPlaceNodes = _collectLiveNodes(dirty);
2355
+ IN_PLACE_VISITED = setCreate();
2356
+ } else if (_isNode(dirty)) {
2357
+ body = _initDocument("<!---->");
2358
+ importedNode = body.ownerDocument.importNode(dirty, true);
2359
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") body = importedNode;
2360
+ else if (importedNode.nodeName === "HTML") body = importedNode;
2361
+ else body.appendChild(importedNode);
2362
+ _sanitizeAttachedShadowRoots(body);
2363
+ } else {
2364
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return _signOutput(dirty);
2365
+ body = _initDocument(dirty);
2366
+ if (!body) return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
2367
+ }
2368
+ if (body && FORCE_BODY) _forceRemove(body.firstChild);
2369
+ const walkRoot = inPlace ? dirty : body;
2370
+ try {
2371
+ if (inPlace) _sanitizeAttachedShadowRoots(dirty);
2372
+ const nodeIterator = _createNodeIterator(walkRoot);
2373
+ while (currentNode = nodeIterator.nextNode()) _sanitizeNode(currentNode, walkRoot);
2374
+ if (inPlace) _sanitizeUnvisitedNodes(dirty, inPlaceNodes);
2375
+ } catch (error) {
2376
+ if (inPlace) {
2377
+ _neutralizeRoot(dirty);
2378
+ _neutralizeDiscarded(dirty, inPlaceNodes);
2379
+ }
2380
+ throw error;
2381
+ } finally {
2382
+ IN_PLACE_VISITED = outerVisited;
2383
+ }
2384
+ if (inPlace) {
2385
+ if (_neutralizeDiscarded(dirty, inPlaceNodes)) throw typeErrorCreate("a node selected for removal could not be safely returned; refusing to sanitize in place");
2386
+ if (SAFE_FOR_TEMPLATES) _scrubTemplateExpressions2(dirty);
2387
+ return dirty;
2388
+ }
2389
+ if (RETURN_DOM) {
2390
+ if (SAFE_FOR_TEMPLATES) _scrubTemplateExpressions2(body);
2391
+ if (RETURN_DOM_FRAGMENT) {
2392
+ returnNode = createDocumentFragment.call(body.ownerDocument);
2393
+ while (body.firstChild) returnNode.appendChild(body.firstChild);
2394
+ } else returnNode = body;
2395
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) returnNode = importNode.call(originalDocument, returnNode, true);
2396
+ return returnNode;
2397
+ }
2398
+ const serialize = () => WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
2399
+ let serializedHTML = serialize();
2400
+ if (SAFE_FOR_TEMPLATES && regExpTest(TMPL_MARKER_SERIALIZED, serializedHTML)) {
2401
+ _scrubOwnCharacterData(body);
2402
+ serializedHTML = serialize();
2403
+ }
2404
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
2405
+ return _signOutput(serializedHTML);
2406
+ };
2407
+ DOMPurify.setConfig = function() {
2408
+ let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
2409
+ _parseConfig(cfg);
2410
+ SET_CONFIG = true;
2411
+ SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
2412
+ SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
2413
+ };
2414
+ DOMPurify.clearConfig = function() {
2415
+ CONFIG = null;
2416
+ SET_CONFIG = false;
2417
+ SET_CONFIG_ALLOWED_TAGS = null;
2418
+ SET_CONFIG_ALLOWED_ATTR = null;
2419
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
2420
+ emptyHTML = "";
2421
+ };
2422
+ DOMPurify.isValidAttribute = function(tag, attr, value) {
2423
+ if (!CONFIG) _parseConfig({});
2424
+ const lcTag = transformCaseFunc(tag);
2425
+ const lcName = transformCaseFunc(attr);
2426
+ if (typeof value === "string" && (_isUnsafeAttributeValue(attr, value) || !ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value))) return false;
2427
+ return _isValidAttribute(lcTag, lcName, value);
2428
+ };
2429
+ DOMPurify.addHook = function(entryPoint, hookFunction) {
2430
+ if (typeof hookFunction !== "function") return;
2431
+ if (!objectHasOwnProperty(hooks, entryPoint)) return;
2432
+ arrayPush(hooks[entryPoint], hookFunction);
2433
+ };
2434
+ DOMPurify.removeHook = function(entryPoint, hookFunction) {
2435
+ if (!objectHasOwnProperty(hooks, entryPoint)) return;
2436
+ if (hookFunction !== void 0) {
2437
+ const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
2438
+ return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
2439
+ }
2440
+ return arrayPop(hooks[entryPoint]);
2441
+ };
2442
+ DOMPurify.removeHooks = function(entryPoint) {
2443
+ if (!objectHasOwnProperty(hooks, entryPoint)) return;
2444
+ hooks[entryPoint] = [];
2445
+ };
2446
+ DOMPurify.removeAllHooks = function() {
2447
+ hooks = _createHooksMap();
2448
+ };
2449
+ return DOMPurify;
2450
+ }
2451
+ var purify_default = createDOMPurify();
2452
+ export { purify_default as default };
2453
+
2454
+ //# sourceMappingURL=purify.es.mjs.map