umap-project 2.1.2__py3-none-any.whl → 2.2.0__py3-none-any.whl

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.

Potentially problematic release.


This version of umap-project might be problematic. Click here for more details.

Files changed (211) hide show
  1. umap/__init__.py +1 -1
  2. umap/context_processors.py +1 -0
  3. umap/locale/br/LC_MESSAGES/django.mo +0 -0
  4. umap/locale/en/LC_MESSAGES/django.po +32 -32
  5. umap/locale/hu/LC_MESSAGES/django.mo +0 -0
  6. umap/locale/it/LC_MESSAGES/django.mo +0 -0
  7. umap/locale/ms/LC_MESSAGES/django.mo +0 -0
  8. umap/migrations/0020_alter_tilelayer_url_template.py +19 -0
  9. umap/migrations/0021_remove_map_description.py +16 -0
  10. umap/models.py +10 -6
  11. umap/settings/base.py +1 -0
  12. umap/static/umap/base.css +43 -156
  13. umap/static/umap/content.css +7 -25
  14. umap/static/umap/css/icon.css +112 -0
  15. umap/static/umap/css/panel.css +140 -0
  16. umap/static/umap/img/16-white.svg +5 -1
  17. umap/static/umap/img/16.svg +7 -4
  18. umap/static/umap/img/24-white.svg +3 -1
  19. umap/static/umap/img/24.svg +3 -4
  20. umap/static/umap/img/source/16-white.svg +176 -940
  21. umap/static/umap/img/source/16.svg +8 -5
  22. umap/static/umap/img/source/24-white.svg +5 -3
  23. umap/static/umap/img/source/24.svg +6 -7
  24. umap/static/umap/js/modules/browser.js +97 -73
  25. umap/static/umap/js/modules/dompurify.js +12 -0
  26. umap/static/umap/js/modules/facets.js +149 -0
  27. umap/static/umap/js/modules/global.js +9 -1
  28. umap/static/umap/js/modules/i18n.js +7 -0
  29. umap/static/umap/js/modules/orderable.js +84 -0
  30. umap/static/umap/js/modules/panel.js +76 -0
  31. umap/static/umap/js/modules/request.js +0 -1
  32. umap/static/umap/js/modules/schema.js +324 -223
  33. umap/static/umap/js/modules/urls.js +1 -16
  34. umap/static/umap/js/modules/utils.js +340 -0
  35. umap/static/umap/js/umap.autocomplete.js +40 -25
  36. umap/static/umap/js/umap.controls.js +248 -361
  37. umap/static/umap/js/umap.core.js +77 -366
  38. umap/static/umap/js/umap.datalayer.permissions.js +1 -1
  39. umap/static/umap/js/umap.features.js +65 -43
  40. umap/static/umap/js/umap.forms.js +128 -36
  41. umap/static/umap/js/umap.icon.js +11 -4
  42. umap/static/umap/js/umap.importer.js +78 -58
  43. umap/static/umap/js/umap.js +206 -192
  44. umap/static/umap/js/umap.layer.js +86 -46
  45. umap/static/umap/js/umap.permissions.js +13 -9
  46. umap/static/umap/js/umap.popup.js +26 -30
  47. umap/static/umap/js/umap.share.js +12 -9
  48. umap/static/umap/js/umap.tableeditor.js +4 -6
  49. umap/static/umap/js/umap.ui.js +10 -60
  50. umap/static/umap/locale/am_ET.js +243 -227
  51. umap/static/umap/locale/am_ET.json +21 -9
  52. umap/static/umap/locale/ar.js +243 -227
  53. umap/static/umap/locale/ar.json +21 -9
  54. umap/static/umap/locale/ast.js +243 -227
  55. umap/static/umap/locale/ast.json +21 -9
  56. umap/static/umap/locale/bg.js +243 -227
  57. umap/static/umap/locale/bg.json +21 -9
  58. umap/static/umap/locale/br.js +253 -237
  59. umap/static/umap/locale/br.json +25 -13
  60. umap/static/umap/locale/ca.js +243 -227
  61. umap/static/umap/locale/ca.json +21 -9
  62. umap/static/umap/locale/cs_CZ.js +243 -227
  63. umap/static/umap/locale/cs_CZ.json +21 -9
  64. umap/static/umap/locale/da.js +243 -227
  65. umap/static/umap/locale/da.json +21 -9
  66. umap/static/umap/locale/de.js +243 -227
  67. umap/static/umap/locale/de.json +21 -9
  68. umap/static/umap/locale/el.js +243 -227
  69. umap/static/umap/locale/el.json +21 -9
  70. umap/static/umap/locale/en.js +243 -234
  71. umap/static/umap/locale/en.json +22 -10
  72. umap/static/umap/locale/en_US.json +21 -9
  73. umap/static/umap/locale/es.js +243 -227
  74. umap/static/umap/locale/es.json +21 -9
  75. umap/static/umap/locale/et.js +243 -227
  76. umap/static/umap/locale/et.json +21 -9
  77. umap/static/umap/locale/eu.js +227 -199
  78. umap/static/umap/locale/eu.json +1 -1
  79. umap/static/umap/locale/fa_IR.js +243 -227
  80. umap/static/umap/locale/fa_IR.json +21 -9
  81. umap/static/umap/locale/fi.js +243 -227
  82. umap/static/umap/locale/fi.json +21 -9
  83. umap/static/umap/locale/fr.js +243 -234
  84. umap/static/umap/locale/fr.json +21 -9
  85. umap/static/umap/locale/gl.js +243 -227
  86. umap/static/umap/locale/gl.json +21 -9
  87. umap/static/umap/locale/he.js +243 -227
  88. umap/static/umap/locale/he.json +21 -9
  89. umap/static/umap/locale/hr.js +243 -227
  90. umap/static/umap/locale/hr.json +21 -9
  91. umap/static/umap/locale/hu.js +243 -234
  92. umap/static/umap/locale/hu.json +21 -9
  93. umap/static/umap/locale/id.js +243 -227
  94. umap/static/umap/locale/id.json +21 -9
  95. umap/static/umap/locale/is.js +243 -227
  96. umap/static/umap/locale/is.json +21 -9
  97. umap/static/umap/locale/it.js +243 -234
  98. umap/static/umap/locale/it.json +21 -9
  99. umap/static/umap/locale/ja.js +243 -227
  100. umap/static/umap/locale/ja.json +21 -9
  101. umap/static/umap/locale/ko.js +243 -227
  102. umap/static/umap/locale/ko.json +21 -9
  103. umap/static/umap/locale/lt.js +243 -227
  104. umap/static/umap/locale/lt.json +21 -9
  105. umap/static/umap/locale/ms.js +243 -234
  106. umap/static/umap/locale/ms.json +22 -10
  107. umap/static/umap/locale/nl.js +246 -230
  108. umap/static/umap/locale/nl.json +21 -9
  109. umap/static/umap/locale/no.js +243 -227
  110. umap/static/umap/locale/no.json +21 -9
  111. umap/static/umap/locale/pl.js +243 -227
  112. umap/static/umap/locale/pl.json +21 -9
  113. umap/static/umap/locale/pl_PL.json +21 -9
  114. umap/static/umap/locale/pt.js +243 -227
  115. umap/static/umap/locale/pt.json +21 -9
  116. umap/static/umap/locale/pt_BR.js +243 -227
  117. umap/static/umap/locale/pt_BR.json +21 -9
  118. umap/static/umap/locale/pt_PT.js +243 -227
  119. umap/static/umap/locale/pt_PT.json +21 -9
  120. umap/static/umap/locale/ro.js +243 -227
  121. umap/static/umap/locale/ro.json +21 -9
  122. umap/static/umap/locale/ru.js +243 -227
  123. umap/static/umap/locale/ru.json +21 -9
  124. umap/static/umap/locale/si.js +1 -1
  125. umap/static/umap/locale/si.json +1 -1
  126. umap/static/umap/locale/sk_SK.js +243 -227
  127. umap/static/umap/locale/sk_SK.json +21 -9
  128. umap/static/umap/locale/sl.js +243 -227
  129. umap/static/umap/locale/sl.json +21 -9
  130. umap/static/umap/locale/sr.js +243 -227
  131. umap/static/umap/locale/sr.json +21 -9
  132. umap/static/umap/locale/sv.js +243 -227
  133. umap/static/umap/locale/sv.json +21 -9
  134. umap/static/umap/locale/th_TH.js +243 -227
  135. umap/static/umap/locale/th_TH.json +21 -9
  136. umap/static/umap/locale/tr.js +243 -227
  137. umap/static/umap/locale/tr.json +21 -9
  138. umap/static/umap/locale/uk_UA.js +243 -227
  139. umap/static/umap/locale/uk_UA.json +21 -9
  140. umap/static/umap/locale/vi.js +243 -227
  141. umap/static/umap/locale/vi.json +21 -9
  142. umap/static/umap/locale/vi_VN.json +21 -9
  143. umap/static/umap/locale/zh.js +243 -227
  144. umap/static/umap/locale/zh.json +21 -9
  145. umap/static/umap/locale/zh_CN.json +21 -9
  146. umap/static/umap/locale/zh_TW.Big5.json +21 -9
  147. umap/static/umap/locale/zh_TW.js +243 -234
  148. umap/static/umap/locale/zh_TW.json +21 -9
  149. umap/static/umap/map.css +124 -264
  150. umap/static/umap/test/DataLayer.js +1 -1
  151. umap/static/umap/test/Feature.js +0 -226
  152. umap/static/umap/test/Map.js +0 -304
  153. umap/static/umap/test/Polygon.js +0 -256
  154. umap/static/umap/test/Polyline.js +0 -116
  155. umap/static/umap/test/TableEditor.js +10 -10
  156. umap/static/umap/test/Util.js +0 -521
  157. umap/static/umap/test/index.html +1 -5
  158. umap/static/umap/unittests/URLs.js +1 -1
  159. umap/static/umap/unittests/utils.js +610 -0
  160. umap/static/umap/vars.css +9 -0
  161. umap/static/umap/vendors/dompurify/purify.es.mjs +1525 -0
  162. umap/static/umap/vendors/formbuilder/Leaflet.FormBuilder.js +1 -0
  163. umap/static/umap/vendors/iconlayers/iconLayers.js +1 -1
  164. umap/templates/umap/css.html +2 -0
  165. umap/templates/umap/js.html +0 -1
  166. umap/templates/umap/map_detail.html +4 -0
  167. umap/templates/umap/map_table.html +12 -10
  168. umap/templatetags/umap_tags.py +5 -0
  169. umap/tests/conftest.py +9 -0
  170. umap/tests/fixtures/test_upload_data.csv +2 -1
  171. umap/tests/fixtures/test_upload_data.umap +171 -0
  172. umap/tests/fixtures/test_upload_data_osm.json +33 -0
  173. umap/tests/integration/conftest.py +16 -0
  174. umap/tests/integration/test_anonymous_owned_map.py +30 -5
  175. umap/tests/integration/test_basics.py +21 -0
  176. umap/tests/integration/test_browser.py +16 -36
  177. umap/tests/integration/test_choropleth.py +89 -0
  178. umap/tests/integration/test_collaborative_editing.py +30 -1
  179. umap/tests/integration/test_dashboard.py +10 -0
  180. umap/tests/integration/test_datalayer.py +132 -0
  181. umap/tests/integration/test_draw_polygon.py +363 -0
  182. umap/tests/integration/test_draw_polyline.py +325 -0
  183. umap/tests/integration/test_edit_datalayer.py +145 -6
  184. umap/tests/integration/test_edit_map.py +202 -0
  185. umap/tests/integration/test_edit_marker.py +120 -0
  186. umap/tests/integration/test_edit_polygon.py +122 -0
  187. umap/tests/integration/test_facets_browser.py +132 -11
  188. umap/tests/integration/test_import.py +407 -10
  189. umap/tests/integration/test_map.py +36 -54
  190. umap/tests/integration/test_map_list.py +28 -0
  191. umap/tests/integration/test_owned_map.py +24 -6
  192. umap/tests/integration/test_picto.py +25 -38
  193. umap/tests/integration/test_querystring.py +9 -15
  194. umap/tests/integration/test_slideshow.py +0 -5
  195. umap/tests/integration/test_statics.py +3 -2
  196. umap/tests/integration/test_tableeditor.py +23 -0
  197. umap/tests/integration/test_tilelayer.py +10 -0
  198. umap/tests/integration/test_view_marker.py +64 -0
  199. umap/tests/integration/test_view_polygon.py +59 -0
  200. umap/tests/integration/test_view_polyline.py +51 -0
  201. umap/tests/test_map_views.py +13 -0
  202. {umap_project-2.1.2.dist-info → umap_project-2.2.0.dist-info}/METADATA +12 -12
  203. {umap_project-2.1.2.dist-info → umap_project-2.2.0.dist-info}/RECORD +206 -187
  204. {umap_project-2.1.2.dist-info → umap_project-2.2.0.dist-info}/WHEEL +1 -1
  205. umap/static/umap/test/Choropleth.js +0 -245
  206. umap/static/umap/test/Permissions.js +0 -74
  207. umap/static/umap/vendors/dompurify/purify.min.js +0 -3
  208. umap/static/umap/vendors/dompurify/purify.min.js.map +0 -1
  209. umap/tests/integration/test_drawing.py +0 -243
  210. {umap_project-2.1.2.dist-info → umap_project-2.2.0.dist-info}/entry_points.txt +0 -0
  211. {umap_project-2.1.2.dist-info → umap_project-2.2.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,1525 @@
1
+ /*! @license DOMPurify 3.1.0 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.1.0/LICENSE */
2
+
3
+ const {
4
+ entries,
5
+ setPrototypeOf,
6
+ isFrozen,
7
+ getPrototypeOf,
8
+ getOwnPropertyDescriptor
9
+ } = Object;
10
+ let {
11
+ freeze,
12
+ seal,
13
+ create
14
+ } = Object; // eslint-disable-line import/no-mutable-exports
15
+ let {
16
+ apply,
17
+ construct
18
+ } = typeof Reflect !== 'undefined' && Reflect;
19
+ if (!freeze) {
20
+ freeze = function freeze(x) {
21
+ return x;
22
+ };
23
+ }
24
+ if (!seal) {
25
+ seal = function seal(x) {
26
+ return x;
27
+ };
28
+ }
29
+ if (!apply) {
30
+ apply = function apply(fun, thisValue, args) {
31
+ return fun.apply(thisValue, args);
32
+ };
33
+ }
34
+ if (!construct) {
35
+ construct = function construct(Func, args) {
36
+ return new Func(...args);
37
+ };
38
+ }
39
+ const arrayForEach = unapply(Array.prototype.forEach);
40
+ const arrayPop = unapply(Array.prototype.pop);
41
+ const arrayPush = unapply(Array.prototype.push);
42
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
43
+ const stringToString = unapply(String.prototype.toString);
44
+ const stringMatch = unapply(String.prototype.match);
45
+ const stringReplace = unapply(String.prototype.replace);
46
+ const stringIndexOf = unapply(String.prototype.indexOf);
47
+ const stringTrim = unapply(String.prototype.trim);
48
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
49
+ const regExpTest = unapply(RegExp.prototype.test);
50
+ const typeErrorCreate = unconstruct(TypeError);
51
+
52
+ /**
53
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
54
+ *
55
+ * @param {Function} func - The function to be wrapped and called.
56
+ * @returns {Function} A new function that calls the given function with a specified thisArg and arguments.
57
+ */
58
+ function unapply(func) {
59
+ return function (thisArg) {
60
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
61
+ args[_key - 1] = arguments[_key];
62
+ }
63
+ return apply(func, thisArg, args);
64
+ };
65
+ }
66
+
67
+ /**
68
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
69
+ *
70
+ * @param {Function} func - The constructor function to be wrapped and called.
71
+ * @returns {Function} A new function that constructs an instance of the given constructor function with the provided arguments.
72
+ */
73
+ function unconstruct(func) {
74
+ return function () {
75
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
76
+ args[_key2] = arguments[_key2];
77
+ }
78
+ return construct(func, args);
79
+ };
80
+ }
81
+
82
+ /**
83
+ * Add properties to a lookup table
84
+ *
85
+ * @param {Object} set - The set to which elements will be added.
86
+ * @param {Array} array - The array containing elements to be added to the set.
87
+ * @param {Function} transformCaseFunc - An optional function to transform the case of each element before adding to the set.
88
+ * @returns {Object} The modified set with added elements.
89
+ */
90
+ function addToSet(set, array) {
91
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
92
+ if (setPrototypeOf) {
93
+ // Make 'in' and truthy checks like Boolean(set.constructor)
94
+ // independent of any properties defined on Object.prototype.
95
+ // Prevent prototype setters from intercepting set as a this value.
96
+ setPrototypeOf(set, null);
97
+ }
98
+ let l = array.length;
99
+ while (l--) {
100
+ let element = array[l];
101
+ if (typeof element === 'string') {
102
+ const lcElement = transformCaseFunc(element);
103
+ if (lcElement !== element) {
104
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
105
+ if (!isFrozen(array)) {
106
+ array[l] = lcElement;
107
+ }
108
+ element = lcElement;
109
+ }
110
+ }
111
+ set[element] = true;
112
+ }
113
+ return set;
114
+ }
115
+
116
+ /**
117
+ * Clean up an array to harden against CSPP
118
+ *
119
+ * @param {Array} array - The array to be cleaned.
120
+ * @returns {Array} The cleaned version of the array
121
+ */
122
+ function cleanArray(array) {
123
+ for (let index = 0; index < array.length; index++) {
124
+ const isPropertyExist = objectHasOwnProperty(array, index);
125
+ if (!isPropertyExist) {
126
+ array[index] = null;
127
+ }
128
+ }
129
+ return array;
130
+ }
131
+
132
+ /**
133
+ * Shallow clone an object
134
+ *
135
+ * @param {Object} object - The object to be cloned.
136
+ * @returns {Object} A new object that copies the original.
137
+ */
138
+ function clone(object) {
139
+ const newObject = create(null);
140
+ for (const [property, value] of entries(object)) {
141
+ const isPropertyExist = objectHasOwnProperty(object, property);
142
+ if (isPropertyExist) {
143
+ if (Array.isArray(value)) {
144
+ newObject[property] = cleanArray(value);
145
+ } else if (value && typeof value === 'object' && value.constructor === Object) {
146
+ newObject[property] = clone(value);
147
+ } else {
148
+ newObject[property] = value;
149
+ }
150
+ }
151
+ }
152
+ return newObject;
153
+ }
154
+
155
+ /**
156
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
157
+ *
158
+ * @param {Object} object - The object to look up the getter function in its prototype chain.
159
+ * @param {String} prop - The property name for which to find the getter function.
160
+ * @returns {Function} The getter function found in the prototype chain or a fallback function.
161
+ */
162
+ function lookupGetter(object, prop) {
163
+ while (object !== null) {
164
+ const desc = getOwnPropertyDescriptor(object, prop);
165
+ if (desc) {
166
+ if (desc.get) {
167
+ return unapply(desc.get);
168
+ }
169
+ if (typeof desc.value === 'function') {
170
+ return unapply(desc.value);
171
+ }
172
+ }
173
+ object = getPrototypeOf(object);
174
+ }
175
+ function fallbackValue() {
176
+ return null;
177
+ }
178
+ return fallbackValue;
179
+ }
180
+
181
+ const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
182
+
183
+ // SVG
184
+ const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
185
+ const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
186
+
187
+ // List of SVG elements that are disallowed by default.
188
+ // We still need to know them so that we can do namespace
189
+ // checks properly in case one wants to add them to
190
+ // allow-list.
191
+ const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
192
+ const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);
193
+
194
+ // Similarly to SVG, we want to know all MathML elements,
195
+ // even those that we disallow by default.
196
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
197
+ const text = freeze(['#text']);
198
+
199
+ const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);
200
+ const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
201
+ const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
202
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
203
+
204
+ // eslint-disable-next-line unicorn/better-regex
205
+ const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
206
+ const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
207
+ const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
208
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
209
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
210
+ const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
211
+ );
212
+
213
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
214
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
215
+ );
216
+
217
+ const DOCTYPE_NAME = seal(/^html$/i);
218
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
219
+
220
+ var EXPRESSIONS = /*#__PURE__*/Object.freeze({
221
+ __proto__: null,
222
+ MUSTACHE_EXPR: MUSTACHE_EXPR,
223
+ ERB_EXPR: ERB_EXPR,
224
+ TMPLIT_EXPR: TMPLIT_EXPR,
225
+ DATA_ATTR: DATA_ATTR,
226
+ ARIA_ATTR: ARIA_ATTR,
227
+ IS_ALLOWED_URI: IS_ALLOWED_URI,
228
+ IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
229
+ ATTR_WHITESPACE: ATTR_WHITESPACE,
230
+ DOCTYPE_NAME: DOCTYPE_NAME,
231
+ CUSTOM_ELEMENT: CUSTOM_ELEMENT
232
+ });
233
+
234
+ const getGlobal = function getGlobal() {
235
+ return typeof window === 'undefined' ? null : window;
236
+ };
237
+
238
+ /**
239
+ * Creates a no-op policy for internal use only.
240
+ * Don't export this function outside this module!
241
+ * @param {TrustedTypePolicyFactory} trustedTypes The policy factory.
242
+ * @param {HTMLScriptElement} purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
243
+ * @return {TrustedTypePolicy} The policy created (or null, if Trusted Types
244
+ * are not supported or creating the policy failed).
245
+ */
246
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
247
+ if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
248
+ return null;
249
+ }
250
+
251
+ // Allow the callers to control the unique policy name
252
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
253
+ // Policy creation with duplicate names throws in Trusted Types.
254
+ let suffix = null;
255
+ const ATTR_NAME = 'data-tt-policy-suffix';
256
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
257
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
258
+ }
259
+ const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
260
+ try {
261
+ return trustedTypes.createPolicy(policyName, {
262
+ createHTML(html) {
263
+ return html;
264
+ },
265
+ createScriptURL(scriptUrl) {
266
+ return scriptUrl;
267
+ }
268
+ });
269
+ } catch (_) {
270
+ // Policy creation failed (most likely another DOMPurify script has
271
+ // already run). Skip creating the policy, as this will only cause errors
272
+ // if TT are enforced.
273
+ console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
274
+ return null;
275
+ }
276
+ };
277
+ function createDOMPurify() {
278
+ let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
279
+ const DOMPurify = root => createDOMPurify(root);
280
+
281
+ /**
282
+ * Version label, exposed for easier checks
283
+ * if DOMPurify is up to date or not
284
+ */
285
+ DOMPurify.version = '3.1.0';
286
+
287
+ /**
288
+ * Array of elements that DOMPurify removed during sanitation.
289
+ * Empty if nothing was removed.
290
+ */
291
+ DOMPurify.removed = [];
292
+ if (!window || !window.document || window.document.nodeType !== 9) {
293
+ // Not running in a browser, provide a factory function
294
+ // so that you can pass your own Window
295
+ DOMPurify.isSupported = false;
296
+ return DOMPurify;
297
+ }
298
+ let {
299
+ document
300
+ } = window;
301
+ const originalDocument = document;
302
+ const currentScript = originalDocument.currentScript;
303
+ const {
304
+ DocumentFragment,
305
+ HTMLTemplateElement,
306
+ Node,
307
+ Element,
308
+ NodeFilter,
309
+ NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
310
+ HTMLFormElement,
311
+ DOMParser,
312
+ trustedTypes
313
+ } = window;
314
+ const ElementPrototype = Element.prototype;
315
+ const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
316
+ const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
317
+ const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
318
+ const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
319
+
320
+ // As per issue #47, the web-components registry is inherited by a
321
+ // new document created via createHTMLDocument. As per the spec
322
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
323
+ // a new empty registry is used when creating a template contents owner
324
+ // document, so we use that as our parent document to ensure nothing
325
+ // is inherited.
326
+ if (typeof HTMLTemplateElement === 'function') {
327
+ const template = document.createElement('template');
328
+ if (template.content && template.content.ownerDocument) {
329
+ document = template.content.ownerDocument;
330
+ }
331
+ }
332
+ let trustedTypesPolicy;
333
+ let emptyHTML = '';
334
+ const {
335
+ implementation,
336
+ createNodeIterator,
337
+ createDocumentFragment,
338
+ getElementsByTagName
339
+ } = document;
340
+ const {
341
+ importNode
342
+ } = originalDocument;
343
+ let hooks = {};
344
+
345
+ /**
346
+ * Expose whether this browser supports running the full DOMPurify.
347
+ */
348
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
349
+ const {
350
+ MUSTACHE_EXPR,
351
+ ERB_EXPR,
352
+ TMPLIT_EXPR,
353
+ DATA_ATTR,
354
+ ARIA_ATTR,
355
+ IS_SCRIPT_OR_DATA,
356
+ ATTR_WHITESPACE,
357
+ CUSTOM_ELEMENT
358
+ } = EXPRESSIONS;
359
+ let {
360
+ IS_ALLOWED_URI: IS_ALLOWED_URI$1
361
+ } = EXPRESSIONS;
362
+
363
+ /**
364
+ * We consider the elements and attributes below to be safe. Ideally
365
+ * don't add any new ones but feel free to remove unwanted ones.
366
+ */
367
+
368
+ /* allowed element names */
369
+ let ALLOWED_TAGS = null;
370
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
371
+
372
+ /* Allowed attribute names */
373
+ let ALLOWED_ATTR = null;
374
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
375
+
376
+ /*
377
+ * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
378
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
379
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
380
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
381
+ */
382
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
383
+ tagNameCheck: {
384
+ writable: true,
385
+ configurable: false,
386
+ enumerable: true,
387
+ value: null
388
+ },
389
+ attributeNameCheck: {
390
+ writable: true,
391
+ configurable: false,
392
+ enumerable: true,
393
+ value: null
394
+ },
395
+ allowCustomizedBuiltInElements: {
396
+ writable: true,
397
+ configurable: false,
398
+ enumerable: true,
399
+ value: false
400
+ }
401
+ }));
402
+
403
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
404
+ let FORBID_TAGS = null;
405
+
406
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
407
+ let FORBID_ATTR = null;
408
+
409
+ /* Decide if ARIA attributes are okay */
410
+ let ALLOW_ARIA_ATTR = true;
411
+
412
+ /* Decide if custom data attributes are okay */
413
+ let ALLOW_DATA_ATTR = true;
414
+
415
+ /* Decide if unknown protocols are okay */
416
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
417
+
418
+ /* Decide if self-closing tags in attributes are allowed.
419
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
420
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
421
+
422
+ /* Output should be safe for common template engines.
423
+ * This means, DOMPurify removes data attributes, mustaches and ERB
424
+ */
425
+ let SAFE_FOR_TEMPLATES = false;
426
+
427
+ /* Output should be safe even for XML used within HTML and alike.
428
+ * This means, DOMPurify removes comments when containing risky content.
429
+ */
430
+ let SAFE_FOR_XML = true;
431
+
432
+ /* Decide if document with <html>... should be returned */
433
+ let WHOLE_DOCUMENT = false;
434
+
435
+ /* Track whether config is already set on this instance of DOMPurify. */
436
+ let SET_CONFIG = false;
437
+
438
+ /* Decide if all elements (e.g. style, script) must be children of
439
+ * document.body. By default, browsers might move them to document.head */
440
+ let FORCE_BODY = false;
441
+
442
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
443
+ * string (or a TrustedHTML object if Trusted Types are supported).
444
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
445
+ */
446
+ let RETURN_DOM = false;
447
+
448
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
449
+ * string (or a TrustedHTML object if Trusted Types are supported) */
450
+ let RETURN_DOM_FRAGMENT = false;
451
+
452
+ /* Try to return a Trusted Type object instead of a string, return a string in
453
+ * case Trusted Types are not supported */
454
+ let RETURN_TRUSTED_TYPE = false;
455
+
456
+ /* Output should be free from DOM clobbering attacks?
457
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
458
+ */
459
+ let SANITIZE_DOM = true;
460
+
461
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
462
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
463
+ *
464
+ * HTML/DOM spec rules that enable DOM Clobbering:
465
+ * - Named Access on Window (§7.3.3)
466
+ * - DOM Tree Accessors (§3.1.5)
467
+ * - Form Element Parent-Child Relations (§4.10.3)
468
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
469
+ * - HTMLCollection (§4.2.10.2)
470
+ *
471
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
472
+ * with a constant string, i.e., `user-content-`
473
+ */
474
+ let SANITIZE_NAMED_PROPS = false;
475
+ const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
476
+
477
+ /* Keep element content when removing element? */
478
+ let KEEP_CONTENT = true;
479
+
480
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
481
+ * of importing it into a new Document and returning a sanitized copy */
482
+ let IN_PLACE = false;
483
+
484
+ /* Allow usage of profiles like html, svg and mathMl */
485
+ let USE_PROFILES = {};
486
+
487
+ /* Tags to ignore content of when KEEP_CONTENT is true */
488
+ let FORBID_CONTENTS = null;
489
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
490
+
491
+ /* Tags that are safe for data: URIs */
492
+ let DATA_URI_TAGS = null;
493
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
494
+
495
+ /* Attributes safe for values like "javascript:" */
496
+ let URI_SAFE_ATTRIBUTES = null;
497
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
498
+ const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
499
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
500
+ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
501
+ /* Document namespace */
502
+ let NAMESPACE = HTML_NAMESPACE;
503
+ let IS_EMPTY_INPUT = false;
504
+
505
+ /* Allowed XHTML+XML namespaces */
506
+ let ALLOWED_NAMESPACES = null;
507
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
508
+
509
+ /* Parsing of strict XHTML documents */
510
+ let PARSER_MEDIA_TYPE = null;
511
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
512
+ const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
513
+ let transformCaseFunc = null;
514
+
515
+ /* Keep a reference to config to pass to hooks */
516
+ let CONFIG = null;
517
+
518
+ /* Ideally, do not touch anything below this line */
519
+ /* ______________________________________________ */
520
+
521
+ const formElement = document.createElement('form');
522
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
523
+ return testValue instanceof RegExp || testValue instanceof Function;
524
+ };
525
+
526
+ /**
527
+ * _parseConfig
528
+ *
529
+ * @param {Object} cfg optional config literal
530
+ */
531
+ // eslint-disable-next-line complexity
532
+ const _parseConfig = function _parseConfig() {
533
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
534
+ if (CONFIG && CONFIG === cfg) {
535
+ return;
536
+ }
537
+
538
+ /* Shield configuration object from tampering */
539
+ if (!cfg || typeof cfg !== 'object') {
540
+ cfg = {};
541
+ }
542
+
543
+ /* Shield configuration object from prototype pollution */
544
+ cfg = clone(cfg);
545
+ PARSER_MEDIA_TYPE =
546
+ // eslint-disable-next-line unicorn/prefer-includes
547
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
548
+
549
+ // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
550
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
551
+
552
+ /* Set configuration parameters */
553
+ ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
554
+ ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
555
+ ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
556
+ URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES),
557
+ // eslint-disable-line indent
558
+ cfg.ADD_URI_SAFE_ATTR,
559
+ // eslint-disable-line indent
560
+ transformCaseFunc // eslint-disable-line indent
561
+ ) // eslint-disable-line indent
562
+ : DEFAULT_URI_SAFE_ATTRIBUTES;
563
+ DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS),
564
+ // eslint-disable-line indent
565
+ cfg.ADD_DATA_URI_TAGS,
566
+ // eslint-disable-line indent
567
+ transformCaseFunc // eslint-disable-line indent
568
+ ) // eslint-disable-line indent
569
+ : DEFAULT_DATA_URI_TAGS;
570
+ FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
571
+ FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
572
+ FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
573
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
574
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
575
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
576
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
577
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
578
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
579
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
580
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
581
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
582
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
583
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
584
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
585
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
586
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
587
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
588
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
589
+ IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
590
+ NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
591
+ CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
592
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
593
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
594
+ }
595
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
596
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
597
+ }
598
+ if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
599
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
600
+ }
601
+ if (SAFE_FOR_TEMPLATES) {
602
+ ALLOW_DATA_ATTR = false;
603
+ }
604
+ if (RETURN_DOM_FRAGMENT) {
605
+ RETURN_DOM = true;
606
+ }
607
+
608
+ /* Parse profile info */
609
+ if (USE_PROFILES) {
610
+ ALLOWED_TAGS = addToSet({}, text);
611
+ ALLOWED_ATTR = [];
612
+ if (USE_PROFILES.html === true) {
613
+ addToSet(ALLOWED_TAGS, html$1);
614
+ addToSet(ALLOWED_ATTR, html);
615
+ }
616
+ if (USE_PROFILES.svg === true) {
617
+ addToSet(ALLOWED_TAGS, svg$1);
618
+ addToSet(ALLOWED_ATTR, svg);
619
+ addToSet(ALLOWED_ATTR, xml);
620
+ }
621
+ if (USE_PROFILES.svgFilters === true) {
622
+ addToSet(ALLOWED_TAGS, svgFilters);
623
+ addToSet(ALLOWED_ATTR, svg);
624
+ addToSet(ALLOWED_ATTR, xml);
625
+ }
626
+ if (USE_PROFILES.mathMl === true) {
627
+ addToSet(ALLOWED_TAGS, mathMl$1);
628
+ addToSet(ALLOWED_ATTR, mathMl);
629
+ addToSet(ALLOWED_ATTR, xml);
630
+ }
631
+ }
632
+
633
+ /* Merge configuration parameters */
634
+ if (cfg.ADD_TAGS) {
635
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
636
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
637
+ }
638
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
639
+ }
640
+ if (cfg.ADD_ATTR) {
641
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
642
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
643
+ }
644
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
645
+ }
646
+ if (cfg.ADD_URI_SAFE_ATTR) {
647
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
648
+ }
649
+ if (cfg.FORBID_CONTENTS) {
650
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
651
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
652
+ }
653
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
654
+ }
655
+
656
+ /* Add #text in case KEEP_CONTENT is set to true */
657
+ if (KEEP_CONTENT) {
658
+ ALLOWED_TAGS['#text'] = true;
659
+ }
660
+
661
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
662
+ if (WHOLE_DOCUMENT) {
663
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
664
+ }
665
+
666
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
667
+ if (ALLOWED_TAGS.table) {
668
+ addToSet(ALLOWED_TAGS, ['tbody']);
669
+ delete FORBID_TAGS.tbody;
670
+ }
671
+ if (cfg.TRUSTED_TYPES_POLICY) {
672
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
673
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
674
+ }
675
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
676
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
677
+ }
678
+
679
+ // Overwrite existing TrustedTypes policy.
680
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
681
+
682
+ // Sign local variables required by `sanitize`.
683
+ emptyHTML = trustedTypesPolicy.createHTML('');
684
+ } else {
685
+ // Uninitialized policy, attempt to initialize the internal dompurify policy.
686
+ if (trustedTypesPolicy === undefined) {
687
+ trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
688
+ }
689
+
690
+ // If creating the internal policy succeeded sign internal variables.
691
+ if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
692
+ emptyHTML = trustedTypesPolicy.createHTML('');
693
+ }
694
+ }
695
+
696
+ // Prevent further manipulation of configuration.
697
+ // Not available in IE8, Safari 5, etc.
698
+ if (freeze) {
699
+ freeze(cfg);
700
+ }
701
+ CONFIG = cfg;
702
+ };
703
+ const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
704
+ const HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']);
705
+
706
+ // Certain elements are allowed in both SVG and HTML
707
+ // namespace. We need to specify them explicitly
708
+ // so that they don't get erroneously deleted from
709
+ // HTML namespace.
710
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
711
+
712
+ /* Keep track of all possible SVG and MathML tags
713
+ * so that we can perform the namespace checks
714
+ * correctly. */
715
+ const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
716
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
717
+
718
+ /**
719
+ * @param {Element} element a DOM element whose namespace is being checked
720
+ * @returns {boolean} Return false if the element has a
721
+ * namespace that a spec-compliant parser would never
722
+ * return. Return true otherwise.
723
+ */
724
+ const _checkValidNamespace = function _checkValidNamespace(element) {
725
+ let parent = getParentNode(element);
726
+
727
+ // In JSDOM, if we're inside shadow DOM, then parentNode
728
+ // can be null. We just simulate parent in this case.
729
+ if (!parent || !parent.tagName) {
730
+ parent = {
731
+ namespaceURI: NAMESPACE,
732
+ tagName: 'template'
733
+ };
734
+ }
735
+ const tagName = stringToLowerCase(element.tagName);
736
+ const parentTagName = stringToLowerCase(parent.tagName);
737
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
738
+ return false;
739
+ }
740
+ if (element.namespaceURI === SVG_NAMESPACE) {
741
+ // The only way to switch from HTML namespace to SVG
742
+ // is via <svg>. If it happens via any other tag, then
743
+ // it should be killed.
744
+ if (parent.namespaceURI === HTML_NAMESPACE) {
745
+ return tagName === 'svg';
746
+ }
747
+
748
+ // The only way to switch from MathML to SVG is via`
749
+ // svg if parent is either <annotation-xml> or MathML
750
+ // text integration points.
751
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
752
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
753
+ }
754
+
755
+ // We only allow elements that are defined in SVG
756
+ // spec. All others are disallowed in SVG namespace.
757
+ return Boolean(ALL_SVG_TAGS[tagName]);
758
+ }
759
+ if (element.namespaceURI === MATHML_NAMESPACE) {
760
+ // The only way to switch from HTML namespace to MathML
761
+ // is via <math>. If it happens via any other tag, then
762
+ // it should be killed.
763
+ if (parent.namespaceURI === HTML_NAMESPACE) {
764
+ return tagName === 'math';
765
+ }
766
+
767
+ // The only way to switch from SVG to MathML is via
768
+ // <math> and HTML integration points
769
+ if (parent.namespaceURI === SVG_NAMESPACE) {
770
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
771
+ }
772
+
773
+ // We only allow elements that are defined in MathML
774
+ // spec. All others are disallowed in MathML namespace.
775
+ return Boolean(ALL_MATHML_TAGS[tagName]);
776
+ }
777
+ if (element.namespaceURI === HTML_NAMESPACE) {
778
+ // The only way to switch from SVG to HTML is via
779
+ // HTML integration points, and from MathML to HTML
780
+ // is via MathML text integration points
781
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
782
+ return false;
783
+ }
784
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
785
+ return false;
786
+ }
787
+
788
+ // We disallow tags that are specific for MathML
789
+ // or SVG and should never appear in HTML namespace
790
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
791
+ }
792
+
793
+ // For XHTML and XML documents that support custom namespaces
794
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
795
+ return true;
796
+ }
797
+
798
+ // The code should never reach this place (this means
799
+ // that the element somehow got namespace that is not
800
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
801
+ // Return false just in case.
802
+ return false;
803
+ };
804
+
805
+ /**
806
+ * _forceRemove
807
+ *
808
+ * @param {Node} node a DOM node
809
+ */
810
+ const _forceRemove = function _forceRemove(node) {
811
+ arrayPush(DOMPurify.removed, {
812
+ element: node
813
+ });
814
+ try {
815
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
816
+ node.parentNode.removeChild(node);
817
+ } catch (_) {
818
+ node.remove();
819
+ }
820
+ };
821
+
822
+ /**
823
+ * _removeAttribute
824
+ *
825
+ * @param {String} name an Attribute name
826
+ * @param {Node} node a DOM node
827
+ */
828
+ const _removeAttribute = function _removeAttribute(name, node) {
829
+ try {
830
+ arrayPush(DOMPurify.removed, {
831
+ attribute: node.getAttributeNode(name),
832
+ from: node
833
+ });
834
+ } catch (_) {
835
+ arrayPush(DOMPurify.removed, {
836
+ attribute: null,
837
+ from: node
838
+ });
839
+ }
840
+ node.removeAttribute(name);
841
+
842
+ // We void attribute values for unremovable "is"" attributes
843
+ if (name === 'is' && !ALLOWED_ATTR[name]) {
844
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
845
+ try {
846
+ _forceRemove(node);
847
+ } catch (_) {}
848
+ } else {
849
+ try {
850
+ node.setAttribute(name, '');
851
+ } catch (_) {}
852
+ }
853
+ }
854
+ };
855
+
856
+ /**
857
+ * _initDocument
858
+ *
859
+ * @param {String} dirty a string of dirty markup
860
+ * @return {Document} a DOM, filled with the dirty markup
861
+ */
862
+ const _initDocument = function _initDocument(dirty) {
863
+ /* Create a HTML document */
864
+ let doc = null;
865
+ let leadingWhitespace = null;
866
+ if (FORCE_BODY) {
867
+ dirty = '<remove></remove>' + dirty;
868
+ } else {
869
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
870
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
871
+ leadingWhitespace = matches && matches[0];
872
+ }
873
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
874
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
875
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
876
+ }
877
+ const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
878
+ /*
879
+ * Use the DOMParser API by default, fallback later if needs be
880
+ * DOMParser not work for svg when has multiple root element.
881
+ */
882
+ if (NAMESPACE === HTML_NAMESPACE) {
883
+ try {
884
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
885
+ } catch (_) {}
886
+ }
887
+
888
+ /* Use createHTMLDocument in case DOMParser is not available */
889
+ if (!doc || !doc.documentElement) {
890
+ doc = implementation.createDocument(NAMESPACE, 'template', null);
891
+ try {
892
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
893
+ } catch (_) {
894
+ // Syntax error if dirtyPayload is invalid xml
895
+ }
896
+ }
897
+ const body = doc.body || doc.documentElement;
898
+ if (dirty && leadingWhitespace) {
899
+ body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
900
+ }
901
+
902
+ /* Work on whole document or just its body */
903
+ if (NAMESPACE === HTML_NAMESPACE) {
904
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
905
+ }
906
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
907
+ };
908
+
909
+ /**
910
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
911
+ *
912
+ * @param {Node} root The root element or node to start traversing on.
913
+ * @return {NodeIterator} The created NodeIterator
914
+ */
915
+ const _createNodeIterator = function _createNodeIterator(root) {
916
+ return createNodeIterator.call(root.ownerDocument || root, root,
917
+ // eslint-disable-next-line no-bitwise
918
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
919
+ };
920
+
921
+ /**
922
+ * _isClobbered
923
+ *
924
+ * @param {Node} elm element to check for clobbering attacks
925
+ * @return {Boolean} true if clobbered, false if safe
926
+ */
927
+ const _isClobbered = function _isClobbered(elm) {
928
+ return elm instanceof HTMLFormElement && (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function' || typeof elm.hasChildNodes !== 'function');
929
+ };
930
+
931
+ /**
932
+ * Checks whether the given object is a DOM node.
933
+ *
934
+ * @param {Node} object object to check whether it's a DOM node
935
+ * @return {Boolean} true is object is a DOM node
936
+ */
937
+ const _isNode = function _isNode(object) {
938
+ return typeof Node === 'function' && object instanceof Node;
939
+ };
940
+
941
+ /**
942
+ * _executeHook
943
+ * Execute user configurable hooks
944
+ *
945
+ * @param {String} entryPoint Name of the hook's entry point
946
+ * @param {Node} currentNode node to work on with the hook
947
+ * @param {Object} data additional hook parameters
948
+ */
949
+ const _executeHook = function _executeHook(entryPoint, currentNode, data) {
950
+ if (!hooks[entryPoint]) {
951
+ return;
952
+ }
953
+ arrayForEach(hooks[entryPoint], hook => {
954
+ hook.call(DOMPurify, currentNode, data, CONFIG);
955
+ });
956
+ };
957
+
958
+ /**
959
+ * _sanitizeElements
960
+ *
961
+ * @protect nodeName
962
+ * @protect textContent
963
+ * @protect removeChild
964
+ *
965
+ * @param {Node} currentNode to check for permission to exist
966
+ * @return {Boolean} true if node was killed, false if left alive
967
+ */
968
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
969
+ let content = null;
970
+
971
+ /* Execute a hook if present */
972
+ _executeHook('beforeSanitizeElements', currentNode, null);
973
+
974
+ /* Check if element is clobbered or can clobber */
975
+ if (_isClobbered(currentNode)) {
976
+ _forceRemove(currentNode);
977
+ return true;
978
+ }
979
+
980
+ /* Now let's check the element's type and name */
981
+ const tagName = transformCaseFunc(currentNode.nodeName);
982
+
983
+ /* Execute a hook if present */
984
+ _executeHook('uponSanitizeElement', currentNode, {
985
+ tagName,
986
+ allowedTags: ALLOWED_TAGS
987
+ });
988
+
989
+ /* Detect mXSS attempts abusing namespace confusion */
990
+ if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
991
+ _forceRemove(currentNode);
992
+ return true;
993
+ }
994
+
995
+ /* Remove any ocurrence of processing instructions */
996
+ if (currentNode.nodeType === 7) {
997
+ _forceRemove(currentNode);
998
+ return true;
999
+ }
1000
+
1001
+ /* Remove any kind of possibly harmful comments */
1002
+ if (SAFE_FOR_XML && currentNode.nodeType === 8 && regExpTest(/<[/\w]/g, currentNode.data)) {
1003
+ _forceRemove(currentNode);
1004
+ return true;
1005
+ }
1006
+
1007
+ /* Remove element if anything forbids its presence */
1008
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1009
+ /* Check if we have a custom element to handle */
1010
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
1011
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
1012
+ return false;
1013
+ }
1014
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
1015
+ return false;
1016
+ }
1017
+ }
1018
+
1019
+ /* Keep content except for bad-listed elements */
1020
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1021
+ const parentNode = getParentNode(currentNode) || currentNode.parentNode;
1022
+ const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
1023
+ if (childNodes && parentNode) {
1024
+ const childCount = childNodes.length;
1025
+ for (let i = childCount - 1; i >= 0; --i) {
1026
+ parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
1027
+ }
1028
+ }
1029
+ }
1030
+ _forceRemove(currentNode);
1031
+ return true;
1032
+ }
1033
+
1034
+ /* Check whether element has a valid namespace */
1035
+ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
1036
+ _forceRemove(currentNode);
1037
+ return true;
1038
+ }
1039
+
1040
+ /* Make sure that older browsers don't get fallback-tag mXSS */
1041
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
1042
+ _forceRemove(currentNode);
1043
+ return true;
1044
+ }
1045
+
1046
+ /* Sanitize element content to be template-safe */
1047
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
1048
+ /* Get the element's text content */
1049
+ content = currentNode.textContent;
1050
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1051
+ content = stringReplace(content, expr, ' ');
1052
+ });
1053
+ if (currentNode.textContent !== content) {
1054
+ arrayPush(DOMPurify.removed, {
1055
+ element: currentNode.cloneNode()
1056
+ });
1057
+ currentNode.textContent = content;
1058
+ }
1059
+ }
1060
+
1061
+ /* Execute a hook if present */
1062
+ _executeHook('afterSanitizeElements', currentNode, null);
1063
+ return false;
1064
+ };
1065
+
1066
+ /**
1067
+ * _isValidAttribute
1068
+ *
1069
+ * @param {string} lcTag Lowercase tag name of containing element.
1070
+ * @param {string} lcName Lowercase attribute name.
1071
+ * @param {string} value Attribute value.
1072
+ * @return {Boolean} Returns true if `value` is valid, otherwise false.
1073
+ */
1074
+ // eslint-disable-next-line complexity
1075
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1076
+ /* Make sure attribute cannot clobber */
1077
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1078
+ return false;
1079
+ }
1080
+
1081
+ /* Allow valid data-* attributes: At least one character after "-"
1082
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1083
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1084
+ We don't need to check the value; it's always URI safe. */
1085
+ if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1086
+ if (
1087
+ // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1088
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1089
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1090
+ _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) ||
1091
+ // Alternative, second condition checks if it's an `is`-attribute, AND
1092
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1093
+ lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
1094
+ return false;
1095
+ }
1096
+ /* Check value is safe. First, is attr inert? If so, is safe */
1097
+ } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
1098
+ return false;
1099
+ } else ;
1100
+ return true;
1101
+ };
1102
+
1103
+ /**
1104
+ * _isBasicCustomElement
1105
+ * checks if at least one dash is included in tagName, and it's not the first char
1106
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1107
+ *
1108
+ * @param {string} tagName name of the tag of the node to sanitize
1109
+ * @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1110
+ */
1111
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1112
+ return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
1113
+ };
1114
+
1115
+ /**
1116
+ * _sanitizeAttributes
1117
+ *
1118
+ * @protect attributes
1119
+ * @protect nodeName
1120
+ * @protect removeAttribute
1121
+ * @protect setAttribute
1122
+ *
1123
+ * @param {Node} currentNode to sanitize
1124
+ */
1125
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1126
+ /* Execute a hook if present */
1127
+ _executeHook('beforeSanitizeAttributes', currentNode, null);
1128
+ const {
1129
+ attributes
1130
+ } = currentNode;
1131
+
1132
+ /* Check if we have attributes; if not we might have a text node */
1133
+ if (!attributes) {
1134
+ return;
1135
+ }
1136
+ const hookEvent = {
1137
+ attrName: '',
1138
+ attrValue: '',
1139
+ keepAttr: true,
1140
+ allowedAttributes: ALLOWED_ATTR
1141
+ };
1142
+ let l = attributes.length;
1143
+
1144
+ /* Go backwards over all attributes; safely remove bad ones */
1145
+ while (l--) {
1146
+ const attr = attributes[l];
1147
+ const {
1148
+ name,
1149
+ namespaceURI,
1150
+ value: attrValue
1151
+ } = attr;
1152
+ const lcName = transformCaseFunc(name);
1153
+ let value = name === 'value' ? attrValue : stringTrim(attrValue);
1154
+
1155
+ /* Execute a hook if present */
1156
+ hookEvent.attrName = lcName;
1157
+ hookEvent.attrValue = value;
1158
+ hookEvent.keepAttr = true;
1159
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1160
+ _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
1161
+ value = hookEvent.attrValue;
1162
+ /* Did the hooks approve of the attribute? */
1163
+ if (hookEvent.forceKeepAttr) {
1164
+ continue;
1165
+ }
1166
+
1167
+ /* Remove attribute */
1168
+ _removeAttribute(name, currentNode);
1169
+
1170
+ /* Did the hooks approve of the attribute? */
1171
+ if (!hookEvent.keepAttr) {
1172
+ continue;
1173
+ }
1174
+
1175
+ /* Work around a security issue in jQuery 3.0 */
1176
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1177
+ _removeAttribute(name, currentNode);
1178
+ continue;
1179
+ }
1180
+
1181
+ /* Sanitize attribute content to be template-safe */
1182
+ if (SAFE_FOR_TEMPLATES) {
1183
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1184
+ value = stringReplace(value, expr, ' ');
1185
+ });
1186
+ }
1187
+
1188
+ /* Is `value` valid for this attribute? */
1189
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1190
+ if (!_isValidAttribute(lcTag, lcName, value)) {
1191
+ continue;
1192
+ }
1193
+
1194
+ /* Full DOM Clobbering protection via namespace isolation,
1195
+ * Prefix id and name attributes with `user-content-`
1196
+ */
1197
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1198
+ // Remove the attribute with this value
1199
+ _removeAttribute(name, currentNode);
1200
+
1201
+ // Prefix the value and later re-create the attribute with the sanitized value
1202
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
1203
+ }
1204
+
1205
+ /* Handle attributes that require Trusted Types */
1206
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1207
+ if (namespaceURI) ; else {
1208
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1209
+ case 'TrustedHTML':
1210
+ {
1211
+ value = trustedTypesPolicy.createHTML(value);
1212
+ break;
1213
+ }
1214
+ case 'TrustedScriptURL':
1215
+ {
1216
+ value = trustedTypesPolicy.createScriptURL(value);
1217
+ break;
1218
+ }
1219
+ }
1220
+ }
1221
+ }
1222
+
1223
+ /* Handle invalid data-* attribute set by try-catching it */
1224
+ try {
1225
+ if (namespaceURI) {
1226
+ currentNode.setAttributeNS(namespaceURI, name, value);
1227
+ } else {
1228
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1229
+ currentNode.setAttribute(name, value);
1230
+ }
1231
+ arrayPop(DOMPurify.removed);
1232
+ } catch (_) {}
1233
+ }
1234
+
1235
+ /* Execute a hook if present */
1236
+ _executeHook('afterSanitizeAttributes', currentNode, null);
1237
+ };
1238
+
1239
+ /**
1240
+ * _sanitizeShadowDOM
1241
+ *
1242
+ * @param {DocumentFragment} fragment to iterate over recursively
1243
+ */
1244
+ const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1245
+ let shadowNode = null;
1246
+ const shadowIterator = _createNodeIterator(fragment);
1247
+
1248
+ /* Execute a hook if present */
1249
+ _executeHook('beforeSanitizeShadowDOM', fragment, null);
1250
+ while (shadowNode = shadowIterator.nextNode()) {
1251
+ /* Execute a hook if present */
1252
+ _executeHook('uponSanitizeShadowNode', shadowNode, null);
1253
+
1254
+ /* Sanitize tags and elements */
1255
+ if (_sanitizeElements(shadowNode)) {
1256
+ continue;
1257
+ }
1258
+
1259
+ /* Deep shadow DOM detected */
1260
+ if (shadowNode.content instanceof DocumentFragment) {
1261
+ _sanitizeShadowDOM(shadowNode.content);
1262
+ }
1263
+
1264
+ /* Check attributes, sanitize if necessary */
1265
+ _sanitizeAttributes(shadowNode);
1266
+ }
1267
+
1268
+ /* Execute a hook if present */
1269
+ _executeHook('afterSanitizeShadowDOM', fragment, null);
1270
+ };
1271
+
1272
+ /**
1273
+ * Sanitize
1274
+ * Public method providing core sanitation functionality
1275
+ *
1276
+ * @param {String|Node} dirty string or DOM node
1277
+ * @param {Object} cfg object
1278
+ */
1279
+ // eslint-disable-next-line complexity
1280
+ DOMPurify.sanitize = function (dirty) {
1281
+ let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1282
+ let body = null;
1283
+ let importedNode = null;
1284
+ let currentNode = null;
1285
+ let returnNode = null;
1286
+ /* Make sure we have a string to sanitize.
1287
+ DO NOT return early, as this will return the wrong type if
1288
+ the user has requested a DOM object rather than a string */
1289
+ IS_EMPTY_INPUT = !dirty;
1290
+ if (IS_EMPTY_INPUT) {
1291
+ dirty = '<!-->';
1292
+ }
1293
+
1294
+ /* Stringify, in case dirty is an object */
1295
+ if (typeof dirty !== 'string' && !_isNode(dirty)) {
1296
+ if (typeof dirty.toString === 'function') {
1297
+ dirty = dirty.toString();
1298
+ if (typeof dirty !== 'string') {
1299
+ throw typeErrorCreate('dirty is not a string, aborting');
1300
+ }
1301
+ } else {
1302
+ throw typeErrorCreate('toString is not a function');
1303
+ }
1304
+ }
1305
+
1306
+ /* Return dirty HTML if DOMPurify cannot run */
1307
+ if (!DOMPurify.isSupported) {
1308
+ return dirty;
1309
+ }
1310
+
1311
+ /* Assign config vars */
1312
+ if (!SET_CONFIG) {
1313
+ _parseConfig(cfg);
1314
+ }
1315
+
1316
+ /* Clean up removed elements */
1317
+ DOMPurify.removed = [];
1318
+
1319
+ /* Check if dirty is correctly typed for IN_PLACE */
1320
+ if (typeof dirty === 'string') {
1321
+ IN_PLACE = false;
1322
+ }
1323
+ if (IN_PLACE) {
1324
+ /* Do some early pre-sanitization to avoid unsafe root nodes */
1325
+ if (dirty.nodeName) {
1326
+ const tagName = transformCaseFunc(dirty.nodeName);
1327
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1328
+ throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1329
+ }
1330
+ }
1331
+ } else if (dirty instanceof Node) {
1332
+ /* If dirty is a DOM element, append to an empty document to avoid
1333
+ elements being stripped by the parser */
1334
+ body = _initDocument('<!---->');
1335
+ importedNode = body.ownerDocument.importNode(dirty, true);
1336
+ if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
1337
+ /* Node is already a body, use as is */
1338
+ body = importedNode;
1339
+ } else if (importedNode.nodeName === 'HTML') {
1340
+ body = importedNode;
1341
+ } else {
1342
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1343
+ body.appendChild(importedNode);
1344
+ }
1345
+ } else {
1346
+ /* Exit directly if we have nothing to do */
1347
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
1348
+ // eslint-disable-next-line unicorn/prefer-includes
1349
+ dirty.indexOf('<') === -1) {
1350
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1351
+ }
1352
+
1353
+ /* Initialize the document to work on */
1354
+ body = _initDocument(dirty);
1355
+
1356
+ /* Check we have a DOM node from the data */
1357
+ if (!body) {
1358
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1359
+ }
1360
+ }
1361
+
1362
+ /* Remove first element node (ours) if FORCE_BODY is set */
1363
+ if (body && FORCE_BODY) {
1364
+ _forceRemove(body.firstChild);
1365
+ }
1366
+
1367
+ /* Get node iterator */
1368
+ const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
1369
+
1370
+ /* Now start iterating over the created document */
1371
+ while (currentNode = nodeIterator.nextNode()) {
1372
+ /* Sanitize tags and elements */
1373
+ if (_sanitizeElements(currentNode)) {
1374
+ continue;
1375
+ }
1376
+
1377
+ /* Shadow DOM detected, sanitize it */
1378
+ if (currentNode.content instanceof DocumentFragment) {
1379
+ _sanitizeShadowDOM(currentNode.content);
1380
+ }
1381
+
1382
+ /* Check attributes, sanitize if necessary */
1383
+ _sanitizeAttributes(currentNode);
1384
+ }
1385
+
1386
+ /* If we sanitized `dirty` in-place, return it. */
1387
+ if (IN_PLACE) {
1388
+ return dirty;
1389
+ }
1390
+
1391
+ /* Return sanitized string or DOM */
1392
+ if (RETURN_DOM) {
1393
+ if (RETURN_DOM_FRAGMENT) {
1394
+ returnNode = createDocumentFragment.call(body.ownerDocument);
1395
+ while (body.firstChild) {
1396
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1397
+ returnNode.appendChild(body.firstChild);
1398
+ }
1399
+ } else {
1400
+ returnNode = body;
1401
+ }
1402
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
1403
+ /*
1404
+ AdoptNode() is not used because internal state is not reset
1405
+ (e.g. the past names map of a HTMLFormElement), this is safe
1406
+ in theory but we would rather not risk another attack vector.
1407
+ The state that is cloned by importNode() is explicitly defined
1408
+ by the specs.
1409
+ */
1410
+ returnNode = importNode.call(originalDocument, returnNode, true);
1411
+ }
1412
+ return returnNode;
1413
+ }
1414
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1415
+
1416
+ /* Serialize doctype if allowed */
1417
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1418
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1419
+ }
1420
+
1421
+ /* Sanitize final string template-safe */
1422
+ if (SAFE_FOR_TEMPLATES) {
1423
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1424
+ serializedHTML = stringReplace(serializedHTML, expr, ' ');
1425
+ });
1426
+ }
1427
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1428
+ };
1429
+
1430
+ /**
1431
+ * Public method to set the configuration once
1432
+ * setConfig
1433
+ *
1434
+ * @param {Object} cfg configuration object
1435
+ */
1436
+ DOMPurify.setConfig = function () {
1437
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1438
+ _parseConfig(cfg);
1439
+ SET_CONFIG = true;
1440
+ };
1441
+
1442
+ /**
1443
+ * Public method to remove the configuration
1444
+ * clearConfig
1445
+ *
1446
+ */
1447
+ DOMPurify.clearConfig = function () {
1448
+ CONFIG = null;
1449
+ SET_CONFIG = false;
1450
+ };
1451
+
1452
+ /**
1453
+ * Public method to check if an attribute value is valid.
1454
+ * Uses last set config, if any. Otherwise, uses config defaults.
1455
+ * isValidAttribute
1456
+ *
1457
+ * @param {String} tag Tag name of containing element.
1458
+ * @param {String} attr Attribute name.
1459
+ * @param {String} value Attribute value.
1460
+ * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
1461
+ */
1462
+ DOMPurify.isValidAttribute = function (tag, attr, value) {
1463
+ /* Initialize shared config vars if necessary. */
1464
+ if (!CONFIG) {
1465
+ _parseConfig({});
1466
+ }
1467
+ const lcTag = transformCaseFunc(tag);
1468
+ const lcName = transformCaseFunc(attr);
1469
+ return _isValidAttribute(lcTag, lcName, value);
1470
+ };
1471
+
1472
+ /**
1473
+ * AddHook
1474
+ * Public method to add DOMPurify hooks
1475
+ *
1476
+ * @param {String} entryPoint entry point for the hook to add
1477
+ * @param {Function} hookFunction function to execute
1478
+ */
1479
+ DOMPurify.addHook = function (entryPoint, hookFunction) {
1480
+ if (typeof hookFunction !== 'function') {
1481
+ return;
1482
+ }
1483
+ hooks[entryPoint] = hooks[entryPoint] || [];
1484
+ arrayPush(hooks[entryPoint], hookFunction);
1485
+ };
1486
+
1487
+ /**
1488
+ * RemoveHook
1489
+ * Public method to remove a DOMPurify hook at a given entryPoint
1490
+ * (pops it from the stack of hooks if more are present)
1491
+ *
1492
+ * @param {String} entryPoint entry point for the hook to remove
1493
+ * @return {Function} removed(popped) hook
1494
+ */
1495
+ DOMPurify.removeHook = function (entryPoint) {
1496
+ if (hooks[entryPoint]) {
1497
+ return arrayPop(hooks[entryPoint]);
1498
+ }
1499
+ };
1500
+
1501
+ /**
1502
+ * RemoveHooks
1503
+ * Public method to remove all DOMPurify hooks at a given entryPoint
1504
+ *
1505
+ * @param {String} entryPoint entry point for the hooks to remove
1506
+ */
1507
+ DOMPurify.removeHooks = function (entryPoint) {
1508
+ if (hooks[entryPoint]) {
1509
+ hooks[entryPoint] = [];
1510
+ }
1511
+ };
1512
+
1513
+ /**
1514
+ * RemoveAllHooks
1515
+ * Public method to remove all DOMPurify hooks
1516
+ */
1517
+ DOMPurify.removeAllHooks = function () {
1518
+ hooks = {};
1519
+ };
1520
+ return DOMPurify;
1521
+ }
1522
+ var purify = createDOMPurify();
1523
+
1524
+ export { purify as default };
1525
+ //# sourceMappingURL=purify.es.mjs.map