sol-components 2.1.0

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