@feedlog-ai/webcomponents 0.0.35 → 0.0.37

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 (73) hide show
  1. package/README.md +9 -17
  2. package/dist/cjs/feedlog-badge.cjs.entry.js +3 -3
  3. package/dist/cjs/feedlog-button_3.cjs.entry.js +16 -1385
  4. package/dist/cjs/feedlog-card.cjs.entry.js +3 -3
  5. package/dist/cjs/feedlog-issues-client.cjs.entry.js +102 -74
  6. package/dist/cjs/feedlog-issues.cjs.entry.js +4 -11
  7. package/dist/cjs/feedlog-toolkit.cjs.js +2 -2
  8. package/dist/cjs/{index-CXKBwRlh.js → index-prPyjPBk.js} +1 -1
  9. package/dist/cjs/loader.cjs.js +2 -2
  10. package/dist/cjs/purify.es-ppGw41aq.js +1384 -0
  11. package/dist/collection/components/feedlog-badge/feedlog-badge.css +35 -45
  12. package/dist/collection/components/feedlog-badge/feedlog-badge.js +1 -1
  13. package/dist/collection/components/feedlog-button/feedlog-button.css +16 -66
  14. package/dist/collection/components/feedlog-button/feedlog-button.js +1 -1
  15. package/dist/collection/components/feedlog-card/feedlog-card.css +22 -24
  16. package/dist/collection/components/feedlog-card/feedlog-card.js +1 -1
  17. package/dist/collection/components/feedlog-card/feedlog-card.stories.js +1 -1
  18. package/dist/collection/components/feedlog-issue/feedlog-issue.css +99 -187
  19. package/dist/collection/components/feedlog-issue/feedlog-issue.js +1 -1
  20. package/dist/collection/components/feedlog-issue/feedlog-issue.stories.js +19 -19
  21. package/dist/collection/components/feedlog-issues/feedlog-issues.css +34 -63
  22. package/dist/collection/components/feedlog-issues/feedlog-issues.js +2 -14
  23. package/dist/collection/components/feedlog-issues/feedlog-issues.stories.js +72 -52
  24. package/dist/collection/components/feedlog-issues-client/feedlog-issues-client.js +22 -28
  25. package/dist/collection/components/feedlog-issues-list/feedlog-issues-list.js +3 -3
  26. package/dist/collection/utils/markdown.js +6 -1
  27. package/dist/components/feedlog-badge.js +1 -1
  28. package/dist/components/feedlog-button.js +1 -1
  29. package/dist/components/feedlog-card.js +1 -1
  30. package/dist/components/feedlog-issue.js +1 -1
  31. package/dist/components/feedlog-issues-client.js +1 -1
  32. package/dist/components/feedlog-issues-list.js +1 -1
  33. package/dist/components/feedlog-issues.js +1 -1
  34. package/dist/components/index.js +1 -1
  35. package/dist/components/p-BoxVrJId.js +1 -0
  36. package/dist/components/{p-BRjVS8bz.js → p-CvIMO_S7.js} +2 -2
  37. package/dist/components/p-DFD585IK.js +1 -0
  38. package/dist/components/p-I6NOP29P.js +1 -0
  39. package/dist/components/p-fDVosM5p.js +1 -0
  40. package/dist/esm/feedlog-badge.entry.js +3 -3
  41. package/dist/esm/feedlog-button_3.entry.js +15 -1384
  42. package/dist/esm/feedlog-card.entry.js +3 -3
  43. package/dist/esm/feedlog-issues-client.entry.js +102 -74
  44. package/dist/esm/feedlog-issues.entry.js +4 -11
  45. package/dist/esm/feedlog-toolkit.js +3 -3
  46. package/dist/esm/{index-CgNWSmzU.js → index-Cu1eYdKa.js} +1 -1
  47. package/dist/esm/loader.js +3 -3
  48. package/dist/esm/purify.es-Bow7VsVH.js +1381 -0
  49. package/dist/feedlog-toolkit/feedlog-toolkit.css +1 -1
  50. package/dist/feedlog-toolkit/feedlog-toolkit.esm.js +1 -1
  51. package/dist/feedlog-toolkit/p-001d7353.entry.js +1 -0
  52. package/dist/feedlog-toolkit/p-556062d0.entry.js +1 -0
  53. package/dist/feedlog-toolkit/p-62554649.entry.js +1 -0
  54. package/dist/feedlog-toolkit/p-Bow7VsVH.js +2 -0
  55. package/dist/feedlog-toolkit/p-Cu1eYdKa.js +2 -0
  56. package/dist/feedlog-toolkit/p-b558fc9f.entry.js +1 -0
  57. package/dist/feedlog-toolkit/p-ca90ade9.entry.js +1 -0
  58. package/dist/types/components/feedlog-issues/feedlog-issues.d.ts +0 -5
  59. package/dist/types/components/feedlog-issues-client/feedlog-issues-client.d.ts +1 -0
  60. package/dist/types/index.d.ts +1 -1
  61. package/hydrate/index.js +130 -101
  62. package/hydrate/index.mjs +130 -101
  63. package/package.json +4 -7
  64. package/dist/components/p-BBbiSGNf.js +0 -1
  65. package/dist/components/p-CuFKEckF.js +0 -1
  66. package/dist/components/p-DMdb-G26.js +0 -1
  67. package/dist/components/p-DzATWlAC.js +0 -1
  68. package/dist/feedlog-toolkit/p-32663f65.entry.js +0 -1
  69. package/dist/feedlog-toolkit/p-891c349f.entry.js +0 -3
  70. package/dist/feedlog-toolkit/p-CgNWSmzU.js +0 -2
  71. package/dist/feedlog-toolkit/p-b51c95a6.entry.js +0 -1
  72. package/dist/feedlog-toolkit/p-da0268a8.entry.js +0 -1
  73. package/dist/feedlog-toolkit/p-f22117ae.entry.js +0 -1
@@ -0,0 +1,1384 @@
1
+ 'use strict';
2
+
3
+ /*! @license DOMPurify 3.3.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.3.1/LICENSE */
4
+
5
+ const {
6
+ entries,
7
+ setPrototypeOf,
8
+ isFrozen,
9
+ getPrototypeOf,
10
+ getOwnPropertyDescriptor
11
+ } = Object;
12
+ let {
13
+ freeze,
14
+ seal,
15
+ create
16
+ } = Object; // eslint-disable-line import/no-mutable-exports
17
+ let {
18
+ apply,
19
+ construct
20
+ } = typeof Reflect !== 'undefined' && Reflect;
21
+ if (!freeze) {
22
+ freeze = function freeze(x) {
23
+ return x;
24
+ };
25
+ }
26
+ if (!seal) {
27
+ seal = function seal(x) {
28
+ return x;
29
+ };
30
+ }
31
+ if (!apply) {
32
+ apply = function apply(func, thisArg) {
33
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
34
+ args[_key - 2] = arguments[_key];
35
+ }
36
+ return func.apply(thisArg, args);
37
+ };
38
+ }
39
+ if (!construct) {
40
+ construct = function construct(Func) {
41
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
42
+ args[_key2 - 1] = arguments[_key2];
43
+ }
44
+ return new Func(...args);
45
+ };
46
+ }
47
+ const arrayForEach = unapply(Array.prototype.forEach);
48
+ const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
49
+ const arrayPop = unapply(Array.prototype.pop);
50
+ const arrayPush = unapply(Array.prototype.push);
51
+ const arraySplice = unapply(Array.prototype.splice);
52
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
53
+ const stringToString = unapply(String.prototype.toString);
54
+ const stringMatch = unapply(String.prototype.match);
55
+ const stringReplace = unapply(String.prototype.replace);
56
+ const stringIndexOf = unapply(String.prototype.indexOf);
57
+ const stringTrim = unapply(String.prototype.trim);
58
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
59
+ const regExpTest = unapply(RegExp.prototype.test);
60
+ const typeErrorCreate = unconstruct(TypeError);
61
+ /**
62
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
63
+ *
64
+ * @param func - The function to be wrapped and called.
65
+ * @returns A new function that calls the given function with a specified thisArg and arguments.
66
+ */
67
+ function unapply(func) {
68
+ return function (thisArg) {
69
+ if (thisArg instanceof RegExp) {
70
+ thisArg.lastIndex = 0;
71
+ }
72
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
73
+ args[_key3 - 1] = arguments[_key3];
74
+ }
75
+ return apply(func, thisArg, args);
76
+ };
77
+ }
78
+ /**
79
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
80
+ *
81
+ * @param func - The constructor function to be wrapped and called.
82
+ * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
83
+ */
84
+ function unconstruct(Func) {
85
+ return function () {
86
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
87
+ args[_key4] = arguments[_key4];
88
+ }
89
+ return construct(Func, args);
90
+ };
91
+ }
92
+ /**
93
+ * Add properties to a lookup table
94
+ *
95
+ * @param set - The set to which elements will be added.
96
+ * @param array - The array containing elements to be added to the set.
97
+ * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
98
+ * @returns The modified set with added elements.
99
+ */
100
+ function addToSet(set, array) {
101
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
102
+ if (setPrototypeOf) {
103
+ // Make 'in' and truthy checks like Boolean(set.constructor)
104
+ // independent of any properties defined on Object.prototype.
105
+ // Prevent prototype setters from intercepting set as a this value.
106
+ setPrototypeOf(set, null);
107
+ }
108
+ let l = array.length;
109
+ while (l--) {
110
+ let element = array[l];
111
+ if (typeof element === 'string') {
112
+ const lcElement = transformCaseFunc(element);
113
+ if (lcElement !== element) {
114
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
115
+ if (!isFrozen(array)) {
116
+ array[l] = lcElement;
117
+ }
118
+ element = lcElement;
119
+ }
120
+ }
121
+ set[element] = true;
122
+ }
123
+ return set;
124
+ }
125
+ /**
126
+ * Clean up an array to harden against CSPP
127
+ *
128
+ * @param array - The array to be cleaned.
129
+ * @returns The cleaned version of the array
130
+ */
131
+ function cleanArray(array) {
132
+ for (let index = 0; index < array.length; index++) {
133
+ const isPropertyExist = objectHasOwnProperty(array, index);
134
+ if (!isPropertyExist) {
135
+ array[index] = null;
136
+ }
137
+ }
138
+ return array;
139
+ }
140
+ /**
141
+ * Shallow clone an object
142
+ *
143
+ * @param object - The object to be cloned.
144
+ * @returns A new object that copies the original.
145
+ */
146
+ function clone(object) {
147
+ const newObject = create(null);
148
+ for (const [property, value] of entries(object)) {
149
+ const isPropertyExist = objectHasOwnProperty(object, property);
150
+ if (isPropertyExist) {
151
+ if (Array.isArray(value)) {
152
+ newObject[property] = cleanArray(value);
153
+ } else if (value && typeof value === 'object' && value.constructor === Object) {
154
+ newObject[property] = clone(value);
155
+ } else {
156
+ newObject[property] = value;
157
+ }
158
+ }
159
+ }
160
+ return newObject;
161
+ }
162
+ /**
163
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
164
+ *
165
+ * @param object - The object to look up the getter function in its prototype chain.
166
+ * @param prop - The property name for which to find the getter function.
167
+ * @returns The getter function found in the prototype chain or a fallback function.
168
+ */
169
+ function lookupGetter(object, prop) {
170
+ while (object !== null) {
171
+ const desc = getOwnPropertyDescriptor(object, prop);
172
+ if (desc) {
173
+ if (desc.get) {
174
+ return unapply(desc.get);
175
+ }
176
+ if (typeof desc.value === 'function') {
177
+ return unapply(desc.value);
178
+ }
179
+ }
180
+ object = getPrototypeOf(object);
181
+ }
182
+ function fallbackValue() {
183
+ return null;
184
+ }
185
+ return fallbackValue;
186
+ }
187
+
188
+ 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']);
189
+ 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']);
190
+ 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']);
191
+ // List of SVG elements that are disallowed by default.
192
+ // We still need to know them so that we can do namespace
193
+ // checks properly in case one wants to add them to
194
+ // allow-list.
195
+ 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']);
196
+ 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']);
197
+ // Similarly to SVG, we want to know all MathML elements,
198
+ // even those that we disallow by default.
199
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
200
+ const text = freeze(['#text']);
201
+
202
+ 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', 'slot']);
203
+ 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']);
204
+ 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']);
205
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
206
+
207
+ // eslint-disable-next-line unicorn/better-regex
208
+ const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
209
+ const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
210
+ const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
211
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
212
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
213
+ 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
214
+ );
215
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
216
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
217
+ );
218
+ const DOCTYPE_NAME = seal(/^html$/i);
219
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
220
+
221
+ var EXPRESSIONS = /*#__PURE__*/Object.freeze({
222
+ __proto__: null,
223
+ ARIA_ATTR: ARIA_ATTR,
224
+ ATTR_WHITESPACE: ATTR_WHITESPACE,
225
+ CUSTOM_ELEMENT: CUSTOM_ELEMENT,
226
+ DATA_ATTR: DATA_ATTR,
227
+ DOCTYPE_NAME: DOCTYPE_NAME,
228
+ ERB_EXPR: ERB_EXPR,
229
+ IS_ALLOWED_URI: IS_ALLOWED_URI,
230
+ IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
231
+ MUSTACHE_EXPR: MUSTACHE_EXPR,
232
+ TMPLIT_EXPR: TMPLIT_EXPR
233
+ });
234
+
235
+ /* eslint-disable @typescript-eslint/indent */
236
+ // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
237
+ const NODE_TYPE = {
238
+ element: 1,
239
+ text: 3,
240
+ // Deprecated
241
+ progressingInstruction: 7,
242
+ comment: 8,
243
+ document: 9};
244
+ const getGlobal = function getGlobal() {
245
+ return typeof window === 'undefined' ? null : window;
246
+ };
247
+ /**
248
+ * Creates a no-op policy for internal use only.
249
+ * Don't export this function outside this module!
250
+ * @param trustedTypes The policy factory.
251
+ * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
252
+ * @return The policy created (or null, if Trusted Types
253
+ * are not supported or creating the policy failed).
254
+ */
255
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
256
+ if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
257
+ return null;
258
+ }
259
+ // Allow the callers to control the unique policy name
260
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
261
+ // Policy creation with duplicate names throws in Trusted Types.
262
+ let suffix = null;
263
+ const ATTR_NAME = 'data-tt-policy-suffix';
264
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
265
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
266
+ }
267
+ const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
268
+ try {
269
+ return trustedTypes.createPolicy(policyName, {
270
+ createHTML(html) {
271
+ return html;
272
+ },
273
+ createScriptURL(scriptUrl) {
274
+ return scriptUrl;
275
+ }
276
+ });
277
+ } catch (_) {
278
+ // Policy creation failed (most likely another DOMPurify script has
279
+ // already run). Skip creating the policy, as this will only cause errors
280
+ // if TT are enforced.
281
+ console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
282
+ return null;
283
+ }
284
+ };
285
+ const _createHooksMap = function _createHooksMap() {
286
+ return {
287
+ afterSanitizeAttributes: [],
288
+ afterSanitizeElements: [],
289
+ afterSanitizeShadowDOM: [],
290
+ beforeSanitizeAttributes: [],
291
+ beforeSanitizeElements: [],
292
+ beforeSanitizeShadowDOM: [],
293
+ uponSanitizeAttribute: [],
294
+ uponSanitizeElement: [],
295
+ uponSanitizeShadowNode: []
296
+ };
297
+ };
298
+ function createDOMPurify() {
299
+ let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
300
+ const DOMPurify = root => createDOMPurify(root);
301
+ DOMPurify.version = '3.3.1';
302
+ DOMPurify.removed = [];
303
+ if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
304
+ // Not running in a browser, provide a factory function
305
+ // so that you can pass your own Window
306
+ DOMPurify.isSupported = false;
307
+ return DOMPurify;
308
+ }
309
+ let {
310
+ document
311
+ } = window;
312
+ const originalDocument = document;
313
+ const currentScript = originalDocument.currentScript;
314
+ const {
315
+ DocumentFragment,
316
+ HTMLTemplateElement,
317
+ Node,
318
+ Element,
319
+ NodeFilter,
320
+ NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
321
+ HTMLFormElement,
322
+ DOMParser,
323
+ trustedTypes
324
+ } = window;
325
+ const ElementPrototype = Element.prototype;
326
+ const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
327
+ const remove = lookupGetter(ElementPrototype, 'remove');
328
+ const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
329
+ const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
330
+ const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
331
+ // As per issue #47, the web-components registry is inherited by a
332
+ // new document created via createHTMLDocument. As per the spec
333
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
334
+ // a new empty registry is used when creating a template contents owner
335
+ // document, so we use that as our parent document to ensure nothing
336
+ // is inherited.
337
+ if (typeof HTMLTemplateElement === 'function') {
338
+ const template = document.createElement('template');
339
+ if (template.content && template.content.ownerDocument) {
340
+ document = template.content.ownerDocument;
341
+ }
342
+ }
343
+ let trustedTypesPolicy;
344
+ let emptyHTML = '';
345
+ const {
346
+ implementation,
347
+ createNodeIterator,
348
+ createDocumentFragment,
349
+ getElementsByTagName
350
+ } = document;
351
+ const {
352
+ importNode
353
+ } = originalDocument;
354
+ let hooks = _createHooksMap();
355
+ /**
356
+ * Expose whether this browser supports running the full DOMPurify.
357
+ */
358
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
359
+ const {
360
+ MUSTACHE_EXPR,
361
+ ERB_EXPR,
362
+ TMPLIT_EXPR,
363
+ DATA_ATTR,
364
+ ARIA_ATTR,
365
+ IS_SCRIPT_OR_DATA,
366
+ ATTR_WHITESPACE,
367
+ CUSTOM_ELEMENT
368
+ } = EXPRESSIONS;
369
+ let {
370
+ IS_ALLOWED_URI: IS_ALLOWED_URI$1
371
+ } = EXPRESSIONS;
372
+ /**
373
+ * We consider the elements and attributes below to be safe. Ideally
374
+ * don't add any new ones but feel free to remove unwanted ones.
375
+ */
376
+ /* allowed element names */
377
+ let ALLOWED_TAGS = null;
378
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
379
+ /* Allowed attribute names */
380
+ let ALLOWED_ATTR = null;
381
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
382
+ /*
383
+ * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
384
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
385
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
386
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
387
+ */
388
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
389
+ tagNameCheck: {
390
+ writable: true,
391
+ configurable: false,
392
+ enumerable: true,
393
+ value: null
394
+ },
395
+ attributeNameCheck: {
396
+ writable: true,
397
+ configurable: false,
398
+ enumerable: true,
399
+ value: null
400
+ },
401
+ allowCustomizedBuiltInElements: {
402
+ writable: true,
403
+ configurable: false,
404
+ enumerable: true,
405
+ value: false
406
+ }
407
+ }));
408
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
409
+ let FORBID_TAGS = null;
410
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
411
+ let FORBID_ATTR = null;
412
+ /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */
413
+ const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
414
+ tagCheck: {
415
+ writable: true,
416
+ configurable: false,
417
+ enumerable: true,
418
+ value: null
419
+ },
420
+ attributeCheck: {
421
+ writable: true,
422
+ configurable: false,
423
+ enumerable: true,
424
+ value: null
425
+ }
426
+ }));
427
+ /* Decide if ARIA attributes are okay */
428
+ let ALLOW_ARIA_ATTR = true;
429
+ /* Decide if custom data attributes are okay */
430
+ let ALLOW_DATA_ATTR = true;
431
+ /* Decide if unknown protocols are okay */
432
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
433
+ /* Decide if self-closing tags in attributes are allowed.
434
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
435
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
436
+ /* Output should be safe for common template engines.
437
+ * This means, DOMPurify removes data attributes, mustaches and ERB
438
+ */
439
+ let SAFE_FOR_TEMPLATES = false;
440
+ /* Output should be safe even for XML used within HTML and alike.
441
+ * This means, DOMPurify removes comments when containing risky content.
442
+ */
443
+ let SAFE_FOR_XML = true;
444
+ /* Decide if document with <html>... should be returned */
445
+ let WHOLE_DOCUMENT = false;
446
+ /* Track whether config is already set on this instance of DOMPurify. */
447
+ let SET_CONFIG = false;
448
+ /* Decide if all elements (e.g. style, script) must be children of
449
+ * document.body. By default, browsers might move them to document.head */
450
+ let FORCE_BODY = false;
451
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
452
+ * string (or a TrustedHTML object if Trusted Types are supported).
453
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
454
+ */
455
+ let RETURN_DOM = false;
456
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
457
+ * string (or a TrustedHTML object if Trusted Types are supported) */
458
+ let RETURN_DOM_FRAGMENT = false;
459
+ /* Try to return a Trusted Type object instead of a string, return a string in
460
+ * case Trusted Types are not supported */
461
+ let RETURN_TRUSTED_TYPE = false;
462
+ /* Output should be free from DOM clobbering attacks?
463
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
464
+ */
465
+ let SANITIZE_DOM = true;
466
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
467
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
468
+ *
469
+ * HTML/DOM spec rules that enable DOM Clobbering:
470
+ * - Named Access on Window (§7.3.3)
471
+ * - DOM Tree Accessors (§3.1.5)
472
+ * - Form Element Parent-Child Relations (§4.10.3)
473
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
474
+ * - HTMLCollection (§4.2.10.2)
475
+ *
476
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
477
+ * with a constant string, i.e., `user-content-`
478
+ */
479
+ let SANITIZE_NAMED_PROPS = false;
480
+ const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
481
+ /* Keep element content when removing element? */
482
+ let KEEP_CONTENT = true;
483
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
484
+ * of importing it into a new Document and returning a sanitized copy */
485
+ let IN_PLACE = false;
486
+ /* Allow usage of profiles like html, svg and mathMl */
487
+ let USE_PROFILES = {};
488
+ /* Tags to ignore content of when KEEP_CONTENT is true */
489
+ let FORBID_CONTENTS = null;
490
+ 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']);
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
+ /* Attributes safe for values like "javascript:" */
495
+ let URI_SAFE_ATTRIBUTES = null;
496
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
497
+ const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
498
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
499
+ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
500
+ /* Document namespace */
501
+ let NAMESPACE = HTML_NAMESPACE;
502
+ let IS_EMPTY_INPUT = false;
503
+ /* Allowed XHTML+XML namespaces */
504
+ let ALLOWED_NAMESPACES = null;
505
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
506
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
507
+ let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
508
+ // Certain elements are allowed in both SVG and HTML
509
+ // namespace. We need to specify them explicitly
510
+ // so that they don't get erroneously deleted from
511
+ // HTML namespace.
512
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
513
+ /* Parsing of strict XHTML documents */
514
+ let PARSER_MEDIA_TYPE = null;
515
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
516
+ const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
517
+ let transformCaseFunc = null;
518
+ /* Keep a reference to config to pass to hooks */
519
+ let CONFIG = null;
520
+ /* Ideally, do not touch anything below this line */
521
+ /* ______________________________________________ */
522
+ const formElement = document.createElement('form');
523
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
524
+ return testValue instanceof RegExp || testValue instanceof Function;
525
+ };
526
+ /**
527
+ * _parseConfig
528
+ *
529
+ * @param 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
+ /* Shield configuration object from tampering */
538
+ if (!cfg || typeof cfg !== 'object') {
539
+ cfg = {};
540
+ }
541
+ /* Shield configuration object from prototype pollution */
542
+ cfg = clone(cfg);
543
+ PARSER_MEDIA_TYPE =
544
+ // eslint-disable-next-line unicorn/prefer-includes
545
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
546
+ // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
547
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
548
+ /* Set configuration parameters */
549
+ ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
550
+ ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
551
+ ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
552
+ URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
553
+ DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
554
+ FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
555
+ FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
556
+ FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
557
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
558
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
559
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
560
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
561
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
562
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
563
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
564
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
565
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
566
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
567
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
568
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
569
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
570
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
571
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
572
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
573
+ IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
574
+ NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
575
+ MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
576
+ HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
577
+ CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
578
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
579
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
580
+ }
581
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
582
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
583
+ }
584
+ if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
585
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
586
+ }
587
+ if (SAFE_FOR_TEMPLATES) {
588
+ ALLOW_DATA_ATTR = false;
589
+ }
590
+ if (RETURN_DOM_FRAGMENT) {
591
+ RETURN_DOM = true;
592
+ }
593
+ /* Parse profile info */
594
+ if (USE_PROFILES) {
595
+ ALLOWED_TAGS = addToSet({}, text);
596
+ ALLOWED_ATTR = [];
597
+ if (USE_PROFILES.html === true) {
598
+ addToSet(ALLOWED_TAGS, html$1);
599
+ addToSet(ALLOWED_ATTR, html);
600
+ }
601
+ if (USE_PROFILES.svg === true) {
602
+ addToSet(ALLOWED_TAGS, svg$1);
603
+ addToSet(ALLOWED_ATTR, svg);
604
+ addToSet(ALLOWED_ATTR, xml);
605
+ }
606
+ if (USE_PROFILES.svgFilters === true) {
607
+ addToSet(ALLOWED_TAGS, svgFilters);
608
+ addToSet(ALLOWED_ATTR, svg);
609
+ addToSet(ALLOWED_ATTR, xml);
610
+ }
611
+ if (USE_PROFILES.mathMl === true) {
612
+ addToSet(ALLOWED_TAGS, mathMl$1);
613
+ addToSet(ALLOWED_ATTR, mathMl);
614
+ addToSet(ALLOWED_ATTR, xml);
615
+ }
616
+ }
617
+ /* Merge configuration parameters */
618
+ if (cfg.ADD_TAGS) {
619
+ if (typeof cfg.ADD_TAGS === 'function') {
620
+ EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
621
+ } else {
622
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
623
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
624
+ }
625
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
626
+ }
627
+ }
628
+ if (cfg.ADD_ATTR) {
629
+ if (typeof cfg.ADD_ATTR === 'function') {
630
+ EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
631
+ } else {
632
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
633
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
634
+ }
635
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
636
+ }
637
+ }
638
+ if (cfg.ADD_URI_SAFE_ATTR) {
639
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
640
+ }
641
+ if (cfg.FORBID_CONTENTS) {
642
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
643
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
644
+ }
645
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
646
+ }
647
+ if (cfg.ADD_FORBID_CONTENTS) {
648
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
649
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
650
+ }
651
+ addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
652
+ }
653
+ /* Add #text in case KEEP_CONTENT is set to true */
654
+ if (KEEP_CONTENT) {
655
+ ALLOWED_TAGS['#text'] = true;
656
+ }
657
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
658
+ if (WHOLE_DOCUMENT) {
659
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
660
+ }
661
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
662
+ if (ALLOWED_TAGS.table) {
663
+ addToSet(ALLOWED_TAGS, ['tbody']);
664
+ delete FORBID_TAGS.tbody;
665
+ }
666
+ if (cfg.TRUSTED_TYPES_POLICY) {
667
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
668
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
669
+ }
670
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
671
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
672
+ }
673
+ // Overwrite existing TrustedTypes policy.
674
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
675
+ // Sign local variables required by `sanitize`.
676
+ emptyHTML = trustedTypesPolicy.createHTML('');
677
+ } else {
678
+ // Uninitialized policy, attempt to initialize the internal dompurify policy.
679
+ if (trustedTypesPolicy === undefined) {
680
+ trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
681
+ }
682
+ // If creating the internal policy succeeded sign internal variables.
683
+ if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
684
+ emptyHTML = trustedTypesPolicy.createHTML('');
685
+ }
686
+ }
687
+ // Prevent further manipulation of configuration.
688
+ // Not available in IE8, Safari 5, etc.
689
+ if (freeze) {
690
+ freeze(cfg);
691
+ }
692
+ CONFIG = cfg;
693
+ };
694
+ /* Keep track of all possible SVG and MathML tags
695
+ * so that we can perform the namespace checks
696
+ * correctly. */
697
+ const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
698
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
699
+ /**
700
+ * @param element a DOM element whose namespace is being checked
701
+ * @returns Return false if the element has a
702
+ * namespace that a spec-compliant parser would never
703
+ * return. Return true otherwise.
704
+ */
705
+ const _checkValidNamespace = function _checkValidNamespace(element) {
706
+ let parent = getParentNode(element);
707
+ // In JSDOM, if we're inside shadow DOM, then parentNode
708
+ // can be null. We just simulate parent in this case.
709
+ if (!parent || !parent.tagName) {
710
+ parent = {
711
+ namespaceURI: NAMESPACE,
712
+ tagName: 'template'
713
+ };
714
+ }
715
+ const tagName = stringToLowerCase(element.tagName);
716
+ const parentTagName = stringToLowerCase(parent.tagName);
717
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
718
+ return false;
719
+ }
720
+ if (element.namespaceURI === SVG_NAMESPACE) {
721
+ // The only way to switch from HTML namespace to SVG
722
+ // is via <svg>. If it happens via any other tag, then
723
+ // it should be killed.
724
+ if (parent.namespaceURI === HTML_NAMESPACE) {
725
+ return tagName === 'svg';
726
+ }
727
+ // The only way to switch from MathML to SVG is via`
728
+ // svg if parent is either <annotation-xml> or MathML
729
+ // text integration points.
730
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
731
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
732
+ }
733
+ // We only allow elements that are defined in SVG
734
+ // spec. All others are disallowed in SVG namespace.
735
+ return Boolean(ALL_SVG_TAGS[tagName]);
736
+ }
737
+ if (element.namespaceURI === MATHML_NAMESPACE) {
738
+ // The only way to switch from HTML namespace to MathML
739
+ // is via <math>. If it happens via any other tag, then
740
+ // it should be killed.
741
+ if (parent.namespaceURI === HTML_NAMESPACE) {
742
+ return tagName === 'math';
743
+ }
744
+ // The only way to switch from SVG to MathML is via
745
+ // <math> and HTML integration points
746
+ if (parent.namespaceURI === SVG_NAMESPACE) {
747
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
748
+ }
749
+ // We only allow elements that are defined in MathML
750
+ // spec. All others are disallowed in MathML namespace.
751
+ return Boolean(ALL_MATHML_TAGS[tagName]);
752
+ }
753
+ if (element.namespaceURI === HTML_NAMESPACE) {
754
+ // The only way to switch from SVG to HTML is via
755
+ // HTML integration points, and from MathML to HTML
756
+ // is via MathML text integration points
757
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
758
+ return false;
759
+ }
760
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
761
+ return false;
762
+ }
763
+ // We disallow tags that are specific for MathML
764
+ // or SVG and should never appear in HTML namespace
765
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
766
+ }
767
+ // For XHTML and XML documents that support custom namespaces
768
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
769
+ return true;
770
+ }
771
+ // The code should never reach this place (this means
772
+ // that the element somehow got namespace that is not
773
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
774
+ // Return false just in case.
775
+ return false;
776
+ };
777
+ /**
778
+ * _forceRemove
779
+ *
780
+ * @param node a DOM node
781
+ */
782
+ const _forceRemove = function _forceRemove(node) {
783
+ arrayPush(DOMPurify.removed, {
784
+ element: node
785
+ });
786
+ try {
787
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
788
+ getParentNode(node).removeChild(node);
789
+ } catch (_) {
790
+ remove(node);
791
+ }
792
+ };
793
+ /**
794
+ * _removeAttribute
795
+ *
796
+ * @param name an Attribute name
797
+ * @param element a DOM node
798
+ */
799
+ const _removeAttribute = function _removeAttribute(name, element) {
800
+ try {
801
+ arrayPush(DOMPurify.removed, {
802
+ attribute: element.getAttributeNode(name),
803
+ from: element
804
+ });
805
+ } catch (_) {
806
+ arrayPush(DOMPurify.removed, {
807
+ attribute: null,
808
+ from: element
809
+ });
810
+ }
811
+ element.removeAttribute(name);
812
+ // We void attribute values for unremovable "is" attributes
813
+ if (name === 'is') {
814
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
815
+ try {
816
+ _forceRemove(element);
817
+ } catch (_) {}
818
+ } else {
819
+ try {
820
+ element.setAttribute(name, '');
821
+ } catch (_) {}
822
+ }
823
+ }
824
+ };
825
+ /**
826
+ * _initDocument
827
+ *
828
+ * @param dirty - a string of dirty markup
829
+ * @return a DOM, filled with the dirty markup
830
+ */
831
+ const _initDocument = function _initDocument(dirty) {
832
+ /* Create a HTML document */
833
+ let doc = null;
834
+ let leadingWhitespace = null;
835
+ if (FORCE_BODY) {
836
+ dirty = '<remove></remove>' + dirty;
837
+ } else {
838
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
839
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
840
+ leadingWhitespace = matches && matches[0];
841
+ }
842
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
843
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
844
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
845
+ }
846
+ const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
847
+ /*
848
+ * Use the DOMParser API by default, fallback later if needs be
849
+ * DOMParser not work for svg when has multiple root element.
850
+ */
851
+ if (NAMESPACE === HTML_NAMESPACE) {
852
+ try {
853
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
854
+ } catch (_) {}
855
+ }
856
+ /* Use createHTMLDocument in case DOMParser is not available */
857
+ if (!doc || !doc.documentElement) {
858
+ doc = implementation.createDocument(NAMESPACE, 'template', null);
859
+ try {
860
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
861
+ } catch (_) {
862
+ // Syntax error if dirtyPayload is invalid xml
863
+ }
864
+ }
865
+ const body = doc.body || doc.documentElement;
866
+ if (dirty && leadingWhitespace) {
867
+ body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
868
+ }
869
+ /* Work on whole document or just its body */
870
+ if (NAMESPACE === HTML_NAMESPACE) {
871
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
872
+ }
873
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
874
+ };
875
+ /**
876
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
877
+ *
878
+ * @param root The root element or node to start traversing on.
879
+ * @return The created NodeIterator
880
+ */
881
+ const _createNodeIterator = function _createNodeIterator(root) {
882
+ return createNodeIterator.call(root.ownerDocument || root, root,
883
+ // eslint-disable-next-line no-bitwise
884
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
885
+ };
886
+ /**
887
+ * _isClobbered
888
+ *
889
+ * @param element element to check for clobbering attacks
890
+ * @return true if clobbered, false if safe
891
+ */
892
+ const _isClobbered = function _isClobbered(element) {
893
+ 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');
894
+ };
895
+ /**
896
+ * Checks whether the given object is a DOM node.
897
+ *
898
+ * @param value object to check whether it's a DOM node
899
+ * @return true is object is a DOM node
900
+ */
901
+ const _isNode = function _isNode(value) {
902
+ return typeof Node === 'function' && value instanceof Node;
903
+ };
904
+ function _executeHooks(hooks, currentNode, data) {
905
+ arrayForEach(hooks, hook => {
906
+ hook.call(DOMPurify, currentNode, data, CONFIG);
907
+ });
908
+ }
909
+ /**
910
+ * _sanitizeElements
911
+ *
912
+ * @protect nodeName
913
+ * @protect textContent
914
+ * @protect removeChild
915
+ * @param currentNode to check for permission to exist
916
+ * @return true if node was killed, false if left alive
917
+ */
918
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
919
+ let content = null;
920
+ /* Execute a hook if present */
921
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
922
+ /* Check if element is clobbered or can clobber */
923
+ if (_isClobbered(currentNode)) {
924
+ _forceRemove(currentNode);
925
+ return true;
926
+ }
927
+ /* Now let's check the element's type and name */
928
+ const tagName = transformCaseFunc(currentNode.nodeName);
929
+ /* Execute a hook if present */
930
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
931
+ tagName,
932
+ allowedTags: ALLOWED_TAGS
933
+ });
934
+ /* Detect mXSS attempts abusing namespace confusion */
935
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
936
+ _forceRemove(currentNode);
937
+ return true;
938
+ }
939
+ /* Remove any occurrence of processing instructions */
940
+ if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
941
+ _forceRemove(currentNode);
942
+ return true;
943
+ }
944
+ /* Remove any kind of possibly harmful comments */
945
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
946
+ _forceRemove(currentNode);
947
+ return true;
948
+ }
949
+ /* Remove element if anything forbids its presence */
950
+ if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
951
+ /* Check if we have a custom element to handle */
952
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
953
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
954
+ return false;
955
+ }
956
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
957
+ return false;
958
+ }
959
+ }
960
+ /* Keep content except for bad-listed elements */
961
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
962
+ const parentNode = getParentNode(currentNode) || currentNode.parentNode;
963
+ const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
964
+ if (childNodes && parentNode) {
965
+ const childCount = childNodes.length;
966
+ for (let i = childCount - 1; i >= 0; --i) {
967
+ const childClone = cloneNode(childNodes[i], true);
968
+ childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
969
+ parentNode.insertBefore(childClone, getNextSibling(currentNode));
970
+ }
971
+ }
972
+ }
973
+ _forceRemove(currentNode);
974
+ return true;
975
+ }
976
+ /* Check whether element has a valid namespace */
977
+ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
978
+ _forceRemove(currentNode);
979
+ return true;
980
+ }
981
+ /* Make sure that older browsers don't get fallback-tag mXSS */
982
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
983
+ _forceRemove(currentNode);
984
+ return true;
985
+ }
986
+ /* Sanitize element content to be template-safe */
987
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
988
+ /* Get the element's text content */
989
+ content = currentNode.textContent;
990
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
991
+ content = stringReplace(content, expr, ' ');
992
+ });
993
+ if (currentNode.textContent !== content) {
994
+ arrayPush(DOMPurify.removed, {
995
+ element: currentNode.cloneNode()
996
+ });
997
+ currentNode.textContent = content;
998
+ }
999
+ }
1000
+ /* Execute a hook if present */
1001
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
1002
+ return false;
1003
+ };
1004
+ /**
1005
+ * _isValidAttribute
1006
+ *
1007
+ * @param lcTag Lowercase tag name of containing element.
1008
+ * @param lcName Lowercase attribute name.
1009
+ * @param value Attribute value.
1010
+ * @return Returns true if `value` is valid, otherwise false.
1011
+ */
1012
+ // eslint-disable-next-line complexity
1013
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1014
+ /* Make sure attribute cannot clobber */
1015
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1016
+ return false;
1017
+ }
1018
+ /* Allow valid data-* attributes: At least one character after "-"
1019
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1020
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1021
+ We don't need to check the value; it's always URI safe. */
1022
+ 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]) {
1023
+ if (
1024
+ // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1025
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1026
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1027
+ _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)) ||
1028
+ // Alternative, second condition checks if it's an `is`-attribute, AND
1029
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1030
+ 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 {
1031
+ return false;
1032
+ }
1033
+ /* Check value is safe. First, is attr inert? If so, is safe */
1034
+ } 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) {
1035
+ return false;
1036
+ } else ;
1037
+ return true;
1038
+ };
1039
+ /**
1040
+ * _isBasicCustomElement
1041
+ * checks if at least one dash is included in tagName, and it's not the first char
1042
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1043
+ *
1044
+ * @param tagName name of the tag of the node to sanitize
1045
+ * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1046
+ */
1047
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1048
+ return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
1049
+ };
1050
+ /**
1051
+ * _sanitizeAttributes
1052
+ *
1053
+ * @protect attributes
1054
+ * @protect nodeName
1055
+ * @protect removeAttribute
1056
+ * @protect setAttribute
1057
+ *
1058
+ * @param currentNode to sanitize
1059
+ */
1060
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1061
+ /* Execute a hook if present */
1062
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1063
+ const {
1064
+ attributes
1065
+ } = currentNode;
1066
+ /* Check if we have attributes; if not we might have a text node */
1067
+ if (!attributes || _isClobbered(currentNode)) {
1068
+ return;
1069
+ }
1070
+ const hookEvent = {
1071
+ attrName: '',
1072
+ attrValue: '',
1073
+ keepAttr: true,
1074
+ allowedAttributes: ALLOWED_ATTR,
1075
+ forceKeepAttr: undefined
1076
+ };
1077
+ let l = attributes.length;
1078
+ /* Go backwards over all attributes; safely remove bad ones */
1079
+ while (l--) {
1080
+ const attr = attributes[l];
1081
+ const {
1082
+ name,
1083
+ namespaceURI,
1084
+ value: attrValue
1085
+ } = attr;
1086
+ const lcName = transformCaseFunc(name);
1087
+ const initValue = attrValue;
1088
+ let value = name === 'value' ? initValue : stringTrim(initValue);
1089
+ /* Execute a hook if present */
1090
+ hookEvent.attrName = lcName;
1091
+ hookEvent.attrValue = value;
1092
+ hookEvent.keepAttr = true;
1093
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1094
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
1095
+ value = hookEvent.attrValue;
1096
+ /* Full DOM Clobbering protection via namespace isolation,
1097
+ * Prefix id and name attributes with `user-content-`
1098
+ */
1099
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1100
+ // Remove the attribute with this value
1101
+ _removeAttribute(name, currentNode);
1102
+ // Prefix the value and later re-create the attribute with the sanitized value
1103
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
1104
+ }
1105
+ /* Work around a security issue with comments inside attributes */
1106
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) {
1107
+ _removeAttribute(name, currentNode);
1108
+ continue;
1109
+ }
1110
+ /* Make sure we cannot easily use animated hrefs, even if animations are allowed */
1111
+ if (lcName === 'attributename' && stringMatch(value, 'href')) {
1112
+ _removeAttribute(name, currentNode);
1113
+ continue;
1114
+ }
1115
+ /* Did the hooks approve of the attribute? */
1116
+ if (hookEvent.forceKeepAttr) {
1117
+ continue;
1118
+ }
1119
+ /* Did the hooks approve of the attribute? */
1120
+ if (!hookEvent.keepAttr) {
1121
+ _removeAttribute(name, currentNode);
1122
+ continue;
1123
+ }
1124
+ /* Work around a security issue in jQuery 3.0 */
1125
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1126
+ _removeAttribute(name, currentNode);
1127
+ continue;
1128
+ }
1129
+ /* Sanitize attribute content to be template-safe */
1130
+ if (SAFE_FOR_TEMPLATES) {
1131
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1132
+ value = stringReplace(value, expr, ' ');
1133
+ });
1134
+ }
1135
+ /* Is `value` valid for this attribute? */
1136
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1137
+ if (!_isValidAttribute(lcTag, lcName, value)) {
1138
+ _removeAttribute(name, currentNode);
1139
+ continue;
1140
+ }
1141
+ /* Handle attributes that require Trusted Types */
1142
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1143
+ if (namespaceURI) ; else {
1144
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1145
+ case 'TrustedHTML':
1146
+ {
1147
+ value = trustedTypesPolicy.createHTML(value);
1148
+ break;
1149
+ }
1150
+ case 'TrustedScriptURL':
1151
+ {
1152
+ value = trustedTypesPolicy.createScriptURL(value);
1153
+ break;
1154
+ }
1155
+ }
1156
+ }
1157
+ }
1158
+ /* Handle invalid data-* attribute set by try-catching it */
1159
+ if (value !== initValue) {
1160
+ try {
1161
+ if (namespaceURI) {
1162
+ currentNode.setAttributeNS(namespaceURI, name, value);
1163
+ } else {
1164
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1165
+ currentNode.setAttribute(name, value);
1166
+ }
1167
+ if (_isClobbered(currentNode)) {
1168
+ _forceRemove(currentNode);
1169
+ } else {
1170
+ arrayPop(DOMPurify.removed);
1171
+ }
1172
+ } catch (_) {
1173
+ _removeAttribute(name, currentNode);
1174
+ }
1175
+ }
1176
+ }
1177
+ /* Execute a hook if present */
1178
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
1179
+ };
1180
+ /**
1181
+ * _sanitizeShadowDOM
1182
+ *
1183
+ * @param fragment to iterate over recursively
1184
+ */
1185
+ const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1186
+ let shadowNode = null;
1187
+ const shadowIterator = _createNodeIterator(fragment);
1188
+ /* Execute a hook if present */
1189
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
1190
+ while (shadowNode = shadowIterator.nextNode()) {
1191
+ /* Execute a hook if present */
1192
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
1193
+ /* Sanitize tags and elements */
1194
+ _sanitizeElements(shadowNode);
1195
+ /* Check attributes next */
1196
+ _sanitizeAttributes(shadowNode);
1197
+ /* Deep shadow DOM detected */
1198
+ if (shadowNode.content instanceof DocumentFragment) {
1199
+ _sanitizeShadowDOM(shadowNode.content);
1200
+ }
1201
+ }
1202
+ /* Execute a hook if present */
1203
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1204
+ };
1205
+ // eslint-disable-next-line complexity
1206
+ DOMPurify.sanitize = function (dirty) {
1207
+ let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1208
+ let body = null;
1209
+ let importedNode = null;
1210
+ let currentNode = null;
1211
+ let returnNode = null;
1212
+ /* Make sure we have a string to sanitize.
1213
+ DO NOT return early, as this will return the wrong type if
1214
+ the user has requested a DOM object rather than a string */
1215
+ IS_EMPTY_INPUT = !dirty;
1216
+ if (IS_EMPTY_INPUT) {
1217
+ dirty = '<!-->';
1218
+ }
1219
+ /* Stringify, in case dirty is an object */
1220
+ if (typeof dirty !== 'string' && !_isNode(dirty)) {
1221
+ if (typeof dirty.toString === 'function') {
1222
+ dirty = dirty.toString();
1223
+ if (typeof dirty !== 'string') {
1224
+ throw typeErrorCreate('dirty is not a string, aborting');
1225
+ }
1226
+ } else {
1227
+ throw typeErrorCreate('toString is not a function');
1228
+ }
1229
+ }
1230
+ /* Return dirty HTML if DOMPurify cannot run */
1231
+ if (!DOMPurify.isSupported) {
1232
+ return dirty;
1233
+ }
1234
+ /* Assign config vars */
1235
+ if (!SET_CONFIG) {
1236
+ _parseConfig(cfg);
1237
+ }
1238
+ /* Clean up removed elements */
1239
+ DOMPurify.removed = [];
1240
+ /* Check if dirty is correctly typed for IN_PLACE */
1241
+ if (typeof dirty === 'string') {
1242
+ IN_PLACE = false;
1243
+ }
1244
+ if (IN_PLACE) {
1245
+ /* Do some early pre-sanitization to avoid unsafe root nodes */
1246
+ if (dirty.nodeName) {
1247
+ const tagName = transformCaseFunc(dirty.nodeName);
1248
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1249
+ throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1250
+ }
1251
+ }
1252
+ } else if (dirty instanceof Node) {
1253
+ /* If dirty is a DOM element, append to an empty document to avoid
1254
+ elements being stripped by the parser */
1255
+ body = _initDocument('<!---->');
1256
+ importedNode = body.ownerDocument.importNode(dirty, true);
1257
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
1258
+ /* Node is already a body, use as is */
1259
+ body = importedNode;
1260
+ } else if (importedNode.nodeName === 'HTML') {
1261
+ body = importedNode;
1262
+ } else {
1263
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1264
+ body.appendChild(importedNode);
1265
+ }
1266
+ } else {
1267
+ /* Exit directly if we have nothing to do */
1268
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
1269
+ // eslint-disable-next-line unicorn/prefer-includes
1270
+ dirty.indexOf('<') === -1) {
1271
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1272
+ }
1273
+ /* Initialize the document to work on */
1274
+ body = _initDocument(dirty);
1275
+ /* Check we have a DOM node from the data */
1276
+ if (!body) {
1277
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1278
+ }
1279
+ }
1280
+ /* Remove first element node (ours) if FORCE_BODY is set */
1281
+ if (body && FORCE_BODY) {
1282
+ _forceRemove(body.firstChild);
1283
+ }
1284
+ /* Get node iterator */
1285
+ const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
1286
+ /* Now start iterating over the created document */
1287
+ while (currentNode = nodeIterator.nextNode()) {
1288
+ /* Sanitize tags and elements */
1289
+ _sanitizeElements(currentNode);
1290
+ /* Check attributes next */
1291
+ _sanitizeAttributes(currentNode);
1292
+ /* Shadow DOM detected, sanitize it */
1293
+ if (currentNode.content instanceof DocumentFragment) {
1294
+ _sanitizeShadowDOM(currentNode.content);
1295
+ }
1296
+ }
1297
+ /* If we sanitized `dirty` in-place, return it. */
1298
+ if (IN_PLACE) {
1299
+ return dirty;
1300
+ }
1301
+ /* Return sanitized string or DOM */
1302
+ if (RETURN_DOM) {
1303
+ if (RETURN_DOM_FRAGMENT) {
1304
+ returnNode = createDocumentFragment.call(body.ownerDocument);
1305
+ while (body.firstChild) {
1306
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1307
+ returnNode.appendChild(body.firstChild);
1308
+ }
1309
+ } else {
1310
+ returnNode = body;
1311
+ }
1312
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
1313
+ /*
1314
+ AdoptNode() is not used because internal state is not reset
1315
+ (e.g. the past names map of a HTMLFormElement), this is safe
1316
+ in theory but we would rather not risk another attack vector.
1317
+ The state that is cloned by importNode() is explicitly defined
1318
+ by the specs.
1319
+ */
1320
+ returnNode = importNode.call(originalDocument, returnNode, true);
1321
+ }
1322
+ return returnNode;
1323
+ }
1324
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1325
+ /* Serialize doctype if allowed */
1326
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1327
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1328
+ }
1329
+ /* Sanitize final string template-safe */
1330
+ if (SAFE_FOR_TEMPLATES) {
1331
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1332
+ serializedHTML = stringReplace(serializedHTML, expr, ' ');
1333
+ });
1334
+ }
1335
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1336
+ };
1337
+ DOMPurify.setConfig = function () {
1338
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1339
+ _parseConfig(cfg);
1340
+ SET_CONFIG = true;
1341
+ };
1342
+ DOMPurify.clearConfig = function () {
1343
+ CONFIG = null;
1344
+ SET_CONFIG = false;
1345
+ };
1346
+ DOMPurify.isValidAttribute = function (tag, attr, value) {
1347
+ /* Initialize shared config vars if necessary. */
1348
+ if (!CONFIG) {
1349
+ _parseConfig({});
1350
+ }
1351
+ const lcTag = transformCaseFunc(tag);
1352
+ const lcName = transformCaseFunc(attr);
1353
+ return _isValidAttribute(lcTag, lcName, value);
1354
+ };
1355
+ DOMPurify.addHook = function (entryPoint, hookFunction) {
1356
+ if (typeof hookFunction !== 'function') {
1357
+ return;
1358
+ }
1359
+ arrayPush(hooks[entryPoint], hookFunction);
1360
+ };
1361
+ DOMPurify.removeHook = function (entryPoint, hookFunction) {
1362
+ if (hookFunction !== undefined) {
1363
+ const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
1364
+ return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
1365
+ }
1366
+ return arrayPop(hooks[entryPoint]);
1367
+ };
1368
+ DOMPurify.removeHooks = function (entryPoint) {
1369
+ hooks[entryPoint] = [];
1370
+ };
1371
+ DOMPurify.removeAllHooks = function () {
1372
+ hooks = _createHooksMap();
1373
+ };
1374
+ return DOMPurify;
1375
+ }
1376
+ var purify = createDOMPurify();
1377
+
1378
+ var purify_es = /*#__PURE__*/Object.freeze({
1379
+ __proto__: null,
1380
+ default: purify
1381
+ });
1382
+
1383
+ exports.purify = purify;
1384
+ exports.purify_es = purify_es;