@everymatrix/nuts-inbox-widget 1.99.56 → 1.99.59

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.
package/hydrate/index.mjs CHANGED
@@ -42820,1565 +42820,2496 @@ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof win
42820
42820
 
42821
42821
  var purify = {exports: {}};
42822
42822
 
42823
- /*! @license DOMPurify 3.1.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.1.6/LICENSE */
42823
+ /*! @license DOMPurify 3.4.17 | (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.17/LICENSE */
42824
42824
 
42825
42825
  (function (module, exports) {
42826
- (function (global, factory) {
42827
- module.exports = factory() ;
42828
- })(commonjsGlobal, (function () {
42829
- const {
42830
- entries,
42831
- setPrototypeOf,
42832
- isFrozen,
42833
- getPrototypeOf,
42834
- getOwnPropertyDescriptor
42835
- } = Object;
42836
- let {
42837
- freeze,
42838
- seal,
42839
- create
42840
- } = Object; // eslint-disable-line import/no-mutable-exports
42841
- let {
42842
- apply,
42843
- construct
42844
- } = typeof Reflect !== 'undefined' && Reflect;
42845
- if (!freeze) {
42846
- freeze = function freeze(x) {
42847
- return x;
42848
- };
42849
- }
42850
- if (!seal) {
42851
- seal = function seal(x) {
42852
- return x;
42853
- };
42854
- }
42855
- if (!apply) {
42856
- apply = function apply(fun, thisValue, args) {
42857
- return fun.apply(thisValue, args);
42858
- };
42859
- }
42860
- if (!construct) {
42861
- construct = function construct(Func, args) {
42862
- return new Func(...args);
42863
- };
42864
- }
42865
- const arrayForEach = unapply(Array.prototype.forEach);
42866
- const arrayPop = unapply(Array.prototype.pop);
42867
- const arrayPush = unapply(Array.prototype.push);
42868
- const stringToLowerCase = unapply(String.prototype.toLowerCase);
42869
- const stringToString = unapply(String.prototype.toString);
42870
- const stringMatch = unapply(String.prototype.match);
42871
- const stringReplace = unapply(String.prototype.replace);
42872
- const stringIndexOf = unapply(String.prototype.indexOf);
42873
- const stringTrim = unapply(String.prototype.trim);
42874
- const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
42875
- const regExpTest = unapply(RegExp.prototype.test);
42876
- const typeErrorCreate = unconstruct(TypeError);
42877
-
42878
- /**
42879
- * Creates a new function that calls the given function with a specified thisArg and arguments.
42880
- *
42881
- * @param {Function} func - The function to be wrapped and called.
42882
- * @returns {Function} A new function that calls the given function with a specified thisArg and arguments.
42883
- */
42884
- function unapply(func) {
42885
- return function (thisArg) {
42886
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
42887
- args[_key - 1] = arguments[_key];
42888
- }
42889
- return apply(func, thisArg, args);
42890
- };
42891
- }
42892
-
42893
- /**
42894
- * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
42895
- *
42896
- * @param {Function} func - The constructor function to be wrapped and called.
42897
- * @returns {Function} A new function that constructs an instance of the given constructor function with the provided arguments.
42898
- */
42899
- function unconstruct(func) {
42900
- return function () {
42901
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
42902
- args[_key2] = arguments[_key2];
42903
- }
42904
- return construct(func, args);
42905
- };
42906
- }
42907
-
42908
- /**
42909
- * Add properties to a lookup table
42910
- *
42911
- * @param {Object} set - The set to which elements will be added.
42912
- * @param {Array} array - The array containing elements to be added to the set.
42913
- * @param {Function} transformCaseFunc - An optional function to transform the case of each element before adding to the set.
42914
- * @returns {Object} The modified set with added elements.
42915
- */
42916
- function addToSet(set, array) {
42917
- let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
42918
- if (setPrototypeOf) {
42919
- // Make 'in' and truthy checks like Boolean(set.constructor)
42920
- // independent of any properties defined on Object.prototype.
42921
- // Prevent prototype setters from intercepting set as a this value.
42922
- setPrototypeOf(set, null);
42923
- }
42924
- let l = array.length;
42925
- while (l--) {
42926
- let element = array[l];
42927
- if (typeof element === 'string') {
42928
- const lcElement = transformCaseFunc(element);
42929
- if (lcElement !== element) {
42930
- // Config presets (e.g. tags.js, attrs.js) are immutable.
42931
- if (!isFrozen(array)) {
42932
- array[l] = lcElement;
42933
- }
42934
- element = lcElement;
42935
- }
42936
- }
42937
- set[element] = true;
42938
- }
42939
- return set;
42940
- }
42941
-
42942
- /**
42943
- * Clean up an array to harden against CSPP
42944
- *
42945
- * @param {Array} array - The array to be cleaned.
42946
- * @returns {Array} The cleaned version of the array
42947
- */
42948
- function cleanArray(array) {
42949
- for (let index = 0; index < array.length; index++) {
42950
- const isPropertyExist = objectHasOwnProperty(array, index);
42951
- if (!isPropertyExist) {
42952
- array[index] = null;
42953
- }
42954
- }
42955
- return array;
42956
- }
42957
-
42958
- /**
42959
- * Shallow clone an object
42960
- *
42961
- * @param {Object} object - The object to be cloned.
42962
- * @returns {Object} A new object that copies the original.
42963
- */
42964
- function clone(object) {
42965
- const newObject = create(null);
42966
- for (const [property, value] of entries(object)) {
42967
- const isPropertyExist = objectHasOwnProperty(object, property);
42968
- if (isPropertyExist) {
42969
- if (Array.isArray(value)) {
42970
- newObject[property] = cleanArray(value);
42971
- } else if (value && typeof value === 'object' && value.constructor === Object) {
42972
- newObject[property] = clone(value);
42973
- } else {
42974
- newObject[property] = value;
42975
- }
42976
- }
42977
- }
42978
- return newObject;
42979
- }
42980
-
42981
- /**
42982
- * This method automatically checks if the prop is function or getter and behaves accordingly.
42983
- *
42984
- * @param {Object} object - The object to look up the getter function in its prototype chain.
42985
- * @param {String} prop - The property name for which to find the getter function.
42986
- * @returns {Function} The getter function found in the prototype chain or a fallback function.
42987
- */
42988
- function lookupGetter(object, prop) {
42989
- while (object !== null) {
42990
- const desc = getOwnPropertyDescriptor(object, prop);
42991
- if (desc) {
42992
- if (desc.get) {
42993
- return unapply(desc.get);
42994
- }
42995
- if (typeof desc.value === 'function') {
42996
- return unapply(desc.value);
42997
- }
42998
- }
42999
- object = getPrototypeOf(object);
43000
- }
43001
- function fallbackValue() {
43002
- return null;
43003
- }
43004
- return fallbackValue;
43005
- }
43006
-
43007
- const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
43008
-
43009
- // SVG
43010
- const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
43011
- 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']);
43012
-
43013
- // List of SVG elements that are disallowed by default.
43014
- // We still need to know them so that we can do namespace
43015
- // checks properly in case one wants to add them to
43016
- // allow-list.
43017
- 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']);
43018
- 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']);
43019
-
43020
- // Similarly to SVG, we want to know all MathML elements,
43021
- // even those that we disallow by default.
43022
- const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
43023
- const text = freeze(['#text']);
43024
-
43025
- const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);
43026
- const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
43027
- 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']);
43028
- const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
43029
-
43030
- // eslint-disable-next-line unicorn/better-regex
43031
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
43032
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
43033
- const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
43034
- const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
43035
- const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
43036
- const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
43037
- );
43038
- const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
43039
- const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
43040
- );
43041
- const DOCTYPE_NAME = seal(/^html$/i);
43042
- const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
43043
-
43044
- var EXPRESSIONS = /*#__PURE__*/Object.freeze({
43045
- __proto__: null,
43046
- MUSTACHE_EXPR: MUSTACHE_EXPR,
43047
- ERB_EXPR: ERB_EXPR,
43048
- TMPLIT_EXPR: TMPLIT_EXPR,
43049
- DATA_ATTR: DATA_ATTR,
43050
- ARIA_ATTR: ARIA_ATTR,
43051
- IS_ALLOWED_URI: IS_ALLOWED_URI,
43052
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
43053
- ATTR_WHITESPACE: ATTR_WHITESPACE,
43054
- DOCTYPE_NAME: DOCTYPE_NAME,
43055
- CUSTOM_ELEMENT: CUSTOM_ELEMENT
43056
- });
43057
-
43058
- // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
43059
- const NODE_TYPE = {
43060
- element: 1,
43061
- attribute: 2,
43062
- text: 3,
43063
- cdataSection: 4,
43064
- entityReference: 5,
43065
- // Deprecated
43066
- entityNode: 6,
43067
- // Deprecated
43068
- progressingInstruction: 7,
43069
- comment: 8,
43070
- document: 9,
43071
- documentType: 10,
43072
- documentFragment: 11,
43073
- notation: 12 // Deprecated
43074
- };
43075
- const getGlobal = function getGlobal() {
43076
- return typeof window === 'undefined' ? null : window;
43077
- };
43078
-
43079
- /**
43080
- * Creates a no-op policy for internal use only.
43081
- * Don't export this function outside this module!
43082
- * @param {TrustedTypePolicyFactory} trustedTypes The policy factory.
43083
- * @param {HTMLScriptElement} purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
43084
- * @return {TrustedTypePolicy} The policy created (or null, if Trusted Types
43085
- * are not supported or creating the policy failed).
43086
- */
43087
- const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
43088
- if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
43089
- return null;
43090
- }
43091
-
43092
- // Allow the callers to control the unique policy name
43093
- // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
43094
- // Policy creation with duplicate names throws in Trusted Types.
43095
- let suffix = null;
43096
- const ATTR_NAME = 'data-tt-policy-suffix';
43097
- if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
43098
- suffix = purifyHostElement.getAttribute(ATTR_NAME);
43099
- }
43100
- const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
43101
- try {
43102
- return trustedTypes.createPolicy(policyName, {
43103
- createHTML(html) {
43104
- return html;
43105
- },
43106
- createScriptURL(scriptUrl) {
43107
- return scriptUrl;
43108
- }
43109
- });
43110
- } catch (_) {
43111
- // Policy creation failed (most likely another DOMPurify script has
43112
- // already run). Skip creating the policy, as this will only cause errors
43113
- // if TT are enforced.
43114
- console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
43115
- return null;
43116
- }
43117
- };
43118
- function createDOMPurify() {
43119
- let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
43120
- const DOMPurify = root => createDOMPurify(root);
43121
-
43122
- /**
43123
- * Version label, exposed for easier checks
43124
- * if DOMPurify is up to date or not
43125
- */
43126
- DOMPurify.version = '3.1.6';
43127
-
43128
- /**
43129
- * Array of elements that DOMPurify removed during sanitation.
43130
- * Empty if nothing was removed.
43131
- */
43132
- DOMPurify.removed = [];
43133
- if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document) {
43134
- // Not running in a browser, provide a factory function
43135
- // so that you can pass your own Window
43136
- DOMPurify.isSupported = false;
43137
- return DOMPurify;
43138
- }
43139
- let {
43140
- document
43141
- } = window;
43142
- const originalDocument = document;
43143
- const currentScript = originalDocument.currentScript;
43144
- const {
43145
- DocumentFragment,
43146
- HTMLTemplateElement,
43147
- Node,
43148
- Element,
43149
- NodeFilter,
43150
- NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
43151
- HTMLFormElement,
43152
- DOMParser,
43153
- trustedTypes
43154
- } = window;
43155
- const ElementPrototype = Element.prototype;
43156
- const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
43157
- const remove = lookupGetter(ElementPrototype, 'remove');
43158
- const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
43159
- const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
43160
- const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
43161
-
43162
- // As per issue #47, the web-components registry is inherited by a
43163
- // new document created via createHTMLDocument. As per the spec
43164
- // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
43165
- // a new empty registry is used when creating a template contents owner
43166
- // document, so we use that as our parent document to ensure nothing
43167
- // is inherited.
43168
- if (typeof HTMLTemplateElement === 'function') {
43169
- const template = document.createElement('template');
43170
- if (template.content && template.content.ownerDocument) {
43171
- document = template.content.ownerDocument;
43172
- }
43173
- }
43174
- let trustedTypesPolicy;
43175
- let emptyHTML = '';
43176
- const {
43177
- implementation,
43178
- createNodeIterator,
43179
- createDocumentFragment,
43180
- getElementsByTagName
43181
- } = document;
43182
- const {
43183
- importNode
43184
- } = originalDocument;
43185
- let hooks = {};
43186
-
43187
- /**
43188
- * Expose whether this browser supports running the full DOMPurify.
43189
- */
43190
- DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
43191
- const {
43192
- MUSTACHE_EXPR,
43193
- ERB_EXPR,
43194
- TMPLIT_EXPR,
43195
- DATA_ATTR,
43196
- ARIA_ATTR,
43197
- IS_SCRIPT_OR_DATA,
43198
- ATTR_WHITESPACE,
43199
- CUSTOM_ELEMENT
43200
- } = EXPRESSIONS;
43201
- let {
43202
- IS_ALLOWED_URI: IS_ALLOWED_URI$1
43203
- } = EXPRESSIONS;
43204
-
43205
- /**
43206
- * We consider the elements and attributes below to be safe. Ideally
43207
- * don't add any new ones but feel free to remove unwanted ones.
43208
- */
43209
-
43210
- /* allowed element names */
43211
- let ALLOWED_TAGS = null;
43212
- const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
43213
-
43214
- /* Allowed attribute names */
43215
- let ALLOWED_ATTR = null;
43216
- const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
43217
-
43218
- /*
43219
- * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
43220
- * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
43221
- * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
43222
- * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
43223
- */
43224
- let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
43225
- tagNameCheck: {
43226
- writable: true,
43227
- configurable: false,
43228
- enumerable: true,
43229
- value: null
43230
- },
43231
- attributeNameCheck: {
43232
- writable: true,
43233
- configurable: false,
43234
- enumerable: true,
43235
- value: null
43236
- },
43237
- allowCustomizedBuiltInElements: {
43238
- writable: true,
43239
- configurable: false,
43240
- enumerable: true,
43241
- value: false
43242
- }
43243
- }));
43244
-
43245
- /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
43246
- let FORBID_TAGS = null;
43247
-
43248
- /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
43249
- let FORBID_ATTR = null;
43250
-
43251
- /* Decide if ARIA attributes are okay */
43252
- let ALLOW_ARIA_ATTR = true;
43253
-
43254
- /* Decide if custom data attributes are okay */
43255
- let ALLOW_DATA_ATTR = true;
43256
-
43257
- /* Decide if unknown protocols are okay */
43258
- let ALLOW_UNKNOWN_PROTOCOLS = false;
43259
-
43260
- /* Decide if self-closing tags in attributes are allowed.
43261
- * Usually removed due to a mXSS issue in jQuery 3.0 */
43262
- let ALLOW_SELF_CLOSE_IN_ATTR = true;
43263
-
43264
- /* Output should be safe for common template engines.
43265
- * This means, DOMPurify removes data attributes, mustaches and ERB
43266
- */
43267
- let SAFE_FOR_TEMPLATES = false;
43268
-
43269
- /* Output should be safe even for XML used within HTML and alike.
43270
- * This means, DOMPurify removes comments when containing risky content.
43271
- */
43272
- let SAFE_FOR_XML = true;
43273
-
43274
- /* Decide if document with <html>... should be returned */
43275
- let WHOLE_DOCUMENT = false;
43276
-
43277
- /* Track whether config is already set on this instance of DOMPurify. */
43278
- let SET_CONFIG = false;
43279
-
43280
- /* Decide if all elements (e.g. style, script) must be children of
43281
- * document.body. By default, browsers might move them to document.head */
43282
- let FORCE_BODY = false;
43283
-
43284
- /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
43285
- * string (or a TrustedHTML object if Trusted Types are supported).
43286
- * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
43287
- */
43288
- let RETURN_DOM = false;
43289
-
43290
- /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
43291
- * string (or a TrustedHTML object if Trusted Types are supported) */
43292
- let RETURN_DOM_FRAGMENT = false;
43293
-
43294
- /* Try to return a Trusted Type object instead of a string, return a string in
43295
- * case Trusted Types are not supported */
43296
- let RETURN_TRUSTED_TYPE = false;
43297
-
43298
- /* Output should be free from DOM clobbering attacks?
43299
- * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
43300
- */
43301
- let SANITIZE_DOM = true;
43302
-
43303
- /* Achieve full DOM Clobbering protection by isolating the namespace of named
43304
- * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
43305
- *
43306
- * HTML/DOM spec rules that enable DOM Clobbering:
43307
- * - Named Access on Window (§7.3.3)
43308
- * - DOM Tree Accessors (§3.1.5)
43309
- * - Form Element Parent-Child Relations (§4.10.3)
43310
- * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
43311
- * - HTMLCollection (§4.2.10.2)
43312
- *
43313
- * Namespace isolation is implemented by prefixing `id` and `name` attributes
43314
- * with a constant string, i.e., `user-content-`
43315
- */
43316
- let SANITIZE_NAMED_PROPS = false;
43317
- const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
43318
-
43319
- /* Keep element content when removing element? */
43320
- let KEEP_CONTENT = true;
43321
-
43322
- /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
43323
- * of importing it into a new Document and returning a sanitized copy */
43324
- let IN_PLACE = false;
43325
-
43326
- /* Allow usage of profiles like html, svg and mathMl */
43327
- let USE_PROFILES = {};
43328
-
43329
- /* Tags to ignore content of when KEEP_CONTENT is true */
43330
- let FORBID_CONTENTS = null;
43331
- 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']);
43332
-
43333
- /* Tags that are safe for data: URIs */
43334
- let DATA_URI_TAGS = null;
43335
- const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
43336
-
43337
- /* Attributes safe for values like "javascript:" */
43338
- let URI_SAFE_ATTRIBUTES = null;
43339
- const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
43340
- const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
43341
- const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
43342
- const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
43343
- /* Document namespace */
43344
- let NAMESPACE = HTML_NAMESPACE;
43345
- let IS_EMPTY_INPUT = false;
43346
-
43347
- /* Allowed XHTML+XML namespaces */
43348
- let ALLOWED_NAMESPACES = null;
43349
- const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
43350
-
43351
- /* Parsing of strict XHTML documents */
43352
- let PARSER_MEDIA_TYPE = null;
43353
- const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
43354
- const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
43355
- let transformCaseFunc = null;
43356
-
43357
- /* Keep a reference to config to pass to hooks */
43358
- let CONFIG = null;
43359
-
43360
- /* Ideally, do not touch anything below this line */
43361
- /* ______________________________________________ */
43362
-
43363
- const formElement = document.createElement('form');
43364
- const isRegexOrFunction = function isRegexOrFunction(testValue) {
43365
- return testValue instanceof RegExp || testValue instanceof Function;
43366
- };
43367
-
43368
- /**
43369
- * _parseConfig
43370
- *
43371
- * @param {Object} cfg optional config literal
43372
- */
43373
- // eslint-disable-next-line complexity
43374
- const _parseConfig = function _parseConfig() {
43375
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
43376
- if (CONFIG && CONFIG === cfg) {
43377
- return;
43378
- }
43379
-
43380
- /* Shield configuration object from tampering */
43381
- if (!cfg || typeof cfg !== 'object') {
43382
- cfg = {};
43383
- }
43384
-
43385
- /* Shield configuration object from prototype pollution */
43386
- cfg = clone(cfg);
43387
- PARSER_MEDIA_TYPE =
43388
- // eslint-disable-next-line unicorn/prefer-includes
43389
- SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
43390
-
43391
- // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
43392
- transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
43393
-
43394
- /* Set configuration parameters */
43395
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
43396
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
43397
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
43398
- URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES),
43399
- // eslint-disable-line indent
43400
- cfg.ADD_URI_SAFE_ATTR,
43401
- // eslint-disable-line indent
43402
- transformCaseFunc // eslint-disable-line indent
43403
- ) // eslint-disable-line indent
43404
- : DEFAULT_URI_SAFE_ATTRIBUTES;
43405
- DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS),
43406
- // eslint-disable-line indent
43407
- cfg.ADD_DATA_URI_TAGS,
43408
- // eslint-disable-line indent
43409
- transformCaseFunc // eslint-disable-line indent
43410
- ) // eslint-disable-line indent
43411
- : DEFAULT_DATA_URI_TAGS;
43412
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
43413
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
43414
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
43415
- USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
43416
- ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
43417
- ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
43418
- ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
43419
- ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
43420
- SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
43421
- SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
43422
- WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
43423
- RETURN_DOM = cfg.RETURN_DOM || false; // Default false
43424
- RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
43425
- RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
43426
- FORCE_BODY = cfg.FORCE_BODY || false; // Default false
43427
- SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
43428
- SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
43429
- KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
43430
- IN_PLACE = cfg.IN_PLACE || false; // Default false
43431
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
43432
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
43433
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
43434
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
43435
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
43436
- }
43437
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
43438
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
43439
- }
43440
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
43441
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
43442
- }
43443
- if (SAFE_FOR_TEMPLATES) {
43444
- ALLOW_DATA_ATTR = false;
43445
- }
43446
- if (RETURN_DOM_FRAGMENT) {
43447
- RETURN_DOM = true;
43448
- }
43449
-
43450
- /* Parse profile info */
43451
- if (USE_PROFILES) {
43452
- ALLOWED_TAGS = addToSet({}, text);
43453
- ALLOWED_ATTR = [];
43454
- if (USE_PROFILES.html === true) {
43455
- addToSet(ALLOWED_TAGS, html$1);
43456
- addToSet(ALLOWED_ATTR, html);
43457
- }
43458
- if (USE_PROFILES.svg === true) {
43459
- addToSet(ALLOWED_TAGS, svg$1);
43460
- addToSet(ALLOWED_ATTR, svg);
43461
- addToSet(ALLOWED_ATTR, xml);
43462
- }
43463
- if (USE_PROFILES.svgFilters === true) {
43464
- addToSet(ALLOWED_TAGS, svgFilters);
43465
- addToSet(ALLOWED_ATTR, svg);
43466
- addToSet(ALLOWED_ATTR, xml);
43467
- }
43468
- if (USE_PROFILES.mathMl === true) {
43469
- addToSet(ALLOWED_TAGS, mathMl$1);
43470
- addToSet(ALLOWED_ATTR, mathMl);
43471
- addToSet(ALLOWED_ATTR, xml);
43472
- }
43473
- }
43474
-
43475
- /* Merge configuration parameters */
43476
- if (cfg.ADD_TAGS) {
43477
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
43478
- ALLOWED_TAGS = clone(ALLOWED_TAGS);
43479
- }
43480
- addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
43481
- }
43482
- if (cfg.ADD_ATTR) {
43483
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
43484
- ALLOWED_ATTR = clone(ALLOWED_ATTR);
43485
- }
43486
- addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
43487
- }
43488
- if (cfg.ADD_URI_SAFE_ATTR) {
43489
- addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
43490
- }
43491
- if (cfg.FORBID_CONTENTS) {
43492
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
43493
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
43494
- }
43495
- addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
43496
- }
43497
-
43498
- /* Add #text in case KEEP_CONTENT is set to true */
43499
- if (KEEP_CONTENT) {
43500
- ALLOWED_TAGS['#text'] = true;
43501
- }
43502
-
43503
- /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
43504
- if (WHOLE_DOCUMENT) {
43505
- addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
43506
- }
43507
-
43508
- /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
43509
- if (ALLOWED_TAGS.table) {
43510
- addToSet(ALLOWED_TAGS, ['tbody']);
43511
- delete FORBID_TAGS.tbody;
43512
- }
43513
- if (cfg.TRUSTED_TYPES_POLICY) {
43514
- if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
43515
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
43516
- }
43517
- if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
43518
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
43519
- }
43520
-
43521
- // Overwrite existing TrustedTypes policy.
43522
- trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
43523
-
43524
- // Sign local variables required by `sanitize`.
43525
- emptyHTML = trustedTypesPolicy.createHTML('');
43526
- } else {
43527
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
43528
- if (trustedTypesPolicy === undefined) {
43529
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
43530
- }
43531
-
43532
- // If creating the internal policy succeeded sign internal variables.
43533
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
43534
- emptyHTML = trustedTypesPolicy.createHTML('');
43535
- }
43536
- }
43537
-
43538
- // Prevent further manipulation of configuration.
43539
- // Not available in IE8, Safari 5, etc.
43540
- if (freeze) {
43541
- freeze(cfg);
43542
- }
43543
- CONFIG = cfg;
43544
- };
43545
- const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
43546
- const HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'annotation-xml']);
43547
-
43548
- // Certain elements are allowed in both SVG and HTML
43549
- // namespace. We need to specify them explicitly
43550
- // so that they don't get erroneously deleted from
43551
- // HTML namespace.
43552
- const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
43553
-
43554
- /* Keep track of all possible SVG and MathML tags
43555
- * so that we can perform the namespace checks
43556
- * correctly. */
43557
- const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
43558
- const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
43559
-
43560
- /**
43561
- * @param {Element} element a DOM element whose namespace is being checked
43562
- * @returns {boolean} Return false if the element has a
43563
- * namespace that a spec-compliant parser would never
43564
- * return. Return true otherwise.
43565
- */
43566
- const _checkValidNamespace = function _checkValidNamespace(element) {
43567
- let parent = getParentNode(element);
43568
-
43569
- // In JSDOM, if we're inside shadow DOM, then parentNode
43570
- // can be null. We just simulate parent in this case.
43571
- if (!parent || !parent.tagName) {
43572
- parent = {
43573
- namespaceURI: NAMESPACE,
43574
- tagName: 'template'
43575
- };
43576
- }
43577
- const tagName = stringToLowerCase(element.tagName);
43578
- const parentTagName = stringToLowerCase(parent.tagName);
43579
- if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
43580
- return false;
43581
- }
43582
- if (element.namespaceURI === SVG_NAMESPACE) {
43583
- // The only way to switch from HTML namespace to SVG
43584
- // is via <svg>. If it happens via any other tag, then
43585
- // it should be killed.
43586
- if (parent.namespaceURI === HTML_NAMESPACE) {
43587
- return tagName === 'svg';
43588
- }
43589
-
43590
- // The only way to switch from MathML to SVG is via`
43591
- // svg if parent is either <annotation-xml> or MathML
43592
- // text integration points.
43593
- if (parent.namespaceURI === MATHML_NAMESPACE) {
43594
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
43595
- }
43596
-
43597
- // We only allow elements that are defined in SVG
43598
- // spec. All others are disallowed in SVG namespace.
43599
- return Boolean(ALL_SVG_TAGS[tagName]);
43600
- }
43601
- if (element.namespaceURI === MATHML_NAMESPACE) {
43602
- // The only way to switch from HTML namespace to MathML
43603
- // is via <math>. If it happens via any other tag, then
43604
- // it should be killed.
43605
- if (parent.namespaceURI === HTML_NAMESPACE) {
43606
- return tagName === 'math';
43607
- }
43608
-
43609
- // The only way to switch from SVG to MathML is via
43610
- // <math> and HTML integration points
43611
- if (parent.namespaceURI === SVG_NAMESPACE) {
43612
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
43613
- }
43614
-
43615
- // We only allow elements that are defined in MathML
43616
- // spec. All others are disallowed in MathML namespace.
43617
- return Boolean(ALL_MATHML_TAGS[tagName]);
43618
- }
43619
- if (element.namespaceURI === HTML_NAMESPACE) {
43620
- // The only way to switch from SVG to HTML is via
43621
- // HTML integration points, and from MathML to HTML
43622
- // is via MathML text integration points
43623
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
43624
- return false;
43625
- }
43626
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
43627
- return false;
43628
- }
43629
-
43630
- // We disallow tags that are specific for MathML
43631
- // or SVG and should never appear in HTML namespace
43632
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
43633
- }
43634
-
43635
- // For XHTML and XML documents that support custom namespaces
43636
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
43637
- return true;
43638
- }
43639
-
43640
- // The code should never reach this place (this means
43641
- // that the element somehow got namespace that is not
43642
- // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
43643
- // Return false just in case.
43644
- return false;
43645
- };
43646
-
43647
- /**
43648
- * _forceRemove
43649
- *
43650
- * @param {Node} node a DOM node
43651
- */
43652
- const _forceRemove = function _forceRemove(node) {
43653
- arrayPush(DOMPurify.removed, {
43654
- element: node
43655
- });
43656
- try {
43657
- // eslint-disable-next-line unicorn/prefer-dom-node-remove
43658
- getParentNode(node).removeChild(node);
43659
- } catch (_) {
43660
- remove(node);
43661
- }
43662
- };
43663
-
43664
- /**
43665
- * _removeAttribute
43666
- *
43667
- * @param {String} name an Attribute name
43668
- * @param {Node} node a DOM node
43669
- */
43670
- const _removeAttribute = function _removeAttribute(name, node) {
43671
- try {
43672
- arrayPush(DOMPurify.removed, {
43673
- attribute: node.getAttributeNode(name),
43674
- from: node
43675
- });
43676
- } catch (_) {
43677
- arrayPush(DOMPurify.removed, {
43678
- attribute: null,
43679
- from: node
43680
- });
43681
- }
43682
- node.removeAttribute(name);
43683
-
43684
- // We void attribute values for unremovable "is"" attributes
43685
- if (name === 'is' && !ALLOWED_ATTR[name]) {
43686
- if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
43687
- try {
43688
- _forceRemove(node);
43689
- } catch (_) {}
43690
- } else {
43691
- try {
43692
- node.setAttribute(name, '');
43693
- } catch (_) {}
43694
- }
43695
- }
43696
- };
43697
-
43698
- /**
43699
- * _initDocument
43700
- *
43701
- * @param {String} dirty a string of dirty markup
43702
- * @return {Document} a DOM, filled with the dirty markup
43703
- */
43704
- const _initDocument = function _initDocument(dirty) {
43705
- /* Create a HTML document */
43706
- let doc = null;
43707
- let leadingWhitespace = null;
43708
- if (FORCE_BODY) {
43709
- dirty = '<remove></remove>' + dirty;
43710
- } else {
43711
- /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
43712
- const matches = stringMatch(dirty, /^[\r\n\t ]+/);
43713
- leadingWhitespace = matches && matches[0];
43714
- }
43715
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
43716
- // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
43717
- dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
43718
- }
43719
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
43720
- /*
43721
- * Use the DOMParser API by default, fallback later if needs be
43722
- * DOMParser not work for svg when has multiple root element.
43723
- */
43724
- if (NAMESPACE === HTML_NAMESPACE) {
43725
- try {
43726
- doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
43727
- } catch (_) {}
43728
- }
43729
-
43730
- /* Use createHTMLDocument in case DOMParser is not available */
43731
- if (!doc || !doc.documentElement) {
43732
- doc = implementation.createDocument(NAMESPACE, 'template', null);
43733
- try {
43734
- doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
43735
- } catch (_) {
43736
- // Syntax error if dirtyPayload is invalid xml
43737
- }
43738
- }
43739
- const body = doc.body || doc.documentElement;
43740
- if (dirty && leadingWhitespace) {
43741
- body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
43742
- }
43743
-
43744
- /* Work on whole document or just its body */
43745
- if (NAMESPACE === HTML_NAMESPACE) {
43746
- return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
43747
- }
43748
- return WHOLE_DOCUMENT ? doc.documentElement : body;
43749
- };
43750
-
43751
- /**
43752
- * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
43753
- *
43754
- * @param {Node} root The root element or node to start traversing on.
43755
- * @return {NodeIterator} The created NodeIterator
43756
- */
43757
- const _createNodeIterator = function _createNodeIterator(root) {
43758
- return createNodeIterator.call(root.ownerDocument || root, root,
43759
- // eslint-disable-next-line no-bitwise
43760
- NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
43761
- };
43762
-
43763
- /**
43764
- * _isClobbered
43765
- *
43766
- * @param {Node} elm element to check for clobbering attacks
43767
- * @return {Boolean} true if clobbered, false if safe
43768
- */
43769
- const _isClobbered = function _isClobbered(elm) {
43770
- return elm instanceof HTMLFormElement && (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function' || typeof elm.hasChildNodes !== 'function');
43771
- };
43772
-
43773
- /**
43774
- * Checks whether the given object is a DOM node.
43775
- *
43776
- * @param {Node} object object to check whether it's a DOM node
43777
- * @return {Boolean} true is object is a DOM node
43778
- */
43779
- const _isNode = function _isNode(object) {
43780
- return typeof Node === 'function' && object instanceof Node;
43781
- };
43782
-
43783
- /**
43784
- * _executeHook
43785
- * Execute user configurable hooks
43786
- *
43787
- * @param {String} entryPoint Name of the hook's entry point
43788
- * @param {Node} currentNode node to work on with the hook
43789
- * @param {Object} data additional hook parameters
43790
- */
43791
- const _executeHook = function _executeHook(entryPoint, currentNode, data) {
43792
- if (!hooks[entryPoint]) {
43793
- return;
43794
- }
43795
- arrayForEach(hooks[entryPoint], hook => {
43796
- hook.call(DOMPurify, currentNode, data, CONFIG);
43797
- });
43798
- };
43799
-
43800
- /**
43801
- * _sanitizeElements
43802
- *
43803
- * @protect nodeName
43804
- * @protect textContent
43805
- * @protect removeChild
43806
- *
43807
- * @param {Node} currentNode to check for permission to exist
43808
- * @return {Boolean} true if node was killed, false if left alive
43809
- */
43810
- const _sanitizeElements = function _sanitizeElements(currentNode) {
43811
- let content = null;
43812
-
43813
- /* Execute a hook if present */
43814
- _executeHook('beforeSanitizeElements', currentNode, null);
43815
-
43816
- /* Check if element is clobbered or can clobber */
43817
- if (_isClobbered(currentNode)) {
43818
- _forceRemove(currentNode);
43819
- return true;
43820
- }
43821
-
43822
- /* Now let's check the element's type and name */
43823
- const tagName = transformCaseFunc(currentNode.nodeName);
43824
-
43825
- /* Execute a hook if present */
43826
- _executeHook('uponSanitizeElement', currentNode, {
43827
- tagName,
43828
- allowedTags: ALLOWED_TAGS
43829
- });
43830
-
43831
- /* Detect mXSS attempts abusing namespace confusion */
43832
- if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
43833
- _forceRemove(currentNode);
43834
- return true;
43835
- }
43836
-
43837
- /* Remove any occurrence of processing instructions */
43838
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
43839
- _forceRemove(currentNode);
43840
- return true;
43841
- }
43842
-
43843
- /* Remove any kind of possibly harmful comments */
43844
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
43845
- _forceRemove(currentNode);
43846
- return true;
43847
- }
43848
-
43849
- /* Remove element if anything forbids its presence */
43850
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
43851
- /* Check if we have a custom element to handle */
43852
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
43853
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
43854
- return false;
43855
- }
43856
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
43857
- return false;
43858
- }
43859
- }
43860
-
43861
- /* Keep content except for bad-listed elements */
43862
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
43863
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
43864
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
43865
- if (childNodes && parentNode) {
43866
- const childCount = childNodes.length;
43867
- for (let i = childCount - 1; i >= 0; --i) {
43868
- const childClone = cloneNode(childNodes[i], true);
43869
- childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
43870
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
43871
- }
43872
- }
43873
- }
43874
- _forceRemove(currentNode);
43875
- return true;
43876
- }
43877
-
43878
- /* Check whether element has a valid namespace */
43879
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
43880
- _forceRemove(currentNode);
43881
- return true;
43882
- }
43883
-
43884
- /* Make sure that older browsers don't get fallback-tag mXSS */
43885
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
43886
- _forceRemove(currentNode);
43887
- return true;
43888
- }
43889
-
43890
- /* Sanitize element content to be template-safe */
43891
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
43892
- /* Get the element's text content */
43893
- content = currentNode.textContent;
43894
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
43895
- content = stringReplace(content, expr, ' ');
43896
- });
43897
- if (currentNode.textContent !== content) {
43898
- arrayPush(DOMPurify.removed, {
43899
- element: currentNode.cloneNode()
43900
- });
43901
- currentNode.textContent = content;
43902
- }
43903
- }
43904
-
43905
- /* Execute a hook if present */
43906
- _executeHook('afterSanitizeElements', currentNode, null);
43907
- return false;
43908
- };
43909
-
43910
- /**
43911
- * _isValidAttribute
43912
- *
43913
- * @param {string} lcTag Lowercase tag name of containing element.
43914
- * @param {string} lcName Lowercase attribute name.
43915
- * @param {string} value Attribute value.
43916
- * @return {Boolean} Returns true if `value` is valid, otherwise false.
43917
- */
43918
- // eslint-disable-next-line complexity
43919
- const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
43920
- /* Make sure attribute cannot clobber */
43921
- if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
43922
- return false;
43923
- }
43924
-
43925
- /* Allow valid data-* attributes: At least one character after "-"
43926
- (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
43927
- XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
43928
- We don't need to check the value; it's always URI safe. */
43929
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
43930
- if (
43931
- // First condition does a very basic check if a) it's basically a valid custom element tagname AND
43932
- // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
43933
- // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
43934
- _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)) ||
43935
- // Alternative, second condition checks if it's an `is`-attribute, AND
43936
- // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
43937
- 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 {
43938
- return false;
43939
- }
43940
- /* Check value is safe. First, is attr inert? If so, is safe */
43941
- } 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) {
43942
- return false;
43943
- } else ;
43944
- return true;
43945
- };
43946
-
43947
- /**
43948
- * _isBasicCustomElement
43949
- * checks if at least one dash is included in tagName, and it's not the first char
43950
- * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
43951
- *
43952
- * @param {string} tagName name of the tag of the node to sanitize
43953
- * @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
43954
- */
43955
- const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
43956
- return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
43957
- };
43958
-
43959
- /**
43960
- * _sanitizeAttributes
43961
- *
43962
- * @protect attributes
43963
- * @protect nodeName
43964
- * @protect removeAttribute
43965
- * @protect setAttribute
43966
- *
43967
- * @param {Node} currentNode to sanitize
43968
- */
43969
- const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
43970
- /* Execute a hook if present */
43971
- _executeHook('beforeSanitizeAttributes', currentNode, null);
43972
- const {
43973
- attributes
43974
- } = currentNode;
43975
-
43976
- /* Check if we have attributes; if not we might have a text node */
43977
- if (!attributes) {
43978
- return;
43979
- }
43980
- const hookEvent = {
43981
- attrName: '',
43982
- attrValue: '',
43983
- keepAttr: true,
43984
- allowedAttributes: ALLOWED_ATTR
43985
- };
43986
- let l = attributes.length;
43987
-
43988
- /* Go backwards over all attributes; safely remove bad ones */
43989
- while (l--) {
43990
- const attr = attributes[l];
43991
- const {
43992
- name,
43993
- namespaceURI,
43994
- value: attrValue
43995
- } = attr;
43996
- const lcName = transformCaseFunc(name);
43997
- let value = name === 'value' ? attrValue : stringTrim(attrValue);
43998
-
43999
- /* Execute a hook if present */
44000
- hookEvent.attrName = lcName;
44001
- hookEvent.attrValue = value;
44002
- hookEvent.keepAttr = true;
44003
- hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
44004
- _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
44005
- value = hookEvent.attrValue;
44006
-
44007
- /* Work around a security issue with comments inside attributes */
44008
- if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
44009
- _removeAttribute(name, currentNode);
44010
- continue;
44011
- }
44012
-
44013
- /* Did the hooks approve of the attribute? */
44014
- if (hookEvent.forceKeepAttr) {
44015
- continue;
44016
- }
44017
-
44018
- /* Remove attribute */
44019
- _removeAttribute(name, currentNode);
44020
-
44021
- /* Did the hooks approve of the attribute? */
44022
- if (!hookEvent.keepAttr) {
44023
- continue;
44024
- }
44025
-
44026
- /* Work around a security issue in jQuery 3.0 */
44027
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
44028
- _removeAttribute(name, currentNode);
44029
- continue;
44030
- }
44031
-
44032
- /* Sanitize attribute content to be template-safe */
44033
- if (SAFE_FOR_TEMPLATES) {
44034
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
44035
- value = stringReplace(value, expr, ' ');
44036
- });
44037
- }
44038
-
44039
- /* Is `value` valid for this attribute? */
44040
- const lcTag = transformCaseFunc(currentNode.nodeName);
44041
- if (!_isValidAttribute(lcTag, lcName, value)) {
44042
- continue;
44043
- }
44044
-
44045
- /* Full DOM Clobbering protection via namespace isolation,
44046
- * Prefix id and name attributes with `user-content-`
44047
- */
44048
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
44049
- // Remove the attribute with this value
44050
- _removeAttribute(name, currentNode);
44051
-
44052
- // Prefix the value and later re-create the attribute with the sanitized value
44053
- value = SANITIZE_NAMED_PROPS_PREFIX + value;
44054
- }
44055
-
44056
- /* Handle attributes that require Trusted Types */
44057
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
44058
- if (namespaceURI) ; else {
44059
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
44060
- case 'TrustedHTML':
44061
- {
44062
- value = trustedTypesPolicy.createHTML(value);
44063
- break;
44064
- }
44065
- case 'TrustedScriptURL':
44066
- {
44067
- value = trustedTypesPolicy.createScriptURL(value);
44068
- break;
44069
- }
44070
- }
44071
- }
44072
- }
44073
-
44074
- /* Handle invalid data-* attribute set by try-catching it */
44075
- try {
44076
- if (namespaceURI) {
44077
- currentNode.setAttributeNS(namespaceURI, name, value);
44078
- } else {
44079
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
44080
- currentNode.setAttribute(name, value);
44081
- }
44082
- if (_isClobbered(currentNode)) {
44083
- _forceRemove(currentNode);
44084
- } else {
44085
- arrayPop(DOMPurify.removed);
44086
- }
44087
- } catch (_) {}
44088
- }
44089
-
44090
- /* Execute a hook if present */
44091
- _executeHook('afterSanitizeAttributes', currentNode, null);
44092
- };
44093
-
44094
- /**
44095
- * _sanitizeShadowDOM
44096
- *
44097
- * @param {DocumentFragment} fragment to iterate over recursively
44098
- */
44099
- const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
44100
- let shadowNode = null;
44101
- const shadowIterator = _createNodeIterator(fragment);
44102
-
44103
- /* Execute a hook if present */
44104
- _executeHook('beforeSanitizeShadowDOM', fragment, null);
44105
- while (shadowNode = shadowIterator.nextNode()) {
44106
- /* Execute a hook if present */
44107
- _executeHook('uponSanitizeShadowNode', shadowNode, null);
44108
-
44109
- /* Sanitize tags and elements */
44110
- if (_sanitizeElements(shadowNode)) {
44111
- continue;
44112
- }
44113
-
44114
- /* Deep shadow DOM detected */
44115
- if (shadowNode.content instanceof DocumentFragment) {
44116
- _sanitizeShadowDOM(shadowNode.content);
44117
- }
44118
-
44119
- /* Check attributes, sanitize if necessary */
44120
- _sanitizeAttributes(shadowNode);
44121
- }
44122
-
44123
- /* Execute a hook if present */
44124
- _executeHook('afterSanitizeShadowDOM', fragment, null);
44125
- };
44126
-
44127
- /**
44128
- * Sanitize
44129
- * Public method providing core sanitation functionality
44130
- *
44131
- * @param {String|Node} dirty string or DOM node
44132
- * @param {Object} cfg object
44133
- */
44134
- // eslint-disable-next-line complexity
44135
- DOMPurify.sanitize = function (dirty) {
44136
- let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
44137
- let body = null;
44138
- let importedNode = null;
44139
- let currentNode = null;
44140
- let returnNode = null;
44141
- /* Make sure we have a string to sanitize.
44142
- DO NOT return early, as this will return the wrong type if
44143
- the user has requested a DOM object rather than a string */
44144
- IS_EMPTY_INPUT = !dirty;
44145
- if (IS_EMPTY_INPUT) {
44146
- dirty = '<!-->';
44147
- }
44148
-
44149
- /* Stringify, in case dirty is an object */
44150
- if (typeof dirty !== 'string' && !_isNode(dirty)) {
44151
- if (typeof dirty.toString === 'function') {
44152
- dirty = dirty.toString();
44153
- if (typeof dirty !== 'string') {
44154
- throw typeErrorCreate('dirty is not a string, aborting');
44155
- }
44156
- } else {
44157
- throw typeErrorCreate('toString is not a function');
44158
- }
44159
- }
44160
-
44161
- /* Return dirty HTML if DOMPurify cannot run */
44162
- if (!DOMPurify.isSupported) {
44163
- return dirty;
44164
- }
44165
-
44166
- /* Assign config vars */
44167
- if (!SET_CONFIG) {
44168
- _parseConfig(cfg);
44169
- }
44170
-
44171
- /* Clean up removed elements */
44172
- DOMPurify.removed = [];
44173
-
44174
- /* Check if dirty is correctly typed for IN_PLACE */
44175
- if (typeof dirty === 'string') {
44176
- IN_PLACE = false;
44177
- }
44178
- if (IN_PLACE) {
44179
- /* Do some early pre-sanitization to avoid unsafe root nodes */
44180
- if (dirty.nodeName) {
44181
- const tagName = transformCaseFunc(dirty.nodeName);
44182
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
44183
- throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
44184
- }
44185
- }
44186
- } else if (dirty instanceof Node) {
44187
- /* If dirty is a DOM element, append to an empty document to avoid
44188
- elements being stripped by the parser */
44189
- body = _initDocument('<!---->');
44190
- importedNode = body.ownerDocument.importNode(dirty, true);
44191
- if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
44192
- /* Node is already a body, use as is */
44193
- body = importedNode;
44194
- } else if (importedNode.nodeName === 'HTML') {
44195
- body = importedNode;
44196
- } else {
44197
- // eslint-disable-next-line unicorn/prefer-dom-node-append
44198
- body.appendChild(importedNode);
44199
- }
44200
- } else {
44201
- /* Exit directly if we have nothing to do */
44202
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
44203
- // eslint-disable-next-line unicorn/prefer-includes
44204
- dirty.indexOf('<') === -1) {
44205
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
44206
- }
44207
-
44208
- /* Initialize the document to work on */
44209
- body = _initDocument(dirty);
44210
-
44211
- /* Check we have a DOM node from the data */
44212
- if (!body) {
44213
- return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
44214
- }
44215
- }
44216
-
44217
- /* Remove first element node (ours) if FORCE_BODY is set */
44218
- if (body && FORCE_BODY) {
44219
- _forceRemove(body.firstChild);
44220
- }
44221
-
44222
- /* Get node iterator */
44223
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
44224
-
44225
- /* Now start iterating over the created document */
44226
- while (currentNode = nodeIterator.nextNode()) {
44227
- /* Sanitize tags and elements */
44228
- if (_sanitizeElements(currentNode)) {
44229
- continue;
44230
- }
44231
-
44232
- /* Shadow DOM detected, sanitize it */
44233
- if (currentNode.content instanceof DocumentFragment) {
44234
- _sanitizeShadowDOM(currentNode.content);
44235
- }
44236
-
44237
- /* Check attributes, sanitize if necessary */
44238
- _sanitizeAttributes(currentNode);
44239
- }
44240
-
44241
- /* If we sanitized `dirty` in-place, return it. */
44242
- if (IN_PLACE) {
44243
- return dirty;
44244
- }
44245
-
44246
- /* Return sanitized string or DOM */
44247
- if (RETURN_DOM) {
44248
- if (RETURN_DOM_FRAGMENT) {
44249
- returnNode = createDocumentFragment.call(body.ownerDocument);
44250
- while (body.firstChild) {
44251
- // eslint-disable-next-line unicorn/prefer-dom-node-append
44252
- returnNode.appendChild(body.firstChild);
44253
- }
44254
- } else {
44255
- returnNode = body;
44256
- }
44257
- if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
44258
- /*
44259
- AdoptNode() is not used because internal state is not reset
44260
- (e.g. the past names map of a HTMLFormElement), this is safe
44261
- in theory but we would rather not risk another attack vector.
44262
- The state that is cloned by importNode() is explicitly defined
44263
- by the specs.
44264
- */
44265
- returnNode = importNode.call(originalDocument, returnNode, true);
44266
- }
44267
- return returnNode;
44268
- }
44269
- let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
44270
-
44271
- /* Serialize doctype if allowed */
44272
- if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
44273
- serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
44274
- }
44275
-
44276
- /* Sanitize final string template-safe */
44277
- if (SAFE_FOR_TEMPLATES) {
44278
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
44279
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
44280
- });
44281
- }
44282
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
44283
- };
44284
-
44285
- /**
44286
- * Public method to set the configuration once
44287
- * setConfig
44288
- *
44289
- * @param {Object} cfg configuration object
44290
- */
44291
- DOMPurify.setConfig = function () {
44292
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
44293
- _parseConfig(cfg);
44294
- SET_CONFIG = true;
44295
- };
44296
-
44297
- /**
44298
- * Public method to remove the configuration
44299
- * clearConfig
44300
- *
44301
- */
44302
- DOMPurify.clearConfig = function () {
44303
- CONFIG = null;
44304
- SET_CONFIG = false;
44305
- };
44306
-
44307
- /**
44308
- * Public method to check if an attribute value is valid.
44309
- * Uses last set config, if any. Otherwise, uses config defaults.
44310
- * isValidAttribute
44311
- *
44312
- * @param {String} tag Tag name of containing element.
44313
- * @param {String} attr Attribute name.
44314
- * @param {String} value Attribute value.
44315
- * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
44316
- */
44317
- DOMPurify.isValidAttribute = function (tag, attr, value) {
44318
- /* Initialize shared config vars if necessary. */
44319
- if (!CONFIG) {
44320
- _parseConfig({});
44321
- }
44322
- const lcTag = transformCaseFunc(tag);
44323
- const lcName = transformCaseFunc(attr);
44324
- return _isValidAttribute(lcTag, lcName, value);
44325
- };
44326
-
44327
- /**
44328
- * AddHook
44329
- * Public method to add DOMPurify hooks
44330
- *
44331
- * @param {String} entryPoint entry point for the hook to add
44332
- * @param {Function} hookFunction function to execute
44333
- */
44334
- DOMPurify.addHook = function (entryPoint, hookFunction) {
44335
- if (typeof hookFunction !== 'function') {
44336
- return;
44337
- }
44338
- hooks[entryPoint] = hooks[entryPoint] || [];
44339
- arrayPush(hooks[entryPoint], hookFunction);
44340
- };
44341
-
44342
- /**
44343
- * RemoveHook
44344
- * Public method to remove a DOMPurify hook at a given entryPoint
44345
- * (pops it from the stack of hooks if more are present)
44346
- *
44347
- * @param {String} entryPoint entry point for the hook to remove
44348
- * @return {Function} removed(popped) hook
44349
- */
44350
- DOMPurify.removeHook = function (entryPoint) {
44351
- if (hooks[entryPoint]) {
44352
- return arrayPop(hooks[entryPoint]);
44353
- }
44354
- };
44355
-
44356
- /**
44357
- * RemoveHooks
44358
- * Public method to remove all DOMPurify hooks at a given entryPoint
44359
- *
44360
- * @param {String} entryPoint entry point for the hooks to remove
44361
- */
44362
- DOMPurify.removeHooks = function (entryPoint) {
44363
- if (hooks[entryPoint]) {
44364
- hooks[entryPoint] = [];
44365
- }
44366
- };
44367
-
44368
- /**
44369
- * RemoveAllHooks
44370
- * Public method to remove all DOMPurify hooks
44371
- */
44372
- DOMPurify.removeAllHooks = function () {
44373
- hooks = {};
44374
- };
44375
- return DOMPurify;
44376
- }
44377
- var purify = createDOMPurify();
44378
-
44379
- return purify;
42826
+ (function(global, factory) {
42827
+ module.exports = factory() ;
42828
+ })(commonjsGlobal, function() {
42829
+ function _arrayLikeToArray(r, a) {
42830
+ (null == a || a > r.length) && (a = r.length);
42831
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
42832
+ return n;
42833
+ }
42834
+ function _arrayWithHoles(r) {
42835
+ if (Array.isArray(r)) return r;
42836
+ }
42837
+ function _iterableToArrayLimit(r, l) {
42838
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
42839
+ if (null != t) {
42840
+ var e, n, i, u, a = [], f = !0, o = !1;
42841
+ try {
42842
+ if (i = (t = t.call(r)).next, 0 === l) {
42843
+ if (Object(t) !== t) return;
42844
+ f = !1;
42845
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
42846
+ } catch (r) {
42847
+ o = !0, n = r;
42848
+ } finally {
42849
+ try {
42850
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
42851
+ } finally {
42852
+ if (o) throw n;
42853
+ }
42854
+ }
42855
+ return a;
42856
+ }
42857
+ }
42858
+ function _nonIterableRest() {
42859
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
42860
+ }
42861
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
42862
+ function _slicedToArray(r, e) {
42863
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
42864
+ }
42865
+ function _unsupportedIterableToArray(r, a) {
42866
+ if (r) {
42867
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
42868
+ var t = {}.toString.call(r).slice(8, -1);
42869
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
42870
+ }
42871
+ }
42872
+ const entries = Object.entries;
42873
+ const setPrototypeOf = Object.setPrototypeOf;
42874
+ const isFrozen = Object.isFrozen;
42875
+ const getPrototypeOf = Object.getPrototypeOf;
42876
+ const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
42877
+ let freeze = Object.freeze;
42878
+ let seal = Object.seal;
42879
+ let create = Object.create;
42880
+ let _ref = typeof Reflect !== "undefined" && Reflect;
42881
+ let apply = _ref.apply;
42882
+ let construct = _ref.construct;
42883
+ if (!freeze) freeze = function freeze(x) {
42884
+ return x;
42885
+ };
42886
+ if (!seal) seal = function seal(x) {
42887
+ return x;
42888
+ };
42889
+ if (!apply) apply = function apply(func, thisArg) {
42890
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) args[_key - 2] = arguments[_key];
42891
+ return func.apply(thisArg, args);
42892
+ };
42893
+ if (!construct) construct = function construct(Func) {
42894
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) args[_key2 - 1] = arguments[_key2];
42895
+ return new Func(...args);
42896
+ };
42897
+ const arrayForEach = unapply(Array.prototype.forEach);
42898
+ const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
42899
+ const arrayPop = unapply(Array.prototype.pop);
42900
+ const arrayPush = unapply(Array.prototype.push);
42901
+ const arraySlice = unapply(Array.prototype.slice);
42902
+ const arraySplice = unapply(Array.prototype.splice);
42903
+ const arrayIsArray = Array.isArray;
42904
+ const setCreate = unconstruct(Set);
42905
+ const setAdd = unapply(Set.prototype.add);
42906
+ const setHas = unapply(Set.prototype.has);
42907
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
42908
+ const stringToString = unapply(String.prototype.toString);
42909
+ const stringMatch = unapply(String.prototype.match);
42910
+ const stringReplace = unapply(String.prototype.replace);
42911
+ const stringIndexOf = unapply(String.prototype.indexOf);
42912
+ const stringTrim = unapply(String.prototype.trim);
42913
+ const numberToString = unapply(Number.prototype.toString);
42914
+ const booleanToString = unapply(Boolean.prototype.toString);
42915
+ const bigintToString = typeof BigInt === "undefined" ? null : unapply(BigInt.prototype.toString);
42916
+ const symbolToString = typeof Symbol === "undefined" ? null : unapply(Symbol.prototype.toString);
42917
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
42918
+ const objectToString = unapply(Object.prototype.toString);
42919
+ const regExpTest = unapply(RegExp.prototype.test);
42920
+ const typeErrorCreate = unconstruct(TypeError);
42921
+ /**
42922
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
42923
+ *
42924
+ * @param func - The function to be wrapped and called.
42925
+ * @returns A new function that calls the given function with a specified thisArg and arguments.
42926
+ */
42927
+ function unapply(func) {
42928
+ return function(thisArg) {
42929
+ if (thisArg instanceof RegExp) thisArg.lastIndex = 0;
42930
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) args[_key3 - 1] = arguments[_key3];
42931
+ return apply(func, thisArg, args);
42932
+ };
42933
+ }
42934
+ /**
42935
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
42936
+ *
42937
+ * @param func - The constructor function to be wrapped and called.
42938
+ * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
42939
+ */
42940
+ function unconstruct(Func) {
42941
+ return function() {
42942
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) args[_key4] = arguments[_key4];
42943
+ return construct(Func, args);
42944
+ };
42945
+ }
42946
+ /**
42947
+ * Add properties to a lookup table
42948
+ *
42949
+ * @param set - The set to which elements will be added.
42950
+ * @param array - The array containing elements to be added to the set.
42951
+ * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
42952
+ * @returns The modified set with added elements.
42953
+ */
42954
+ function addToSet(set, array) {
42955
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
42956
+ if (setPrototypeOf) setPrototypeOf(set, null);
42957
+ if (!arrayIsArray(array)) return set;
42958
+ let l = array.length;
42959
+ while (l--) {
42960
+ let element = array[l];
42961
+ if (typeof element === "string") {
42962
+ const lcElement = transformCaseFunc(element);
42963
+ if (lcElement !== element) {
42964
+ if (!isFrozen(array)) array[l] = lcElement;
42965
+ element = lcElement;
42966
+ }
42967
+ }
42968
+ set[element] = true;
42969
+ }
42970
+ return set;
42971
+ }
42972
+ /**
42973
+ * Clean up an array to harden against CSPP
42974
+ *
42975
+ * @param array - The array to be cleaned.
42976
+ * @returns The cleaned version of the array
42977
+ */
42978
+ function cleanArray(array) {
42979
+ for (let index = 0; index < array.length; index++) if (!objectHasOwnProperty(array, index)) array[index] = null;
42980
+ return array;
42981
+ }
42982
+ /**
42983
+ * Shallow clone an object
42984
+ *
42985
+ * @param object - The object to be cloned.
42986
+ * @returns A new object that copies the original.
42987
+ */
42988
+ function clone(object) {
42989
+ const newObject = create(null);
42990
+ for (const _ref2 of entries(object)) {
42991
+ var _ref3 = _slicedToArray(_ref2, 2);
42992
+ const property = _ref3[0];
42993
+ const value = _ref3[1];
42994
+ if (objectHasOwnProperty(object, property)) {
42995
+ if (arrayIsArray(value)) newObject[property] = cleanArray(value);
42996
+ else if (value && typeof value === "object" && value.constructor === Object) newObject[property] = clone(value);
42997
+ else newObject[property] = value;
42998
+ }
42999
+ }
43000
+ return newObject;
43001
+ }
43002
+ /**
43003
+ * Convert non-node values into strings without depending on direct property access.
43004
+ *
43005
+ * @param value - The value to stringify.
43006
+ * @returns A string representation of the provided value.
43007
+ */
43008
+ function stringifyValue(value) {
43009
+ switch (typeof value) {
43010
+ case "string": return value;
43011
+ case "number": return numberToString(value);
43012
+ case "boolean": return booleanToString(value);
43013
+ case "bigint": return bigintToString ? bigintToString(value) : "0";
43014
+ case "symbol": return symbolToString ? symbolToString(value) : "Symbol()";
43015
+ case "undefined": return objectToString(value);
43016
+ case "function":
43017
+ case "object": {
43018
+ if (value === null) return objectToString(value);
43019
+ const valueAsRecord = value;
43020
+ const valueToString = lookupGetter(valueAsRecord, "toString");
43021
+ if (typeof valueToString === "function") {
43022
+ const stringified = valueToString(valueAsRecord);
43023
+ return typeof stringified === "string" ? stringified : objectToString(stringified);
43024
+ }
43025
+ return objectToString(value);
43026
+ }
43027
+ default: return objectToString(value);
43028
+ }
43029
+ }
43030
+ /**
43031
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
43032
+ *
43033
+ * @param object - The object to look up the getter function in its prototype chain.
43034
+ * @param prop - The property name for which to find the getter function.
43035
+ * @returns The getter function found in the prototype chain or a fallback function.
43036
+ */
43037
+ function lookupGetter(object, prop) {
43038
+ while (object !== null) {
43039
+ const desc = getOwnPropertyDescriptor(object, prop);
43040
+ if (desc) {
43041
+ if (desc.get) return unapply(desc.get);
43042
+ if (typeof desc.value === "function") return unapply(desc.value);
43043
+ }
43044
+ object = getPrototypeOf(object);
43045
+ }
43046
+ function fallbackValue() {
43047
+ return null;
43048
+ }
43049
+ return fallbackValue;
43050
+ }
43051
+ /**
43052
+ * Like lookupGetter, but for accessor properties only, and returns null
43053
+ * instead of a null-returning fallback when no getter exists on the chain.
43054
+ * Lets a caller fall back to a direct property read in environments that
43055
+ * lack the getter, where a fallback returning null would be indistinguishable
43056
+ * from a legitimate null value (e.g. namespaceURI of a no-namespace element).
43057
+ *
43058
+ * @param object - The object (usually a prototype) to start the lookup at.
43059
+ * @param prop - The accessor property name.
43060
+ * @returns The unapplied getter, or null if none was found.
43061
+ */
43062
+ function lookupAccessor(object, prop) {
43063
+ while (object !== null) {
43064
+ const desc = getOwnPropertyDescriptor(object, prop);
43065
+ if (desc) return desc.get ? unapply(desc.get) : null;
43066
+ object = getPrototypeOf(object);
43067
+ }
43068
+ return null;
43069
+ }
43070
+ function isRegex(value) {
43071
+ try {
43072
+ regExpTest(value, "");
43073
+ return true;
43074
+ } catch (_unused) {
43075
+ return false;
43076
+ }
43077
+ }
43078
+ const html$1 = freeze([
43079
+ "a",
43080
+ "abbr",
43081
+ "acronym",
43082
+ "address",
43083
+ "area",
43084
+ "article",
43085
+ "aside",
43086
+ "audio",
43087
+ "b",
43088
+ "bdi",
43089
+ "bdo",
43090
+ "big",
43091
+ "blink",
43092
+ "blockquote",
43093
+ "body",
43094
+ "br",
43095
+ "button",
43096
+ "canvas",
43097
+ "caption",
43098
+ "center",
43099
+ "cite",
43100
+ "code",
43101
+ "col",
43102
+ "colgroup",
43103
+ "content",
43104
+ "data",
43105
+ "datalist",
43106
+ "dd",
43107
+ "decorator",
43108
+ "del",
43109
+ "details",
43110
+ "dfn",
43111
+ "dialog",
43112
+ "dir",
43113
+ "div",
43114
+ "dl",
43115
+ "dt",
43116
+ "element",
43117
+ "em",
43118
+ "fieldset",
43119
+ "figcaption",
43120
+ "figure",
43121
+ "font",
43122
+ "footer",
43123
+ "form",
43124
+ "h1",
43125
+ "h2",
43126
+ "h3",
43127
+ "h4",
43128
+ "h5",
43129
+ "h6",
43130
+ "head",
43131
+ "header",
43132
+ "hgroup",
43133
+ "hr",
43134
+ "html",
43135
+ "i",
43136
+ "img",
43137
+ "input",
43138
+ "ins",
43139
+ "kbd",
43140
+ "label",
43141
+ "legend",
43142
+ "li",
43143
+ "main",
43144
+ "map",
43145
+ "mark",
43146
+ "marquee",
43147
+ "menu",
43148
+ "menuitem",
43149
+ "meter",
43150
+ "nav",
43151
+ "nobr",
43152
+ "ol",
43153
+ "optgroup",
43154
+ "option",
43155
+ "output",
43156
+ "p",
43157
+ "picture",
43158
+ "pre",
43159
+ "progress",
43160
+ "q",
43161
+ "rp",
43162
+ "rt",
43163
+ "ruby",
43164
+ "s",
43165
+ "samp",
43166
+ "search",
43167
+ "section",
43168
+ "select",
43169
+ "shadow",
43170
+ "slot",
43171
+ "small",
43172
+ "source",
43173
+ "spacer",
43174
+ "span",
43175
+ "strike",
43176
+ "strong",
43177
+ "style",
43178
+ "sub",
43179
+ "summary",
43180
+ "sup",
43181
+ "table",
43182
+ "tbody",
43183
+ "td",
43184
+ "template",
43185
+ "textarea",
43186
+ "tfoot",
43187
+ "th",
43188
+ "thead",
43189
+ "time",
43190
+ "tr",
43191
+ "track",
43192
+ "tt",
43193
+ "u",
43194
+ "ul",
43195
+ "var",
43196
+ "video",
43197
+ "wbr"
43198
+ ]);
43199
+ const svg$1 = freeze([
43200
+ "svg",
43201
+ "a",
43202
+ "altglyph",
43203
+ "altglyphdef",
43204
+ "altglyphitem",
43205
+ "animatecolor",
43206
+ "animatemotion",
43207
+ "animatetransform",
43208
+ "circle",
43209
+ "clippath",
43210
+ "defs",
43211
+ "desc",
43212
+ "ellipse",
43213
+ "enterkeyhint",
43214
+ "exportparts",
43215
+ "filter",
43216
+ "font",
43217
+ "g",
43218
+ "glyph",
43219
+ "glyphref",
43220
+ "hkern",
43221
+ "image",
43222
+ "inputmode",
43223
+ "line",
43224
+ "lineargradient",
43225
+ "marker",
43226
+ "mask",
43227
+ "metadata",
43228
+ "mpath",
43229
+ "part",
43230
+ "path",
43231
+ "pattern",
43232
+ "polygon",
43233
+ "polyline",
43234
+ "radialgradient",
43235
+ "rect",
43236
+ "stop",
43237
+ "style",
43238
+ "switch",
43239
+ "symbol",
43240
+ "text",
43241
+ "textpath",
43242
+ "title",
43243
+ "tref",
43244
+ "tspan",
43245
+ "view",
43246
+ "vkern"
43247
+ ]);
43248
+ const svgFilters = freeze([
43249
+ "feBlend",
43250
+ "feColorMatrix",
43251
+ "feComponentTransfer",
43252
+ "feComposite",
43253
+ "feConvolveMatrix",
43254
+ "feDiffuseLighting",
43255
+ "feDisplacementMap",
43256
+ "feDistantLight",
43257
+ "feDropShadow",
43258
+ "feFlood",
43259
+ "feFuncA",
43260
+ "feFuncB",
43261
+ "feFuncG",
43262
+ "feFuncR",
43263
+ "feGaussianBlur",
43264
+ "feImage",
43265
+ "feMerge",
43266
+ "feMergeNode",
43267
+ "feMorphology",
43268
+ "feOffset",
43269
+ "fePointLight",
43270
+ "feSpecularLighting",
43271
+ "feSpotLight",
43272
+ "feTile",
43273
+ "feTurbulence"
43274
+ ]);
43275
+ const svgDisallowed = freeze([
43276
+ "animate",
43277
+ "color-profile",
43278
+ "cursor",
43279
+ "discard",
43280
+ "font-face",
43281
+ "font-face-format",
43282
+ "font-face-name",
43283
+ "font-face-src",
43284
+ "font-face-uri",
43285
+ "foreignobject",
43286
+ "hatch",
43287
+ "hatchpath",
43288
+ "mesh",
43289
+ "meshgradient",
43290
+ "meshpatch",
43291
+ "meshrow",
43292
+ "missing-glyph",
43293
+ "script",
43294
+ "set",
43295
+ "solidcolor",
43296
+ "unknown",
43297
+ "use"
43298
+ ]);
43299
+ const mathMl$1 = freeze([
43300
+ "math",
43301
+ "menclose",
43302
+ "merror",
43303
+ "mfenced",
43304
+ "mfrac",
43305
+ "mglyph",
43306
+ "mi",
43307
+ "mlabeledtr",
43308
+ "mmultiscripts",
43309
+ "mn",
43310
+ "mo",
43311
+ "mover",
43312
+ "mpadded",
43313
+ "mphantom",
43314
+ "mroot",
43315
+ "mrow",
43316
+ "ms",
43317
+ "mspace",
43318
+ "msqrt",
43319
+ "mstyle",
43320
+ "msub",
43321
+ "msup",
43322
+ "msubsup",
43323
+ "mtable",
43324
+ "mtd",
43325
+ "mtext",
43326
+ "mtr",
43327
+ "munder",
43328
+ "munderover",
43329
+ "mprescripts"
43330
+ ]);
43331
+ const mathMlDisallowed = freeze([
43332
+ "maction",
43333
+ "maligngroup",
43334
+ "malignmark",
43335
+ "mlongdiv",
43336
+ "mscarries",
43337
+ "mscarry",
43338
+ "msgroup",
43339
+ "mstack",
43340
+ "msline",
43341
+ "msrow",
43342
+ "semantics",
43343
+ "annotation",
43344
+ "annotation-xml",
43345
+ "mprescripts",
43346
+ "none"
43347
+ ]);
43348
+ const text = freeze(["#text"]);
43349
+ const html = freeze([
43350
+ "accept",
43351
+ "action",
43352
+ "align",
43353
+ "alt",
43354
+ "autocapitalize",
43355
+ "autocomplete",
43356
+ "autopictureinpicture",
43357
+ "autoplay",
43358
+ "background",
43359
+ "bgcolor",
43360
+ "border",
43361
+ "capture",
43362
+ "cellpadding",
43363
+ "cellspacing",
43364
+ "checked",
43365
+ "cite",
43366
+ "class",
43367
+ "clear",
43368
+ "color",
43369
+ "cols",
43370
+ "colspan",
43371
+ "command",
43372
+ "commandfor",
43373
+ "controls",
43374
+ "controlslist",
43375
+ "coords",
43376
+ "crossorigin",
43377
+ "datetime",
43378
+ "decoding",
43379
+ "default",
43380
+ "dir",
43381
+ "disabled",
43382
+ "disablepictureinpicture",
43383
+ "disableremoteplayback",
43384
+ "download",
43385
+ "draggable",
43386
+ "enctype",
43387
+ "enterkeyhint",
43388
+ "exportparts",
43389
+ "face",
43390
+ "for",
43391
+ "headers",
43392
+ "height",
43393
+ "hidden",
43394
+ "high",
43395
+ "href",
43396
+ "hreflang",
43397
+ "id",
43398
+ "inert",
43399
+ "inputmode",
43400
+ "integrity",
43401
+ "ismap",
43402
+ "kind",
43403
+ "label",
43404
+ "lang",
43405
+ "list",
43406
+ "loading",
43407
+ "loop",
43408
+ "low",
43409
+ "max",
43410
+ "maxlength",
43411
+ "media",
43412
+ "method",
43413
+ "min",
43414
+ "minlength",
43415
+ "multiple",
43416
+ "muted",
43417
+ "name",
43418
+ "nonce",
43419
+ "noshade",
43420
+ "novalidate",
43421
+ "nowrap",
43422
+ "open",
43423
+ "optimum",
43424
+ "part",
43425
+ "pattern",
43426
+ "placeholder",
43427
+ "playsinline",
43428
+ "popover",
43429
+ "popovertarget",
43430
+ "popovertargetaction",
43431
+ "poster",
43432
+ "preload",
43433
+ "pubdate",
43434
+ "radiogroup",
43435
+ "readonly",
43436
+ "rel",
43437
+ "required",
43438
+ "rev",
43439
+ "reversed",
43440
+ "role",
43441
+ "rows",
43442
+ "rowspan",
43443
+ "spellcheck",
43444
+ "scope",
43445
+ "selected",
43446
+ "shape",
43447
+ "size",
43448
+ "sizes",
43449
+ "slot",
43450
+ "span",
43451
+ "srclang",
43452
+ "start",
43453
+ "src",
43454
+ "srcset",
43455
+ "step",
43456
+ "style",
43457
+ "summary",
43458
+ "tabindex",
43459
+ "title",
43460
+ "translate",
43461
+ "type",
43462
+ "usemap",
43463
+ "valign",
43464
+ "value",
43465
+ "width",
43466
+ "wrap",
43467
+ "xmlns"
43468
+ ]);
43469
+ const svg = freeze([
43470
+ "accent-height",
43471
+ "accumulate",
43472
+ "additive",
43473
+ "alignment-baseline",
43474
+ "amplitude",
43475
+ "ascent",
43476
+ "attributename",
43477
+ "attributetype",
43478
+ "azimuth",
43479
+ "basefrequency",
43480
+ "baseline-shift",
43481
+ "begin",
43482
+ "bias",
43483
+ "by",
43484
+ "class",
43485
+ "clip",
43486
+ "clippathunits",
43487
+ "clip-path",
43488
+ "clip-rule",
43489
+ "color",
43490
+ "color-interpolation",
43491
+ "color-interpolation-filters",
43492
+ "color-profile",
43493
+ "color-rendering",
43494
+ "cx",
43495
+ "cy",
43496
+ "d",
43497
+ "dx",
43498
+ "dy",
43499
+ "diffuseconstant",
43500
+ "direction",
43501
+ "display",
43502
+ "divisor",
43503
+ "dominant-baseline",
43504
+ "dur",
43505
+ "edgemode",
43506
+ "elevation",
43507
+ "end",
43508
+ "exponent",
43509
+ "fill",
43510
+ "fill-opacity",
43511
+ "fill-rule",
43512
+ "filter",
43513
+ "filterunits",
43514
+ "flood-color",
43515
+ "flood-opacity",
43516
+ "font-family",
43517
+ "font-size",
43518
+ "font-size-adjust",
43519
+ "font-stretch",
43520
+ "font-style",
43521
+ "font-variant",
43522
+ "font-weight",
43523
+ "fx",
43524
+ "fy",
43525
+ "g1",
43526
+ "g2",
43527
+ "glyph-name",
43528
+ "glyphref",
43529
+ "gradientunits",
43530
+ "gradienttransform",
43531
+ "height",
43532
+ "href",
43533
+ "id",
43534
+ "image-rendering",
43535
+ "in",
43536
+ "in2",
43537
+ "intercept",
43538
+ "k",
43539
+ "k1",
43540
+ "k2",
43541
+ "k3",
43542
+ "k4",
43543
+ "kerning",
43544
+ "keypoints",
43545
+ "keysplines",
43546
+ "keytimes",
43547
+ "lang",
43548
+ "lengthadjust",
43549
+ "letter-spacing",
43550
+ "kernelmatrix",
43551
+ "kernelunitlength",
43552
+ "lighting-color",
43553
+ "local",
43554
+ "marker-end",
43555
+ "marker-mid",
43556
+ "marker-start",
43557
+ "markerheight",
43558
+ "markerunits",
43559
+ "markerwidth",
43560
+ "maskcontentunits",
43561
+ "maskunits",
43562
+ "max",
43563
+ "mask",
43564
+ "mask-type",
43565
+ "media",
43566
+ "method",
43567
+ "mode",
43568
+ "min",
43569
+ "name",
43570
+ "numoctaves",
43571
+ "offset",
43572
+ "operator",
43573
+ "opacity",
43574
+ "order",
43575
+ "orient",
43576
+ "orientation",
43577
+ "origin",
43578
+ "overflow",
43579
+ "paint-order",
43580
+ "path",
43581
+ "pathlength",
43582
+ "patterncontentunits",
43583
+ "patterntransform",
43584
+ "patternunits",
43585
+ "pointer-events",
43586
+ "points",
43587
+ "preservealpha",
43588
+ "preserveaspectratio",
43589
+ "primitiveunits",
43590
+ "r",
43591
+ "rx",
43592
+ "ry",
43593
+ "radius",
43594
+ "refx",
43595
+ "refy",
43596
+ "repeatcount",
43597
+ "repeatdur",
43598
+ "restart",
43599
+ "result",
43600
+ "rotate",
43601
+ "scale",
43602
+ "seed",
43603
+ "shape-rendering",
43604
+ "slope",
43605
+ "specularconstant",
43606
+ "specularexponent",
43607
+ "spreadmethod",
43608
+ "startoffset",
43609
+ "stddeviation",
43610
+ "stitchtiles",
43611
+ "stop-color",
43612
+ "stop-opacity",
43613
+ "stroke-dasharray",
43614
+ "stroke-dashoffset",
43615
+ "stroke-linecap",
43616
+ "stroke-linejoin",
43617
+ "stroke-miterlimit",
43618
+ "stroke-opacity",
43619
+ "stroke",
43620
+ "stroke-width",
43621
+ "style",
43622
+ "surfacescale",
43623
+ "systemlanguage",
43624
+ "tabindex",
43625
+ "tablevalues",
43626
+ "targetx",
43627
+ "targety",
43628
+ "transform",
43629
+ "transform-origin",
43630
+ "text-anchor",
43631
+ "text-decoration",
43632
+ "text-orientation",
43633
+ "text-rendering",
43634
+ "textlength",
43635
+ "type",
43636
+ "u1",
43637
+ "u2",
43638
+ "unicode",
43639
+ "values",
43640
+ "vector-effect",
43641
+ "viewbox",
43642
+ "visibility",
43643
+ "version",
43644
+ "vert-adv-y",
43645
+ "vert-origin-x",
43646
+ "vert-origin-y",
43647
+ "width",
43648
+ "word-spacing",
43649
+ "wrap",
43650
+ "writing-mode",
43651
+ "xchannelselector",
43652
+ "ychannelselector",
43653
+ "x",
43654
+ "x1",
43655
+ "x2",
43656
+ "xmlns",
43657
+ "y",
43658
+ "y1",
43659
+ "y2",
43660
+ "z",
43661
+ "zoomandpan"
43662
+ ]);
43663
+ const mathMl = freeze([
43664
+ "accent",
43665
+ "accentunder",
43666
+ "align",
43667
+ "bevelled",
43668
+ "close",
43669
+ "columnalign",
43670
+ "columnlines",
43671
+ "columnspacing",
43672
+ "columnspan",
43673
+ "denomalign",
43674
+ "depth",
43675
+ "dir",
43676
+ "display",
43677
+ "displaystyle",
43678
+ "encoding",
43679
+ "fence",
43680
+ "frame",
43681
+ "height",
43682
+ "href",
43683
+ "id",
43684
+ "largeop",
43685
+ "length",
43686
+ "linethickness",
43687
+ "lquote",
43688
+ "lspace",
43689
+ "mathbackground",
43690
+ "mathcolor",
43691
+ "mathsize",
43692
+ "mathvariant",
43693
+ "maxsize",
43694
+ "minsize",
43695
+ "movablelimits",
43696
+ "notation",
43697
+ "numalign",
43698
+ "open",
43699
+ "rowalign",
43700
+ "rowlines",
43701
+ "rowspacing",
43702
+ "rowspan",
43703
+ "rspace",
43704
+ "rquote",
43705
+ "scriptlevel",
43706
+ "scriptminsize",
43707
+ "scriptsizemultiplier",
43708
+ "selection",
43709
+ "separator",
43710
+ "separators",
43711
+ "stretchy",
43712
+ "subscriptshift",
43713
+ "supscriptshift",
43714
+ "symmetric",
43715
+ "voffset",
43716
+ "width",
43717
+ "xmlns"
43718
+ ]);
43719
+ const xml = freeze([
43720
+ "xlink:href",
43721
+ "xml:id",
43722
+ "xlink:title",
43723
+ "xml:space",
43724
+ "xmlns:xlink"
43725
+ ]);
43726
+ const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
43727
+ const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
43728
+ const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
43729
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
43730
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/);
43731
+ const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
43732
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
43733
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g);
43734
+ const DOCTYPE_NAME = seal(/^html$/i);
43735
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
43736
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
43737
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
43738
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
43739
+ const SELF_CLOSING_TAG = seal(/\/>/i);
43740
+ const NODE_TYPE = {
43741
+ element: 1,
43742
+ attribute: 2,
43743
+ text: 3,
43744
+ cdataSection: 4,
43745
+ entityReference: 5,
43746
+ entityNode: 6,
43747
+ processingInstruction: 7,
43748
+ comment: 8,
43749
+ document: 9,
43750
+ documentType: 10,
43751
+ documentFragment: 11,
43752
+ notation: 12
43753
+ };
43754
+ const LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, [
43755
+ "style",
43756
+ "script",
43757
+ "xmp",
43758
+ "iframe",
43759
+ "noembed",
43760
+ "noframes",
43761
+ "plaintext",
43762
+ "noscript"
43763
+ ]));
43764
+ const getGlobal = function getGlobal() {
43765
+ return typeof window === "undefined" ? null : window;
43766
+ };
43767
+ /**
43768
+ * Creates a no-op policy for internal use only.
43769
+ * Don't export this function outside this module!
43770
+ * @param trustedTypes The policy factory.
43771
+ * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
43772
+ * @return The policy created (or null, if Trusted Types
43773
+ * are not supported or creating the policy failed).
43774
+ */
43775
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
43776
+ if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") return null;
43777
+ let suffix = null;
43778
+ const ATTR_NAME = "data-tt-policy-suffix";
43779
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) suffix = purifyHostElement.getAttribute(ATTR_NAME);
43780
+ const policyName = "dompurify" + (suffix ? "#" + suffix : "");
43781
+ try {
43782
+ return trustedTypes.createPolicy(policyName, {
43783
+ createHTML(html) {
43784
+ return html;
43785
+ },
43786
+ createScriptURL(scriptUrl) {
43787
+ return scriptUrl;
43788
+ }
43789
+ });
43790
+ } catch (_) {
43791
+ console.warn("TrustedTypes policy " + policyName + " could not be created.");
43792
+ return null;
43793
+ }
43794
+ };
43795
+ const _createHooksMap = function _createHooksMap() {
43796
+ return {
43797
+ afterSanitizeAttributes: [],
43798
+ afterSanitizeElements: [],
43799
+ afterSanitizeShadowDOM: [],
43800
+ beforeSanitizeAttributes: [],
43801
+ beforeSanitizeElements: [],
43802
+ beforeSanitizeShadowDOM: [],
43803
+ uponSanitizeAttribute: [],
43804
+ uponSanitizeElement: [],
43805
+ uponSanitizeShadowNode: []
43806
+ };
43807
+ };
43808
+ /**
43809
+ * Resolve a set-valued configuration option: a fresh set built from
43810
+ * cfg[key] when it is an own array property (seeded with a clone of
43811
+ * options.base when given, case-normalized via options.transform),
43812
+ * the fallback set otherwise.
43813
+ *
43814
+ * @param cfg the cloned, prototype-free configuration object
43815
+ * @param key the configuration property to read
43816
+ * @param fallback the set to use when the option is absent or not an array
43817
+ * @param options transform and optional base set to merge into
43818
+ * @returns the resolved set
43819
+ */
43820
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
43821
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
43822
+ };
43823
+ /**
43824
+ * Resolve an object-valued configuration option: a prototype-free clone
43825
+ * of cfg[key] when it is an own, truthy object property, else a fresh
43826
+ * fallback built by makeFallback (fresh on every parse, so a previous
43827
+ * parse can never leak state into the next one).
43828
+ *
43829
+ * @param cfg the cloned, prototype-free configuration object
43830
+ * @param key the configuration property to read
43831
+ * @param makeFallback builds the fallback value when the option is absent
43832
+ * @returns the resolved object
43833
+ */
43834
+ const _resolveObjectOption = function _resolveObjectOption(cfg, key, makeFallback) {
43835
+ const value = objectHasOwnProperty(cfg, key) ? cfg[key] : void 0;
43836
+ return value && typeof value === "object" ? clone(value) : makeFallback();
43837
+ };
43838
+ function createDOMPurify() {
43839
+ let window = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
43840
+ const DOMPurify = (root) => createDOMPurify(root);
43841
+ DOMPurify.version = "3.4.17";
43842
+ DOMPurify.removed = [];
43843
+ if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
43844
+ DOMPurify.isSupported = false;
43845
+ return DOMPurify;
43846
+ }
43847
+ let document = window.document;
43848
+ const originalDocument = document;
43849
+ const currentScript = originalDocument.currentScript;
43850
+ const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter;
43851
+ const DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
43852
+ const ElementPrototype = Element.prototype;
43853
+ const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
43854
+ const remove = lookupGetter(ElementPrototype, "remove");
43855
+ const removeAttributeNode = lookupGetter(ElementPrototype, "removeAttributeNode");
43856
+ const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
43857
+ const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
43858
+ const getParentNode = lookupGetter(ElementPrototype, "parentNode");
43859
+ const getShadowRoot = lookupGetter(ElementPrototype, "shadowRoot");
43860
+ const getAttributes = lookupGetter(ElementPrototype, "attributes");
43861
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeType") : null;
43862
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeName") : null;
43863
+ const getOwnerDocument = Node && Node.prototype ? lookupGetter(Node.prototype, "ownerDocument") : null;
43864
+ const _readNodeType = function _readNodeType(node) {
43865
+ return getNodeType ? getNodeType(node) : node.nodeType;
43866
+ };
43867
+ const _readNodeName = function _readNodeName(node) {
43868
+ return getNodeName ? getNodeName(node) : node.nodeName;
43869
+ };
43870
+ const getNamespaceURI = lookupAccessor(ElementPrototype, "namespaceURI");
43871
+ const _readNamespaceURI = function _readNamespaceURI(element) {
43872
+ return getNamespaceURI ? getNamespaceURI(element) : element.namespaceURI;
43873
+ };
43874
+ if (typeof HTMLTemplateElement === "function") {
43875
+ const template = document.createElement("template");
43876
+ if (template.content && template.content.ownerDocument) document = template.content.ownerDocument;
43877
+ }
43878
+ let trustedTypesPolicy;
43879
+ let emptyHTML = "";
43880
+ let defaultTrustedTypesPolicy;
43881
+ let defaultTrustedTypesPolicyResolved = false;
43882
+ let IN_TRUSTED_TYPES_POLICY = 0;
43883
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
43884
+ if (IN_TRUSTED_TYPES_POLICY > 0) throw typeErrorCreate("A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the \"DOMPurify and Trusted Types\" section of the README.");
43885
+ };
43886
+ const _createTrustedHTML = function _createTrustedHTML(html) {
43887
+ _assertNotInTrustedTypesPolicy();
43888
+ IN_TRUSTED_TYPES_POLICY++;
43889
+ try {
43890
+ return trustedTypesPolicy.createHTML(html);
43891
+ } finally {
43892
+ IN_TRUSTED_TYPES_POLICY--;
43893
+ }
43894
+ };
43895
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
43896
+ _assertNotInTrustedTypesPolicy();
43897
+ IN_TRUSTED_TYPES_POLICY++;
43898
+ try {
43899
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
43900
+ } finally {
43901
+ IN_TRUSTED_TYPES_POLICY--;
43902
+ }
43903
+ };
43904
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
43905
+ if (!defaultTrustedTypesPolicyResolved) {
43906
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
43907
+ defaultTrustedTypesPolicyResolved = true;
43908
+ }
43909
+ return defaultTrustedTypesPolicy;
43910
+ };
43911
+ const _document = document, implementation = _document.implementation, createNodeIterator = _document.createNodeIterator, createDocumentFragment = _document.createDocumentFragment, getElementsByTagName = _document.getElementsByTagName;
43912
+ const importNode = originalDocument.importNode;
43913
+ let hooks = _createHooksMap();
43914
+ /**
43915
+ * Expose whether this browser supports running the full DOMPurify.
43916
+ */
43917
+ DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
43918
+ const MUSTACHE_EXPR$1 = MUSTACHE_EXPR, ERB_EXPR$1 = ERB_EXPR, TMPLIT_EXPR$1 = TMPLIT_EXPR, DATA_ATTR$1 = DATA_ATTR, ARIA_ATTR$1 = ARIA_ATTR, IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA, ATTR_WHITESPACE$1 = ATTR_WHITESPACE, CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
43919
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
43920
+ /**
43921
+ * We consider the elements and attributes below to be safe. Ideally
43922
+ * don't add any new ones but feel free to remove unwanted ones.
43923
+ */
43924
+ let ALLOWED_TAGS = null;
43925
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [
43926
+ ...html$1,
43927
+ ...svg$1,
43928
+ ...svgFilters,
43929
+ ...mathMl$1,
43930
+ ...text
43931
+ ]);
43932
+ let ALLOWED_ATTR = null;
43933
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [
43934
+ ...html,
43935
+ ...svg,
43936
+ ...mathMl,
43937
+ ...xml
43938
+ ]);
43939
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
43940
+ tagNameCheck: {
43941
+ writable: true,
43942
+ configurable: false,
43943
+ enumerable: true,
43944
+ value: null
43945
+ },
43946
+ attributeNameCheck: {
43947
+ writable: true,
43948
+ configurable: false,
43949
+ enumerable: true,
43950
+ value: null
43951
+ },
43952
+ allowCustomizedBuiltInElements: {
43953
+ writable: true,
43954
+ configurable: false,
43955
+ enumerable: true,
43956
+ value: false
43957
+ }
43958
+ }));
43959
+ let FORBID_TAGS = null;
43960
+ let FORBID_ATTR = null;
43961
+ const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
43962
+ tagCheck: {
43963
+ writable: true,
43964
+ configurable: false,
43965
+ enumerable: true,
43966
+ value: null
43967
+ },
43968
+ attributeCheck: {
43969
+ writable: true,
43970
+ configurable: false,
43971
+ enumerable: true,
43972
+ value: null
43973
+ }
43974
+ }));
43975
+ let ALLOW_ARIA_ATTR = true;
43976
+ let ALLOW_DATA_ATTR = true;
43977
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
43978
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
43979
+ let SAFE_FOR_TEMPLATES = false;
43980
+ let SAFE_FOR_XML = true;
43981
+ let WHOLE_DOCUMENT = false;
43982
+ let SET_CONFIG = false;
43983
+ let SET_CONFIG_ALLOWED_TAGS = null;
43984
+ let SET_CONFIG_ALLOWED_ATTR = null;
43985
+ let FORCE_BODY = false;
43986
+ let RETURN_DOM = false;
43987
+ let RETURN_DOM_FRAGMENT = false;
43988
+ let RETURN_TRUSTED_TYPE = false;
43989
+ let SANITIZE_DOM = true;
43990
+ let SANITIZE_NAMED_PROPS = false;
43991
+ const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
43992
+ let KEEP_CONTENT = true;
43993
+ let IN_PLACE = false;
43994
+ let IN_PLACE_VISITED = null;
43995
+ let USE_PROFILES = {};
43996
+ let FORBID_CONTENTS = null;
43997
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, [
43998
+ "annotation-xml",
43999
+ "audio",
44000
+ "colgroup",
44001
+ "desc",
44002
+ "foreignobject",
44003
+ "head",
44004
+ "iframe",
44005
+ "math",
44006
+ "mi",
44007
+ "mn",
44008
+ "mo",
44009
+ "ms",
44010
+ "mtext",
44011
+ "noembed",
44012
+ "noframes",
44013
+ "noscript",
44014
+ "plaintext",
44015
+ "script",
44016
+ "selectedcontent",
44017
+ "style",
44018
+ "svg",
44019
+ "template",
44020
+ "thead",
44021
+ "title",
44022
+ "video",
44023
+ "xmp"
44024
+ ]);
44025
+ let DATA_URI_TAGS = null;
44026
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, [
44027
+ "audio",
44028
+ "video",
44029
+ "img",
44030
+ "source",
44031
+ "image",
44032
+ "track"
44033
+ ]);
44034
+ let URI_SAFE_ATTRIBUTES = null;
44035
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
44036
+ "alt",
44037
+ "class",
44038
+ "for",
44039
+ "id",
44040
+ "label",
44041
+ "name",
44042
+ "pattern",
44043
+ "placeholder",
44044
+ "role",
44045
+ "summary",
44046
+ "title",
44047
+ "value",
44048
+ "style",
44049
+ "xmlns"
44050
+ ]);
44051
+ const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
44052
+ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
44053
+ const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
44054
+ let NAMESPACE = HTML_NAMESPACE;
44055
+ let IS_EMPTY_INPUT = false;
44056
+ let ALLOWED_NAMESPACES = null;
44057
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [
44058
+ MATHML_NAMESPACE,
44059
+ SVG_NAMESPACE,
44060
+ HTML_NAMESPACE
44061
+ ], stringToString);
44062
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze([
44063
+ "mi",
44064
+ "mo",
44065
+ "mn",
44066
+ "ms",
44067
+ "mtext"
44068
+ ]);
44069
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
44070
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(["annotation-xml"]);
44071
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
44072
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
44073
+ "title",
44074
+ "style",
44075
+ "font",
44076
+ "a",
44077
+ "script"
44078
+ ]);
44079
+ let PARSER_MEDIA_TYPE = null;
44080
+ const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
44081
+ const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
44082
+ let transformCaseFunc = null;
44083
+ let CONFIG = null;
44084
+ const formElement = document.createElement("form");
44085
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
44086
+ return testValue instanceof RegExp || testValue instanceof Function;
44087
+ };
44088
+ /**
44089
+ * _parseConfig
44090
+ *
44091
+ * @param cfg optional config literal
44092
+ */
44093
+ const _parseConfig = function _parseConfig() {
44094
+ let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
44095
+ if (CONFIG && CONFIG === cfg) return;
44096
+ if (!cfg || typeof cfg !== "object") cfg = {};
44097
+ cfg = clone(cfg);
44098
+ PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
44099
+ transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
44100
+ ALLOWED_TAGS = _resolveSetOption(cfg, "ALLOWED_TAGS", DEFAULT_ALLOWED_TAGS, { transform: transformCaseFunc });
44101
+ ALLOWED_ATTR = _resolveSetOption(cfg, "ALLOWED_ATTR", DEFAULT_ALLOWED_ATTR, { transform: transformCaseFunc });
44102
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, "ALLOWED_NAMESPACES", DEFAULT_ALLOWED_NAMESPACES, { transform: stringToString });
44103
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, "ADD_URI_SAFE_ATTR", DEFAULT_URI_SAFE_ATTRIBUTES, {
44104
+ transform: transformCaseFunc,
44105
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
44106
+ });
44107
+ DATA_URI_TAGS = _resolveSetOption(cfg, "ADD_DATA_URI_TAGS", DEFAULT_DATA_URI_TAGS, {
44108
+ transform: transformCaseFunc,
44109
+ base: DEFAULT_DATA_URI_TAGS
44110
+ });
44111
+ FORBID_CONTENTS = _resolveSetOption(cfg, "FORBID_CONTENTS", DEFAULT_FORBID_CONTENTS, { transform: transformCaseFunc });
44112
+ FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", clone({}), { transform: transformCaseFunc });
44113
+ FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", clone({}), { transform: transformCaseFunc });
44114
+ USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === "object" ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
44115
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
44116
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
44117
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
44118
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
44119
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
44120
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
44121
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
44122
+ RETURN_DOM = cfg.RETURN_DOM || false;
44123
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
44124
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
44125
+ FORCE_BODY = cfg.FORCE_BODY || false;
44126
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
44127
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
44128
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
44129
+ IN_PLACE = cfg.IN_PLACE || false;
44130
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI;
44131
+ NAMESPACE = typeof cfg.NAMESPACE === "string" ? cfg.NAMESPACE : HTML_NAMESPACE;
44132
+ MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS));
44133
+ HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS));
44134
+ const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", () => create(null));
44135
+ CUSTOM_ELEMENT_HANDLING = create(null);
44136
+ if (objectHasOwnProperty(customElementHandling, "tagNameCheck") && isRegexOrFunction(customElementHandling.tagNameCheck)) CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck;
44137
+ if (objectHasOwnProperty(customElementHandling, "attributeNameCheck") && isRegexOrFunction(customElementHandling.attributeNameCheck)) CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck;
44138
+ if (objectHasOwnProperty(customElementHandling, "allowCustomizedBuiltInElements") && typeof customElementHandling.allowCustomizedBuiltInElements === "boolean") CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements;
44139
+ seal(CUSTOM_ELEMENT_HANDLING);
44140
+ if (SAFE_FOR_TEMPLATES) ALLOW_DATA_ATTR = false;
44141
+ if (RETURN_DOM_FRAGMENT) RETURN_DOM = true;
44142
+ if (USE_PROFILES) {
44143
+ ALLOWED_TAGS = addToSet({}, text);
44144
+ ALLOWED_ATTR = create(null);
44145
+ if (USE_PROFILES.html === true) {
44146
+ addToSet(ALLOWED_TAGS, html$1);
44147
+ addToSet(ALLOWED_ATTR, html);
44148
+ }
44149
+ if (USE_PROFILES.svg === true) {
44150
+ addToSet(ALLOWED_TAGS, svg$1);
44151
+ addToSet(ALLOWED_ATTR, svg);
44152
+ addToSet(ALLOWED_ATTR, xml);
44153
+ }
44154
+ if (USE_PROFILES.svgFilters === true) {
44155
+ addToSet(ALLOWED_TAGS, svgFilters);
44156
+ addToSet(ALLOWED_ATTR, svg);
44157
+ addToSet(ALLOWED_ATTR, xml);
44158
+ }
44159
+ if (USE_PROFILES.mathMl === true) {
44160
+ addToSet(ALLOWED_TAGS, mathMl$1);
44161
+ addToSet(ALLOWED_ATTR, mathMl);
44162
+ addToSet(ALLOWED_ATTR, xml);
44163
+ }
44164
+ }
44165
+ EXTRA_ELEMENT_HANDLING.tagCheck = null;
44166
+ EXTRA_ELEMENT_HANDLING.attributeCheck = null;
44167
+ if (objectHasOwnProperty(cfg, "ADD_TAGS")) {
44168
+ if (typeof cfg.ADD_TAGS === "function") EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
44169
+ else if (arrayIsArray(cfg.ADD_TAGS)) {
44170
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = clone(ALLOWED_TAGS);
44171
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
44172
+ }
44173
+ }
44174
+ if (objectHasOwnProperty(cfg, "ADD_ATTR")) {
44175
+ if (typeof cfg.ADD_ATTR === "function") EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
44176
+ else if (arrayIsArray(cfg.ADD_ATTR)) {
44177
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = clone(ALLOWED_ATTR);
44178
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
44179
+ }
44180
+ }
44181
+ if (objectHasOwnProperty(cfg, "ADD_FORBID_CONTENTS") && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
44182
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = clone(FORBID_CONTENTS);
44183
+ addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
44184
+ }
44185
+ if (KEEP_CONTENT) ALLOWED_TAGS["#text"] = true;
44186
+ if (WHOLE_DOCUMENT) addToSet(ALLOWED_TAGS, [
44187
+ "html",
44188
+ "head",
44189
+ "body"
44190
+ ]);
44191
+ if (ALLOWED_TAGS.table) {
44192
+ addToSet(ALLOWED_TAGS, ["tbody"]);
44193
+ delete FORBID_TAGS.tbody;
44194
+ }
44195
+ if (cfg.TRUSTED_TYPES_POLICY) {
44196
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") throw typeErrorCreate("TRUSTED_TYPES_POLICY configuration option must provide a \"createHTML\" hook.");
44197
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") throw typeErrorCreate("TRUSTED_TYPES_POLICY configuration option must provide a \"createScriptURL\" hook.");
44198
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
44199
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
44200
+ try {
44201
+ emptyHTML = _createTrustedHTML("");
44202
+ } catch (error) {
44203
+ trustedTypesPolicy = previousTrustedTypesPolicy;
44204
+ throw error;
44205
+ }
44206
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
44207
+ trustedTypesPolicy = void 0;
44208
+ emptyHTML = "";
44209
+ } else {
44210
+ if (trustedTypesPolicy === void 0) trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
44211
+ if (trustedTypesPolicy && typeof emptyHTML === "string") emptyHTML = _createTrustedHTML("");
44212
+ }
44213
+ if (freeze) freeze(cfg);
44214
+ CONFIG = cfg;
44215
+ };
44216
+ const ALL_SVG_TAGS = addToSet({}, [
44217
+ ...svg$1,
44218
+ ...svgFilters,
44219
+ ...svgDisallowed
44220
+ ]);
44221
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
44222
+ /**
44223
+ * Namespace rules for an element in the SVG namespace.
44224
+ *
44225
+ * @param tagName the element's lowercase tag name
44226
+ * @param parent the (possibly simulated) parent node
44227
+ * @param parentTagName the parent's lowercase tag name
44228
+ * @returns true if a spec-compliant parser could produce this element
44229
+ */
44230
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
44231
+ if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "svg";
44232
+ if (parent.namespaceURI === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
44233
+ return Boolean(ALL_SVG_TAGS[tagName]);
44234
+ };
44235
+ /**
44236
+ * Namespace rules for an element in the MathML namespace.
44237
+ *
44238
+ * @param tagName the element's lowercase tag name
44239
+ * @param parent the (possibly simulated) parent node
44240
+ * @param parentTagName the parent's lowercase tag name
44241
+ * @returns true if a spec-compliant parser could produce this element
44242
+ */
44243
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
44244
+ if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "math";
44245
+ if (parent.namespaceURI === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
44246
+ return Boolean(ALL_MATHML_TAGS[tagName]);
44247
+ };
44248
+ /**
44249
+ * Namespace rules for an element in the HTML namespace.
44250
+ *
44251
+ * @param tagName the element's lowercase tag name
44252
+ * @param parent the (possibly simulated) parent node
44253
+ * @param parentTagName the parent's lowercase tag name
44254
+ * @returns true if a spec-compliant parser could produce this element
44255
+ */
44256
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
44257
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
44258
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
44259
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
44260
+ };
44261
+ /**
44262
+ * @param element a DOM element whose namespace is being checked
44263
+ * @returns Return false if the element has a
44264
+ * namespace that a spec-compliant parser would never
44265
+ * return. Return true otherwise.
44266
+ */
44267
+ const _checkValidNamespace = function _checkValidNamespace(element) {
44268
+ const elementNamespace = _readNamespaceURI(element);
44269
+ const tagName = stringToLowerCase(_readNodeName(element));
44270
+ const parentNode = getParentNode(element);
44271
+ let parent;
44272
+ let parentTagName;
44273
+ if (parentNode && _readNodeType(parentNode) === NODE_TYPE.element) {
44274
+ parent = { namespaceURI: _readNamespaceURI(parentNode) };
44275
+ parentTagName = stringToLowerCase(_readNodeName(parentNode));
44276
+ } else {
44277
+ parent = { namespaceURI: NAMESPACE };
44278
+ parentTagName = "template";
44279
+ }
44280
+ if (!ALLOWED_NAMESPACES[elementNamespace]) return false;
44281
+ if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parent, parentTagName);
44282
+ if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parent, parentTagName);
44283
+ if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parent, parentTagName);
44284
+ if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[elementNamespace]) return true;
44285
+ return false;
44286
+ };
44287
+ /**
44288
+ * _forceRemove
44289
+ *
44290
+ * @param node a DOM node
44291
+ */
44292
+ const _forceRemove = function _forceRemove(node) {
44293
+ arrayPush(DOMPurify.removed, { element: node });
44294
+ try {
44295
+ getParentNode(node).removeChild(node);
44296
+ } catch (_) {
44297
+ remove(node);
44298
+ if (!getParentNode(node)) throw typeErrorCreate("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place");
44299
+ }
44300
+ };
44301
+ /**
44302
+ * _stripAttributeNode
44303
+ *
44304
+ * Remove a single Attr node case/namespace-exactly on an attribute-teardown
44305
+ * path. Name-based removeAttribute() ASCII-lowercases its lookup key for an
44306
+ * HTML element in an HTML document and so silently misses a case-preserved
44307
+ * handler (e.g. `ONERROR` off an XML/XHTML import) - the same defect
44308
+ * _removeAttribute() was fixed for, which a name-based call would reintroduce
44309
+ * on these IN_PLACE teardown paths. Unlike _removeAttribute this does not
44310
+ * record into DOMPurify.removed: the neutralize passes intentionally do not
44311
+ * book-keep. A clobbered/detached node falls back to best-effort name-based
44312
+ * removal.
44313
+ *
44314
+ * @param element the element to strip the attribute from
44315
+ * @param attribute the Attr node to remove
44316
+ * @param name the attribute's name, for the fallback path
44317
+ */
44318
+ const _stripAttributeNode = function _stripAttributeNode(element, attribute, name) {
44319
+ try {
44320
+ removeAttributeNode(element, attribute);
44321
+ } catch (_) {
44322
+ try {
44323
+ element.removeAttribute(name);
44324
+ } catch (_) {}
44325
+ }
44326
+ };
44327
+ /**
44328
+ * Fail-closed teardown of an in-place root: strip every disallowed attribute
44329
+ * in the subtree first, so nothing armed is left behind, then remove all
44330
+ * children and the root's own attributes.
44331
+ *
44332
+ * @param root the in-place root to empty
44333
+ */
44334
+ const _neutralizeRoot = function _neutralizeRoot(root) {
44335
+ _neutralizeSubtree(root);
44336
+ const childNodes = getChildNodes(root);
44337
+ if (childNodes) arrayForEach(arraySlice(childNodes), (child) => {
44338
+ try {
44339
+ remove(child);
44340
+ } catch (_) {}
44341
+ });
44342
+ const attributes = _readNodeType(root) === NODE_TYPE.element ? getAttributes(root) : null;
44343
+ if (attributes) for (let i = attributes.length - 1; i >= 0; --i) {
44344
+ const attribute = attributes[i];
44345
+ const name = attribute && attribute.name;
44346
+ if (typeof name === "string") _stripAttributeNode(root, attribute, name);
44347
+ }
44348
+ };
44349
+ /**
44350
+ * Removes an attribute, preferably as its exact Attr node: name-based
44351
+ * removal lowercases the name in HTML documents and misses case-preserved
44352
+ * names, e.g. from imported XHTML.
44353
+ *
44354
+ * @param name an Attribute name
44355
+ * @param element a DOM node
44356
+ * @param attr the exact Attr node to remove, when the caller has it
44357
+ */
44358
+ const _removeAttribute = function _removeAttribute(name, element, attr) {
44359
+ if (!attr) try {
44360
+ attr = element.getAttributeNode(name);
44361
+ } catch (_) {
44362
+ attr = null;
44363
+ }
44364
+ arrayPush(DOMPurify.removed, {
44365
+ attribute: attr || null,
44366
+ from: element
44367
+ });
44368
+ try {
44369
+ if (attr) removeAttributeNode(element, attr);
44370
+ else element.removeAttribute(name);
44371
+ } catch (_) {
44372
+ try {
44373
+ element.removeAttribute(name);
44374
+ } catch (_) {}
44375
+ }
44376
+ if (name === "is") {
44377
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) try {
44378
+ _forceRemove(element);
44379
+ } catch (_) {}
44380
+ else try {
44381
+ element.setAttribute(name, "");
44382
+ } catch (_) {}
44383
+ }
44384
+ };
44385
+ /**
44386
+ * Removes every attribute the configuration does not allow. Used to
44387
+ * neutralize nodes discarded from an in-place tree.
44388
+ *
44389
+ * @param element the element to strip
44390
+ */
44391
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
44392
+ const attributes = getAttributes(element);
44393
+ if (!attributes) return;
44394
+ for (let i = attributes.length - 1; i >= 0; --i) {
44395
+ const attribute = attributes[i];
44396
+ const name = attribute && attribute.name;
44397
+ if (typeof name !== "string" || ALLOWED_ATTR[transformCaseFunc(name)]) continue;
44398
+ _stripAttributeNode(element, attribute, name);
44399
+ }
44400
+ };
44401
+ /**
44402
+ * Iterative depth-first walk, so deep trees cannot overflow the call stack,
44403
+ * reading through the cached getters, so clobbering cannot hide children.
44404
+ * When `visit` returns false, the node's children are skipped. With
44405
+ * `intoShadow`, open shadow roots are walked after their host's children.
44406
+ *
44407
+ * @param root where to start
44408
+ * @param visit called for every node
44409
+ * @param intoShadow whether to enter open shadow roots
44410
+ */
44411
+ const _walkTree = function _walkTree(root, visit) {
44412
+ let intoShadow = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
44413
+ const stack = [root];
44414
+ while (stack.length > 0) {
44415
+ const node = stack.pop();
44416
+ if (visit(node) === false) continue;
44417
+ if (intoShadow && _readNodeType(node) === NODE_TYPE.element) {
44418
+ const shadowRoot = getShadowRoot(node);
44419
+ if (_isDocumentFragment(shadowRoot)) stack.push(shadowRoot);
44420
+ }
44421
+ const childNodes = getChildNodes(node);
44422
+ if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push(childNodes[i]);
44423
+ }
44424
+ };
44425
+ /**
44426
+ * Strips disallowed attributes from every element of a discarded subtree,
44427
+ * so a handler that is already queued (a loading image) cannot fire.
44428
+ *
44429
+ * @param root the root of a removed subtree
44430
+ */
44431
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
44432
+ _walkTree(root, (node) => {
44433
+ if (_readNodeType(node) === NODE_TYPE.element) _stripDisallowedAttributes(node);
44434
+ });
44435
+ };
44436
+ /**
44437
+ * All nodes under `root`, root first, including open shadow roots. Template
44438
+ * content is not entered, it is inert.
44439
+ *
44440
+ * @param root the in-place root
44441
+ * @return the nodes
44442
+ */
44443
+ const _collectLiveNodes = function _collectLiveNodes(root) {
44444
+ const nodes = [];
44445
+ _walkTree(root, (node) => {
44446
+ nodes.push(node);
44447
+ }, true);
44448
+ return nodes;
44449
+ };
44450
+ /**
44451
+ * Strips disallowed attributes from every element that was under the
44452
+ * in-place root when the call started and no longer is, whatever removed
44453
+ * or moved it.
44454
+ *
44455
+ * @param root the in-place root
44456
+ * @param before the root's nodes, collected before the walk
44457
+ */
44458
+ const _neutralizeEscapedElements = function _neutralizeEscapedElements(root, before) {
44459
+ const reachable = setCreate();
44460
+ arrayForEach(_collectLiveNodes(root), (node) => {
44461
+ if (_readNodeType(node) === NODE_TYPE.element) setAdd(reachable, node);
44462
+ });
44463
+ arrayForEach(before, (node) => {
44464
+ if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node)) _stripDisallowedAttributes(node);
44465
+ });
44466
+ };
44467
+ /**
44468
+ * Neutralizes everything that left the in-place tree during the call: what
44469
+ * DOMPurify removed, and what hooks or custom elements removed or moved out.
44470
+ *
44471
+ * @param root the in-place root
44472
+ * @param before the root's nodes, collected before the walk
44473
+ * @return true if the root itself was removed
44474
+ */
44475
+ const _neutralizeDiscarded = function _neutralizeDiscarded(root, before) {
44476
+ let rootRemoved = false;
44477
+ arrayForEach(DOMPurify.removed, (entry) => {
44478
+ if (entry.element) {
44479
+ rootRemoved = rootRemoved || entry.element === root;
44480
+ _neutralizeSubtree(entry.element);
44481
+ }
44482
+ });
44483
+ _neutralizeEscapedElements(root, before);
44484
+ return rootRemoved;
44485
+ };
44486
+ const MAX_UNVISITED_ROUNDS = 8;
44487
+ /**
44488
+ * The walk only moves forward, so a node moved to a position it already
44489
+ * passed is never visited. Give every original node that is still in the
44490
+ * tree but unvisited the normal treatment, hooks included. Nodes created
44491
+ * during the call are left alone. Fails closed if the tree keeps changing.
44492
+ *
44493
+ * @param root the in-place root
44494
+ * @param before the root's nodes, collected before the walk
44495
+ */
44496
+ const _sanitizeUnvisitedNodes = function _sanitizeUnvisitedNodes(root, before) {
44497
+ const visited = IN_PLACE_VISITED;
44498
+ let original = null;
44499
+ const getOriginal = () => {
44500
+ if (!original) {
44501
+ original = setCreate();
44502
+ arrayForEach(before, (beforeNode) => {
44503
+ setAdd(original, beforeNode);
44504
+ });
44505
+ }
44506
+ return original;
44507
+ };
44508
+ for (let round = 0;; round++) {
44509
+ const live = _collectLiveNodes(root);
44510
+ const containers = [root];
44511
+ let pending = false;
44512
+ arrayForEach(live, (node) => {
44513
+ if (_readNodeType(node) === NODE_TYPE.documentFragment) arrayPush(containers, node);
44514
+ else if (!pending && !setHas(visited, node)) pending = setHas(getOriginal(), node);
44515
+ });
44516
+ if (!pending) return;
44517
+ if (round >= MAX_UNVISITED_ROUNDS) throw typeErrorCreate("the tree kept changing during in-place sanitization; refusing to return it");
44518
+ arrayForEach(containers, (container, index) => {
44519
+ _sanitizeUnvisitedIn(container, index > 0, root, getOriginal());
44520
+ });
44521
+ }
44522
+ };
44523
+ /**
44524
+ * One _sanitizeUnvisitedNodes pass over the root or an open shadow root.
44525
+ *
44526
+ * @param container the root or an open shadow root
44527
+ * @param inShadow whether container is a shadow root
44528
+ * @param root the in-place root
44529
+ * @param original the root's nodes collected before the walk, as a set
44530
+ */
44531
+ const _sanitizeUnvisitedIn = function _sanitizeUnvisitedIn(container, inShadow, root, original) {
44532
+ const iterator = _createNodeIterator(container);
44533
+ let node;
44534
+ while (node = iterator.nextNode()) {
44535
+ if (!setHas(original, node) || setHas(IN_PLACE_VISITED, node)) continue;
44536
+ if (inShadow) _executeHooks(hooks.uponSanitizeShadowNode, node, null);
44537
+ _sanitizeElements(node, root);
44538
+ _sanitizeAttributes(node, root);
44539
+ if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
44540
+ }
44541
+ };
44542
+ /**
44543
+ * Records that _sanitizeElements processed `node`. No-op outside IN_PLACE.
44544
+ *
44545
+ * @param node the node being processed
44546
+ */
44547
+ const _markVisited = function _markVisited(node) {
44548
+ if (IN_PLACE_VISITED) setAdd(IN_PLACE_VISITED, node);
44549
+ };
44550
+ /**
44551
+ * Patch-linkage attributes (declarative partial updates): `patchsrc`
44552
+ * always, `for` everywhere except on <label> and <output>. Gated on
44553
+ * SAFE_FOR_XML. Shared by the IN_PLACE pre-pass and _isValidAttribute.
44554
+ *
44555
+ * @param lcName the transformCaseFunc'd attribute name
44556
+ * @param lcTag the transformCaseFunc'd tag name of the carrying element
44557
+ * @return true if the attribute is patch linkage and must be dropped
44558
+ */
44559
+ const _isPatchLinkageAttribute = function _isPatchLinkageAttribute(lcName, lcTag) {
44560
+ if (!SAFE_FOR_XML) return false;
44561
+ if (lcName === "patchsrc") return true;
44562
+ return lcName === "for" && lcTag !== "label" && lcTag !== "output";
44563
+ };
44564
+ /**
44565
+ * IN_PLACE pre-pass: sever all patch linkage before the walk, so no patch
44566
+ * can fire mid-walk into a part of the tree the walker already passed.
44567
+ * Removes range markers (processing instructions, comments with markup)
44568
+ * and strips linkage attributes. It cannot undo a patch that already fired.
44569
+ *
44570
+ * TODO: if the shipped feature can patch through `for` on <label>/<output>,
44571
+ * drop that pair here too (see test/declarative-patch-probe.html).
44572
+ *
44573
+ * @param root the in-place root to sweep
44574
+ */
44575
+ const _neutralizePatchLinkage = function _neutralizePatchLinkage(root) {
44576
+ if (!SAFE_FOR_XML) return;
44577
+ _walkTree(root, (node) => {
44578
+ const nodeType = _readNodeType(node);
44579
+ if (nodeType === NODE_TYPE.processingInstruction || nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, node.data)) {
44580
+ try {
44581
+ remove(node);
44582
+ } catch (_) {}
44583
+ return false;
44584
+ }
44585
+ if (nodeType === NODE_TYPE.element) {
44586
+ const element = node;
44587
+ const lcTag = transformCaseFunc(_readNodeName(node));
44588
+ try {
44589
+ if (element.hasAttribute && element.hasAttribute("patchsrc")) element.removeAttribute("patchsrc");
44590
+ if (element.hasAttribute && element.hasAttribute("for") && _isPatchLinkageAttribute("for", lcTag)) element.removeAttribute("for");
44591
+ } catch (_) {}
44592
+ }
44593
+ return true;
44594
+ });
44595
+ };
44596
+ /**
44597
+ * _initDocument
44598
+ *
44599
+ * @param dirty - a string of dirty markup
44600
+ * @return a DOM, filled with the dirty markup
44601
+ */
44602
+ const _initDocument = function _initDocument(dirty) {
44603
+ let doc = null;
44604
+ let leadingWhitespace = null;
44605
+ if (FORCE_BODY) dirty = "<remove></remove>" + dirty;
44606
+ else {
44607
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
44608
+ leadingWhitespace = matches && matches[0];
44609
+ }
44610
+ if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) dirty = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body>" + dirty + "</body></html>";
44611
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
44612
+ if (NAMESPACE === HTML_NAMESPACE) try {
44613
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
44614
+ } catch (_) {}
44615
+ if (!doc || !doc.documentElement) {
44616
+ doc = implementation.createDocument(NAMESPACE, "template", null);
44617
+ try {
44618
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
44619
+ } catch (_) {}
44620
+ }
44621
+ const body = doc.body || doc.documentElement;
44622
+ if (dirty && leadingWhitespace) body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
44623
+ if (NAMESPACE === HTML_NAMESPACE) return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
44624
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
44625
+ };
44626
+ /**
44627
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
44628
+ *
44629
+ * @param root The root element or node to start traversing on.
44630
+ * @return The created NodeIterator
44631
+ */
44632
+ const _createNodeIterator = function _createNodeIterator(root) {
44633
+ const doc = getOwnerDocument ? getOwnerDocument(root) : root.ownerDocument;
44634
+ return createNodeIterator.call(doc || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
44635
+ };
44636
+ /**
44637
+ * Replace template expression syntax (mustache, ERB, template
44638
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
44639
+ * sites. Order matters: mustache, then ERB, then template literal.
44640
+ *
44641
+ * @param value the string to scrub
44642
+ * @returns the scrubbed string
44643
+ */
44644
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
44645
+ value = stringReplace(value, MUSTACHE_EXPR$1, " ");
44646
+ value = stringReplace(value, ERB_EXPR$1, " ");
44647
+ value = stringReplace(value, TMPLIT_EXPR$1, " ");
44648
+ return value;
44649
+ };
44650
+ /**
44651
+ * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
44652
+ * character data of an element subtree. Used as the final safety net for
44653
+ * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
44654
+ * which only form after text-node normalization (e.g. fragments split across
44655
+ * stripped elements) cannot survive into a template-evaluating framework.
44656
+ *
44657
+ * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
44658
+ * in place rather than round-tripping through innerHTML. This preserves
44659
+ * descendant node references (important for IN_PLACE callers), avoids a
44660
+ * serialize/reparse cycle, and reads literal character data — which means
44661
+ * `<%...%>` in text content matches the ERB regex against its real bytes
44662
+ * instead of the HTML-entity-escaped form innerHTML would produce.
44663
+ *
44664
+ * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
44665
+ * attributes is performed during the per-node `_sanitizeAttributes` pass.
44666
+ *
44667
+ * @param node The root element whose character data should be scrubbed.
44668
+ */
44669
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
44670
+ var _node$querySelectorAl;
44671
+ _scrubOwnCharacterData(node);
44672
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, "template");
44673
+ if (templates) arrayForEach(templates, (tmpl) => {
44674
+ if (_isDocumentFragment(tmpl.content)) _scrubTemplateExpressions2(tmpl.content);
44675
+ });
44676
+ };
44677
+ /**
44678
+ * _scrubOwnCharacterData
44679
+ *
44680
+ * Non-recursive core of _scrubTemplateExpressions: normalize `node` and
44681
+ * strip template expressions from its own character data only. Does not
44682
+ * enter <template>.content or attached shadow roots (NodeIterator never
44683
+ * does). Used by _sanitizeShadowDOM, where every nested template content
44684
+ * and shadow root is already walked - and therefore scrubbed - by its own
44685
+ * recursive _sanitizeShadowDOM call; recursing here as well would rescrub
44686
+ * each nested fragment once per ancestor, which is quadratic in nesting
44687
+ * depth.
44688
+ *
44689
+ * @param node The root whose own character data should be scrubbed.
44690
+ */
44691
+ const _scrubOwnCharacterData = function _scrubOwnCharacterData(node) {
44692
+ node.normalize();
44693
+ const doc = getOwnerDocument ? getOwnerDocument(node) : node.ownerDocument;
44694
+ const walker = createNodeIterator.call(doc || node, node, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
44695
+ let currentNode = walker.nextNode();
44696
+ while (currentNode) {
44697
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
44698
+ currentNode = walker.nextNode();
44699
+ }
44700
+ };
44701
+ /**
44702
+ * _isClobbered
44703
+ *
44704
+ * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
44705
+ * interface with [LegacyOverrideBuiltIns]; a descendant element with a
44706
+ * `name` attribute matching a prototype property shadows that property
44707
+ * on direct reads. We use this check at the IN_PLACE entry-point and
44708
+ * during attribute sanitization to refuse clobbered forms.
44709
+ *
44710
+ * @param element element to check for clobbering attacks
44711
+ * @return true if clobbered, false if safe
44712
+ */
44713
+ const _isClobbered = function _isClobbered(element) {
44714
+ const realTagName = getNodeName ? getNodeName(element) : null;
44715
+ if (typeof realTagName !== "string") return false;
44716
+ if (transformCaseFunc(realTagName) !== "form") return false;
44717
+ return typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || element.attributes !== getAttributes(element) || typeof element.removeAttribute !== "function" || typeof element.removeAttributeNode !== "function" || typeof element.getAttributeNode !== "function" || typeof element.setAttribute !== "function" || typeof element.namespaceURI !== "string" || typeof element.insertBefore !== "function" || typeof element.hasChildNodes !== "function" || element.nodeType !== getNodeType(element) || element.childNodes !== getChildNodes(element);
44718
+ };
44719
+ /**
44720
+ * Checks whether the given value is a DocumentFragment from any realm.
44721
+ *
44722
+ * The realm-independent replacement reads `nodeType` through the cached
44723
+ * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
44724
+ * constant (11). nodeType is a numeric value resolved from the node's
44725
+ * internal slot, identical across realms for the same kind of node.
44726
+ *
44727
+ * @param value object to check
44728
+ * @return true if value is a DocumentFragment-shaped node from any realm
44729
+ */
44730
+ const _isDocumentFragment = function _isDocumentFragment(value) {
44731
+ if (!getNodeType || typeof value !== "object" || value === null) return false;
44732
+ try {
44733
+ return getNodeType(value) === NODE_TYPE.documentFragment;
44734
+ } catch (_) {
44735
+ return false;
44736
+ }
44737
+ };
44738
+ /**
44739
+ * Checks whether the given object is a DOM node, including nodes that
44740
+ * originate from a different window/realm (e.g. an iframe's
44741
+ * contentDocument). The previous `value instanceof Node` check was
44742
+ * realm-bound: nodes from a different window failed it, causing
44743
+ * sanitize() to silently stringify them and reset IN_PLACE to false,
44744
+ * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
44745
+ *
44746
+ * @param value object to check whether it's a DOM node
44747
+ * @return true if value is a DOM node from any realm
44748
+ */
44749
+ const _isNode = function _isNode(value) {
44750
+ if (!getNodeType || typeof value !== "object" || value === null) return false;
44751
+ try {
44752
+ return typeof getNodeType(value) === "number";
44753
+ } catch (_) {
44754
+ return false;
44755
+ }
44756
+ };
44757
+ function _executeHooks(hooks, currentNode, data) {
44758
+ if (hooks.length === 0) return;
44759
+ arrayForEach(hooks, (hook) => {
44760
+ hook.call(DOMPurify, currentNode, data, CONFIG);
44761
+ });
44762
+ }
44763
+ /**
44764
+ * Structural-threat checks that condemn a node regardless of the
44765
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
44766
+ * processing instructions, markup-bearing comments. Pure predicate;
44767
+ * the caller removes. Check order is load-bearing.
44768
+ *
44769
+ * @param currentNode the node to inspect
44770
+ * @param tagName the node's transformCaseFunc'd tag name
44771
+ * @return true if the node must be removed
44772
+ */
44773
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
44774
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
44775
+ if (SAFE_FOR_XML && LITERAL_TEXT_ELEMENTS[tagName] && _readNodeType(currentNode) === NODE_TYPE.element && _readNamespaceURI(currentNode) === HTML_NAMESPACE && (_isNode(currentNode.firstElementChild) || typeof currentNode.textContent === "string" && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent))) return true;
44776
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) return true;
44777
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
44778
+ return false;
44779
+ };
44780
+ /**
44781
+ * Evaluate a CUSTOM_ELEMENT_HANDLING check (a RegExp or a predicate
44782
+ * function, per the validation in _parseConfig) against a name.
44783
+ * Additional arguments are forwarded to predicate functions - the
44784
+ * attributeNameCheck predicate receives the tag name as its second
44785
+ * argument. A null/absent check never matches.
44786
+ *
44787
+ * @param check the configured tagNameCheck / attributeNameCheck value
44788
+ * @param name the name to test
44789
+ * @param args extra arguments forwarded to a predicate function
44790
+ * @return true if the check matches the name
44791
+ */
44792
+ const _matchesNameCheck = function _matchesNameCheck(check, name) {
44793
+ if (check instanceof RegExp) return regExpTest(check, name);
44794
+ if (check instanceof Function) {
44795
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) args[_key - 2] = arguments[_key];
44796
+ return Boolean(check(name, ...args));
44797
+ }
44798
+ return false;
44799
+ };
44800
+ /**
44801
+ * Handle a node whose tag is forbidden or not allowlisted: keep
44802
+ * allowed custom elements (false return exits _sanitizeElements
44803
+ * early - the namespace and fallback-tag removal checks are
44804
+ * intentionally skipped for kept custom elements), else hoist
44805
+ * content per KEEP_CONTENT and remove.
44806
+ *
44807
+ * A kept custom element is the ONLY case in which this function
44808
+ * returns false, so the caller uses that return value to run the
44809
+ * afterSanitizeElements hook on the kept element and keep the
44810
+ * element-hook lifecycle consistent with normal allowlisted
44811
+ * elements (GHSA-c2j3-45gr-mqc4).
44812
+ *
44813
+ * @param currentNode the disallowed node
44814
+ * @param tagName the node's transformCaseFunc'd tag name
44815
+ * @return true if the node was removed, false if kept
44816
+ */
44817
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName, root) {
44818
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
44819
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName] && !FORBID_CONTENTS[stringToLowerCase(tagName)]) {
44820
+ const parentNode = getParentNode(currentNode);
44821
+ const childNodes = getChildNodes(currentNode);
44822
+ if (childNodes && parentNode) {
44823
+ const childCount = childNodes.length;
44824
+ for (let i = childCount - 1; i >= 0; --i) {
44825
+ const hoisted = currentNode === root ? cloneNode(childNodes[i], true) : childNodes[i];
44826
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
44827
+ }
44828
+ }
44829
+ }
44830
+ _forceRemove(currentNode);
44831
+ return true;
44832
+ };
44833
+ /**
44834
+ * Fork a hook-mutable allowlist off its shared binding the first time a
44835
+ * (possibly lazily-installed) uponSanitize* hook is about to see it, so the
44836
+ * hook cannot widen the per-instance default or the setConfig binding by
44837
+ * reference and leak past the call. Returns the set unchanged once it is
44838
+ * already call-local, so repeated calls across elements are idempotent.
44839
+ *
44840
+ * @param hookList the uponSanitize* hook array for this event
44841
+ * @param set the current ALLOWED_TAGS / ALLOWED_ATTR binding
44842
+ * @param defaultSet the per-instance DEFAULT_ALLOWED_* constant
44843
+ * @param setConfigSet the captured setConfig() binding, or null
44844
+ * @return a call-local clone if a hook is present and set is still shared,
44845
+ * else set unchanged
44846
+ */
44847
+ const _forkSharedAllowlist = function _forkSharedAllowlist(hookList, set, defaultSet, setConfigSet) {
44848
+ if (hookList.length === 0) return set;
44849
+ return set === defaultSet || set === setConfigSet ? clone(set) : set;
44850
+ };
44851
+ /**
44852
+ * A hook may have detached the node it was called for. If so, treat it as
44853
+ * removed and stop processing it; the walk root is exempt. On the IN_PLACE
44854
+ * path the detached subtree is neutralized right away.
44855
+ *
44856
+ * @param currentNode the node a hook may have detached
44857
+ * @param root the current walk root
44858
+ * @return true if the node was detached
44859
+ */
44860
+ const _handleHookDetachedNode = function _handleHookDetachedNode(currentNode, root) {
44861
+ if (currentNode === root || getParentNode(currentNode) !== null) return false;
44862
+ if (IN_PLACE) _neutralizeSubtree(currentNode);
44863
+ return true;
44864
+ };
44865
+ /**
44866
+ * _sanitizeElements
44867
+ *
44868
+ * @protect nodeName
44869
+ * @protect textContent
44870
+ * @protect removeChild
44871
+ * @param currentNode to check for permission to exist
44872
+ * @return true if node was killed, false if left alive
44873
+ */
44874
+ const _sanitizeElements = function _sanitizeElements(currentNode, root) {
44875
+ _markVisited(currentNode);
44876
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
44877
+ if (_handleHookDetachedNode(currentNode, root)) return true;
44878
+ if (_isClobbered(currentNode)) {
44879
+ _forceRemove(currentNode);
44880
+ return true;
44881
+ }
44882
+ const tagName = transformCaseFunc(_readNodeName(currentNode));
44883
+ ALLOWED_TAGS = _forkSharedAllowlist(hooks.uponSanitizeElement, ALLOWED_TAGS, DEFAULT_ALLOWED_TAGS, SET_CONFIG_ALLOWED_TAGS);
44884
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
44885
+ tagName,
44886
+ allowedTags: ALLOWED_TAGS
44887
+ });
44888
+ if (_handleHookDetachedNode(currentNode, root)) return true;
44889
+ if (_isUnsafeNode(currentNode, tagName)) {
44890
+ _forceRemove(currentNode);
44891
+ return true;
44892
+ }
44893
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
44894
+ const removed = _sanitizeDisallowedNode(currentNode, tagName, root);
44895
+ if (removed === false) {
44896
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
44897
+ if (_handleHookDetachedNode(currentNode, root)) return true;
44898
+ }
44899
+ return removed;
44900
+ }
44901
+ if (_readNodeType(currentNode) === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
44902
+ _forceRemove(currentNode);
44903
+ return true;
44904
+ }
44905
+ if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
44906
+ _forceRemove(currentNode);
44907
+ return true;
44908
+ }
44909
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
44910
+ const content = _stripTemplateExpressions(currentNode.textContent);
44911
+ if (currentNode.textContent !== content) {
44912
+ arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
44913
+ currentNode.textContent = content;
44914
+ }
44915
+ }
44916
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
44917
+ return _handleHookDetachedNode(currentNode, root);
44918
+ };
44919
+ /**
44920
+ * _isValidAttribute
44921
+ *
44922
+ * @param lcTag Lowercase tag name of containing element.
44923
+ * @param lcName Lowercase attribute name.
44924
+ * @param value Attribute value.
44925
+ * @return Returns true if `value` is valid, otherwise false.
44926
+ */
44927
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
44928
+ if (FORBID_ATTR[lcName]) return false;
44929
+ if (_isPatchLinkageAttribute(lcName, lcTag)) return false;
44930
+ if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document || value in formElement)) return false;
44931
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
44932
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) return true;
44933
+ if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) return true;
44934
+ if (!nameIsPermitted) return _isBasicCustomElement(lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName, lcTag) || lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value);
44935
+ if (URI_SAFE_ATTRIBUTES[lcName]) return true;
44936
+ if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
44937
+ if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) return true;
44938
+ if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
44939
+ return !value;
44940
+ };
44941
+ const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, [
44942
+ "annotation-xml",
44943
+ "color-profile",
44944
+ "font-face",
44945
+ "font-face-format",
44946
+ "font-face-name",
44947
+ "font-face-src",
44948
+ "font-face-uri",
44949
+ "missing-glyph"
44950
+ ]);
44951
+ /**
44952
+ * _isBasicCustomElement
44953
+ * checks if at least one dash is included in tagName, and it's not the first char
44954
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
44955
+ *
44956
+ * @param tagName name of the tag of the node to sanitize
44957
+ * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
44958
+ */
44959
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
44960
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
44961
+ };
44962
+ /**
44963
+ * Wrap an attribute value in the matching Trusted Types object when
44964
+ * the active policy requires it. Namespaced attributes pass through
44965
+ * unchanged (no TT support yet, see
44966
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
44967
+ *
44968
+ * @param lcTag lowercase tag name of the containing element
44969
+ * @param lcName lowercase attribute name
44970
+ * @param namespaceURI the attribute's namespace, if any
44971
+ * @param value the attribute value to wrap
44972
+ * @return the value, wrapped when Trusted Types demand it
44973
+ */
44974
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
44975
+ if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function" && !namespaceURI) switch (trustedTypes.getAttributeType(lcTag, lcName)) {
44976
+ case "TrustedHTML": return _createTrustedHTML(value);
44977
+ case "TrustedScriptURL": return _createTrustedScriptURL(value);
44978
+ }
44979
+ return value;
44980
+ };
44981
+ /**
44982
+ * Write a modified attribute value back onto the element. On
44983
+ * success, re-probe for clobbering introduced by the new value and
44984
+ * remove the element when found; otherwise, when this writeback is the
44985
+ * recreate half of the SANITIZE_NAMED_PROPS remove-and-recreate, pop the
44986
+ * removal entry that path recorded so it does not show as removed. On
44987
+ * failure, remove the attribute instead.
44988
+ *
44989
+ * Returns true only on a clean write (the value was set and the new value
44990
+ * introduced no clobbering). The caller uses that, together with its own
44991
+ * knowledge of whether this attribute pushed a DOMPurify.removed record, to
44992
+ * decide whether to pop that record. The pop must happen ONLY for the
44993
+ * named-prop remove-and-recreate; popping on any other value change (trim,
44994
+ * template scrubbing, Trusted Types) would consume an unrelated _forceRemove
44995
+ * subtree-cleanup record and let that detached subtree keep a live event
44996
+ * handler through the IN_PLACE neutralization pass (SO-001).
44997
+ *
44998
+ * @param currentNode the element carrying the attribute
44999
+ * @param name the attribute name as present on the element
45000
+ * @param namespaceURI the attribute's namespace, if any
45001
+ * @param value the new attribute value
45002
+ * @return true if the value was written without introducing clobbering
45003
+ */
45004
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
45005
+ try {
45006
+ if (namespaceURI) currentNode.setAttributeNS(namespaceURI, name, value);
45007
+ else currentNode.setAttribute(name, value);
45008
+ if (_isClobbered(currentNode)) {
45009
+ _forceRemove(currentNode);
45010
+ return false;
45011
+ }
45012
+ return true;
45013
+ } catch (_) {
45014
+ _removeAttribute(name, currentNode);
45015
+ return false;
45016
+ }
45017
+ };
45018
+ /**
45019
+ * _isUnsafeAttributeValue
45020
+ *
45021
+ * Value-based attribute checks that the attribute walk applies before any
45022
+ * hook can force-keep an attribute, shared with the public
45023
+ * isValidAttribute() so that it never approves a value sanitize() would
45024
+ * strip.
45025
+ *
45026
+ * @param name the attribute name as found on the node (case preserved)
45027
+ * @param value the attribute value
45028
+ * @returns true if the attribute must be removed because of its value
45029
+ */
45030
+ const _isUnsafeAttributeValue = function _isUnsafeAttributeValue(name, value) {
45031
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) return true;
45032
+ return stringToLowerCase(name) === "attributename" && stringMatch(value, "href") !== null;
45033
+ };
45034
+ /**
45035
+ * _sanitizeAttributes
45036
+ *
45037
+ * @protect attributes
45038
+ * @protect nodeName
45039
+ * @protect removeAttribute
45040
+ * @protect setAttribute
45041
+ *
45042
+ * @param currentNode to sanitize
45043
+ * @param root the current walk root
45044
+ */
45045
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode, root) {
45046
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
45047
+ if (_handleHookDetachedNode(currentNode, root)) return;
45048
+ const attributes = currentNode.attributes;
45049
+ if (!attributes || _isClobbered(currentNode)) return;
45050
+ ALLOWED_ATTR = _forkSharedAllowlist(hooks.uponSanitizeAttribute, ALLOWED_ATTR, DEFAULT_ALLOWED_ATTR, SET_CONFIG_ALLOWED_ATTR);
45051
+ const hookEvent = {
45052
+ attrName: "",
45053
+ attrValue: "",
45054
+ keepAttr: true,
45055
+ allowedAttributes: ALLOWED_ATTR,
45056
+ forceKeepAttr: void 0
45057
+ };
45058
+ let l = attributes.length;
45059
+ const lcTag = transformCaseFunc(currentNode.nodeName);
45060
+ while (l--) {
45061
+ const attr = attributes[l];
45062
+ const name = attr.name, namespaceURI = attr.namespaceURI, attrValue = attr.value;
45063
+ const lcName = transformCaseFunc(name);
45064
+ const initValue = attrValue;
45065
+ let value = name === "value" ? initValue : stringTrim(initValue);
45066
+ let recreatedNamedProp = false;
45067
+ hookEvent.attrName = lcName;
45068
+ hookEvent.attrValue = value;
45069
+ hookEvent.keepAttr = true;
45070
+ hookEvent.forceKeepAttr = void 0;
45071
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
45072
+ value = hookEvent.attrValue;
45073
+ if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name") && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
45074
+ _removeAttribute(name, currentNode, attr);
45075
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
45076
+ recreatedNamedProp = true;
45077
+ }
45078
+ if (_isUnsafeAttributeValue(name, value)) {
45079
+ _removeAttribute(name, currentNode, attr);
45080
+ continue;
45081
+ }
45082
+ if (hookEvent.forceKeepAttr) continue;
45083
+ if (!hookEvent.keepAttr) {
45084
+ _removeAttribute(name, currentNode, attr);
45085
+ continue;
45086
+ }
45087
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
45088
+ _removeAttribute(name, currentNode, attr);
45089
+ continue;
45090
+ }
45091
+ if (SAFE_FOR_TEMPLATES) value = _stripTemplateExpressions(value);
45092
+ if (!_isValidAttribute(lcTag, lcName, value)) {
45093
+ _removeAttribute(name, currentNode, attr);
45094
+ continue;
45095
+ }
45096
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
45097
+ if (value !== initValue) {
45098
+ if (_setAttributeValue(currentNode, name, namespaceURI, value) && recreatedNamedProp) arrayPop(DOMPurify.removed);
45099
+ }
45100
+ }
45101
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
45102
+ _handleHookDetachedNode(currentNode, root);
45103
+ };
45104
+ /**
45105
+ * _sanitizeShadowDOM
45106
+ *
45107
+ * @param fragment to iterate over recursively
45108
+ */
45109
+ const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
45110
+ let shadowNode = null;
45111
+ const shadowIterator = _createNodeIterator(fragment);
45112
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
45113
+ while (shadowNode = shadowIterator.nextNode()) {
45114
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
45115
+ _sanitizeElements(shadowNode, fragment);
45116
+ _sanitizeAttributes(shadowNode, fragment);
45117
+ if (_isDocumentFragment(shadowNode.content)) _sanitizeShadowDOM2(shadowNode.content);
45118
+ if (_readNodeType(shadowNode) === NODE_TYPE.element) {
45119
+ const innerSr = getShadowRoot(shadowNode);
45120
+ if (_isDocumentFragment(innerSr)) {
45121
+ _sanitizeAttachedShadowRoots(innerSr);
45122
+ _sanitizeShadowDOM2(innerSr);
45123
+ }
45124
+ }
45125
+ }
45126
+ if (SAFE_FOR_TEMPLATES) _scrubOwnCharacterData(fragment);
45127
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
45128
+ };
45129
+ /**
45130
+ * Sanitizes every attached shadow root under `root`, since the node
45131
+ * iterator does not enter shadow trees. Needed for IN_PLACE input and for
45132
+ * DOM input whose clonable shadow roots were copied by importNode().
45133
+ *
45134
+ * @param root the subtree root to walk for attached shadow roots
45135
+ */
45136
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
45137
+ const stack = [{
45138
+ node: root,
45139
+ shadow: null
45140
+ }];
45141
+ while (stack.length > 0) {
45142
+ const item = stack.pop();
45143
+ if (item.shadow) {
45144
+ _sanitizeShadowDOM2(item.shadow);
45145
+ continue;
45146
+ }
45147
+ const node = item.node;
45148
+ const isElement = _readNodeType(node) === NODE_TYPE.element;
45149
+ const childNodes = getChildNodes(node);
45150
+ if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push({
45151
+ node: childNodes[i],
45152
+ shadow: null
45153
+ });
45154
+ if (isElement) {
45155
+ const rootName = getNodeName ? getNodeName(node) : null;
45156
+ if (typeof rootName === "string" && transformCaseFunc(rootName) === "template") {
45157
+ const content = node.content;
45158
+ if (_isDocumentFragment(content)) stack.push({
45159
+ node: content,
45160
+ shadow: null
45161
+ });
45162
+ }
45163
+ }
45164
+ if (isElement) {
45165
+ const sr = getShadowRoot(node);
45166
+ if (_isDocumentFragment(sr)) stack.push({
45167
+ node: null,
45168
+ shadow: sr
45169
+ }, {
45170
+ node: sr,
45171
+ shadow: null
45172
+ });
45173
+ }
45174
+ }
45175
+ };
45176
+ DOMPurify.sanitize = function(dirty) {
45177
+ let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
45178
+ let body = null;
45179
+ let importedNode = null;
45180
+ let currentNode = null;
45181
+ let returnNode = null;
45182
+ IS_EMPTY_INPUT = !dirty;
45183
+ if (IS_EMPTY_INPUT) dirty = "<!-->";
45184
+ if (typeof dirty !== "string" && !_isNode(dirty)) {
45185
+ dirty = stringifyValue(dirty);
45186
+ if (typeof dirty !== "string") throw typeErrorCreate("dirty is not a string, aborting");
45187
+ }
45188
+ if (!DOMPurify.isSupported) return dirty;
45189
+ if (SET_CONFIG) {
45190
+ ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
45191
+ ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
45192
+ } else _parseConfig(cfg);
45193
+ if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) ALLOWED_TAGS = clone(ALLOWED_TAGS);
45194
+ if (hooks.uponSanitizeAttribute.length > 0) ALLOWED_ATTR = clone(ALLOWED_ATTR);
45195
+ DOMPurify.removed = [];
45196
+ const inPlace = IN_PLACE && typeof dirty !== "string" && _isNode(dirty);
45197
+ let inPlaceNodes = [];
45198
+ const outerVisited = IN_PLACE_VISITED;
45199
+ if (inPlace) {
45200
+ _neutralizePatchLinkage(dirty);
45201
+ const nn = _readNodeName(dirty);
45202
+ if (typeof nn === "string") {
45203
+ const tagName = transformCaseFunc(nn);
45204
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
45205
+ _neutralizeRoot(dirty);
45206
+ throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
45207
+ }
45208
+ }
45209
+ if (_isClobbered(dirty)) {
45210
+ _neutralizeRoot(dirty);
45211
+ throw typeErrorCreate("root node is clobbered and cannot be sanitized in-place");
45212
+ }
45213
+ inPlaceNodes = _collectLiveNodes(dirty);
45214
+ IN_PLACE_VISITED = setCreate();
45215
+ } else if (_isNode(dirty)) {
45216
+ body = _initDocument("<!---->");
45217
+ importedNode = body.ownerDocument.importNode(dirty, true);
45218
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") body = importedNode;
45219
+ else if (importedNode.nodeName === "HTML") body = importedNode;
45220
+ else body.appendChild(importedNode);
45221
+ _sanitizeAttachedShadowRoots(body);
45222
+ } else {
45223
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
45224
+ body = _initDocument(dirty);
45225
+ if (!body) return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
45226
+ }
45227
+ if (body && FORCE_BODY) _forceRemove(body.firstChild);
45228
+ const walkRoot = inPlace ? dirty : body;
45229
+ try {
45230
+ if (inPlace) _sanitizeAttachedShadowRoots(dirty);
45231
+ const nodeIterator = _createNodeIterator(walkRoot);
45232
+ while (currentNode = nodeIterator.nextNode()) {
45233
+ _sanitizeElements(currentNode, walkRoot);
45234
+ _sanitizeAttributes(currentNode, walkRoot);
45235
+ if (_isDocumentFragment(currentNode.content)) _sanitizeShadowDOM2(currentNode.content);
45236
+ }
45237
+ if (inPlace) _sanitizeUnvisitedNodes(dirty, inPlaceNodes);
45238
+ } catch (error) {
45239
+ if (inPlace) {
45240
+ _neutralizeRoot(dirty);
45241
+ _neutralizeDiscarded(dirty, inPlaceNodes);
45242
+ }
45243
+ throw error;
45244
+ } finally {
45245
+ IN_PLACE_VISITED = outerVisited;
45246
+ }
45247
+ if (inPlace) {
45248
+ if (_neutralizeDiscarded(dirty, inPlaceNodes)) throw typeErrorCreate("a node selected for removal could not be safely returned; refusing to sanitize in place");
45249
+ if (SAFE_FOR_TEMPLATES) _scrubTemplateExpressions2(dirty);
45250
+ return dirty;
45251
+ }
45252
+ if (RETURN_DOM) {
45253
+ if (SAFE_FOR_TEMPLATES) _scrubTemplateExpressions2(body);
45254
+ if (RETURN_DOM_FRAGMENT) {
45255
+ returnNode = createDocumentFragment.call(body.ownerDocument);
45256
+ while (body.firstChild) returnNode.appendChild(body.firstChild);
45257
+ } else returnNode = body;
45258
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) returnNode = importNode.call(originalDocument, returnNode, true);
45259
+ return returnNode;
45260
+ }
45261
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
45262
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
45263
+ if (SAFE_FOR_TEMPLATES) serializedHTML = _stripTemplateExpressions(serializedHTML);
45264
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
45265
+ };
45266
+ DOMPurify.setConfig = function() {
45267
+ let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
45268
+ _parseConfig(cfg);
45269
+ SET_CONFIG = true;
45270
+ SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
45271
+ SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
45272
+ };
45273
+ DOMPurify.clearConfig = function() {
45274
+ CONFIG = null;
45275
+ SET_CONFIG = false;
45276
+ SET_CONFIG_ALLOWED_TAGS = null;
45277
+ SET_CONFIG_ALLOWED_ATTR = null;
45278
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
45279
+ emptyHTML = "";
45280
+ };
45281
+ DOMPurify.isValidAttribute = function(tag, attr, value) {
45282
+ if (!CONFIG) _parseConfig({});
45283
+ const lcTag = transformCaseFunc(tag);
45284
+ const lcName = transformCaseFunc(attr);
45285
+ if (typeof value === "string" && (_isUnsafeAttributeValue(attr, value) || !ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value))) return false;
45286
+ return _isValidAttribute(lcTag, lcName, value);
45287
+ };
45288
+ DOMPurify.addHook = function(entryPoint, hookFunction) {
45289
+ if (typeof hookFunction !== "function") return;
45290
+ if (!objectHasOwnProperty(hooks, entryPoint)) return;
45291
+ arrayPush(hooks[entryPoint], hookFunction);
45292
+ };
45293
+ DOMPurify.removeHook = function(entryPoint, hookFunction) {
45294
+ if (!objectHasOwnProperty(hooks, entryPoint)) return;
45295
+ if (hookFunction !== void 0) {
45296
+ const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
45297
+ return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
45298
+ }
45299
+ return arrayPop(hooks[entryPoint]);
45300
+ };
45301
+ DOMPurify.removeHooks = function(entryPoint) {
45302
+ if (!objectHasOwnProperty(hooks, entryPoint)) return;
45303
+ hooks[entryPoint] = [];
45304
+ };
45305
+ DOMPurify.removeAllHooks = function() {
45306
+ hooks = _createHooksMap();
45307
+ };
45308
+ return DOMPurify;
45309
+ }
45310
+ return createDOMPurify();
45311
+ });
44380
45312
 
44381
- }));
44382
45313
 
44383
45314
  }(purify));
44384
45315