@everymatrix/nuts-inbox-widget 1.99.57 → 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.
@@ -40738,1565 +40738,2496 @@ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof win
40738
40738
 
40739
40739
  var purify = {exports: {}};
40740
40740
 
40741
- /*! @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 */
40741
+ /*! @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 */
40742
40742
 
40743
40743
  (function (module, exports) {
40744
- (function (global, factory) {
40745
- module.exports = factory() ;
40746
- })(commonjsGlobal, (function () {
40747
- const {
40748
- entries,
40749
- setPrototypeOf,
40750
- isFrozen,
40751
- getPrototypeOf,
40752
- getOwnPropertyDescriptor
40753
- } = Object;
40754
- let {
40755
- freeze,
40756
- seal,
40757
- create
40758
- } = Object; // eslint-disable-line import/no-mutable-exports
40759
- let {
40760
- apply,
40761
- construct
40762
- } = typeof Reflect !== 'undefined' && Reflect;
40763
- if (!freeze) {
40764
- freeze = function freeze(x) {
40765
- return x;
40766
- };
40767
- }
40768
- if (!seal) {
40769
- seal = function seal(x) {
40770
- return x;
40771
- };
40772
- }
40773
- if (!apply) {
40774
- apply = function apply(fun, thisValue, args) {
40775
- return fun.apply(thisValue, args);
40776
- };
40777
- }
40778
- if (!construct) {
40779
- construct = function construct(Func, args) {
40780
- return new Func(...args);
40781
- };
40782
- }
40783
- const arrayForEach = unapply(Array.prototype.forEach);
40784
- const arrayPop = unapply(Array.prototype.pop);
40785
- const arrayPush = unapply(Array.prototype.push);
40786
- const stringToLowerCase = unapply(String.prototype.toLowerCase);
40787
- const stringToString = unapply(String.prototype.toString);
40788
- const stringMatch = unapply(String.prototype.match);
40789
- const stringReplace = unapply(String.prototype.replace);
40790
- const stringIndexOf = unapply(String.prototype.indexOf);
40791
- const stringTrim = unapply(String.prototype.trim);
40792
- const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
40793
- const regExpTest = unapply(RegExp.prototype.test);
40794
- const typeErrorCreate = unconstruct(TypeError);
40795
-
40796
- /**
40797
- * Creates a new function that calls the given function with a specified thisArg and arguments.
40798
- *
40799
- * @param {Function} func - The function to be wrapped and called.
40800
- * @returns {Function} A new function that calls the given function with a specified thisArg and arguments.
40801
- */
40802
- function unapply(func) {
40803
- return function (thisArg) {
40804
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
40805
- args[_key - 1] = arguments[_key];
40806
- }
40807
- return apply(func, thisArg, args);
40808
- };
40809
- }
40810
-
40811
- /**
40812
- * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
40813
- *
40814
- * @param {Function} func - The constructor function to be wrapped and called.
40815
- * @returns {Function} A new function that constructs an instance of the given constructor function with the provided arguments.
40816
- */
40817
- function unconstruct(func) {
40818
- return function () {
40819
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
40820
- args[_key2] = arguments[_key2];
40821
- }
40822
- return construct(func, args);
40823
- };
40824
- }
40825
-
40826
- /**
40827
- * Add properties to a lookup table
40828
- *
40829
- * @param {Object} set - The set to which elements will be added.
40830
- * @param {Array} array - The array containing elements to be added to the set.
40831
- * @param {Function} transformCaseFunc - An optional function to transform the case of each element before adding to the set.
40832
- * @returns {Object} The modified set with added elements.
40833
- */
40834
- function addToSet(set, array) {
40835
- let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
40836
- if (setPrototypeOf) {
40837
- // Make 'in' and truthy checks like Boolean(set.constructor)
40838
- // independent of any properties defined on Object.prototype.
40839
- // Prevent prototype setters from intercepting set as a this value.
40840
- setPrototypeOf(set, null);
40841
- }
40842
- let l = array.length;
40843
- while (l--) {
40844
- let element = array[l];
40845
- if (typeof element === 'string') {
40846
- const lcElement = transformCaseFunc(element);
40847
- if (lcElement !== element) {
40848
- // Config presets (e.g. tags.js, attrs.js) are immutable.
40849
- if (!isFrozen(array)) {
40850
- array[l] = lcElement;
40851
- }
40852
- element = lcElement;
40853
- }
40854
- }
40855
- set[element] = true;
40856
- }
40857
- return set;
40858
- }
40859
-
40860
- /**
40861
- * Clean up an array to harden against CSPP
40862
- *
40863
- * @param {Array} array - The array to be cleaned.
40864
- * @returns {Array} The cleaned version of the array
40865
- */
40866
- function cleanArray(array) {
40867
- for (let index = 0; index < array.length; index++) {
40868
- const isPropertyExist = objectHasOwnProperty(array, index);
40869
- if (!isPropertyExist) {
40870
- array[index] = null;
40871
- }
40872
- }
40873
- return array;
40874
- }
40875
-
40876
- /**
40877
- * Shallow clone an object
40878
- *
40879
- * @param {Object} object - The object to be cloned.
40880
- * @returns {Object} A new object that copies the original.
40881
- */
40882
- function clone(object) {
40883
- const newObject = create(null);
40884
- for (const [property, value] of entries(object)) {
40885
- const isPropertyExist = objectHasOwnProperty(object, property);
40886
- if (isPropertyExist) {
40887
- if (Array.isArray(value)) {
40888
- newObject[property] = cleanArray(value);
40889
- } else if (value && typeof value === 'object' && value.constructor === Object) {
40890
- newObject[property] = clone(value);
40891
- } else {
40892
- newObject[property] = value;
40893
- }
40894
- }
40895
- }
40896
- return newObject;
40897
- }
40898
-
40899
- /**
40900
- * This method automatically checks if the prop is function or getter and behaves accordingly.
40901
- *
40902
- * @param {Object} object - The object to look up the getter function in its prototype chain.
40903
- * @param {String} prop - The property name for which to find the getter function.
40904
- * @returns {Function} The getter function found in the prototype chain or a fallback function.
40905
- */
40906
- function lookupGetter(object, prop) {
40907
- while (object !== null) {
40908
- const desc = getOwnPropertyDescriptor(object, prop);
40909
- if (desc) {
40910
- if (desc.get) {
40911
- return unapply(desc.get);
40912
- }
40913
- if (typeof desc.value === 'function') {
40914
- return unapply(desc.value);
40915
- }
40916
- }
40917
- object = getPrototypeOf(object);
40918
- }
40919
- function fallbackValue() {
40920
- return null;
40921
- }
40922
- return fallbackValue;
40923
- }
40924
-
40925
- 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']);
40926
-
40927
- // SVG
40928
- 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']);
40929
- 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']);
40930
-
40931
- // List of SVG elements that are disallowed by default.
40932
- // We still need to know them so that we can do namespace
40933
- // checks properly in case one wants to add them to
40934
- // allow-list.
40935
- 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']);
40936
- 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']);
40937
-
40938
- // Similarly to SVG, we want to know all MathML elements,
40939
- // even those that we disallow by default.
40940
- const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
40941
- const text = freeze(['#text']);
40942
-
40943
- 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']);
40944
- 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']);
40945
- 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']);
40946
- const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
40947
-
40948
- // eslint-disable-next-line unicorn/better-regex
40949
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
40950
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
40951
- const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
40952
- const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
40953
- const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
40954
- 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
40955
- );
40956
- const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
40957
- const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
40958
- );
40959
- const DOCTYPE_NAME = seal(/^html$/i);
40960
- const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
40961
-
40962
- var EXPRESSIONS = /*#__PURE__*/Object.freeze({
40963
- __proto__: null,
40964
- MUSTACHE_EXPR: MUSTACHE_EXPR,
40965
- ERB_EXPR: ERB_EXPR,
40966
- TMPLIT_EXPR: TMPLIT_EXPR,
40967
- DATA_ATTR: DATA_ATTR,
40968
- ARIA_ATTR: ARIA_ATTR,
40969
- IS_ALLOWED_URI: IS_ALLOWED_URI,
40970
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
40971
- ATTR_WHITESPACE: ATTR_WHITESPACE,
40972
- DOCTYPE_NAME: DOCTYPE_NAME,
40973
- CUSTOM_ELEMENT: CUSTOM_ELEMENT
40974
- });
40975
-
40976
- // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
40977
- const NODE_TYPE = {
40978
- element: 1,
40979
- attribute: 2,
40980
- text: 3,
40981
- cdataSection: 4,
40982
- entityReference: 5,
40983
- // Deprecated
40984
- entityNode: 6,
40985
- // Deprecated
40986
- progressingInstruction: 7,
40987
- comment: 8,
40988
- document: 9,
40989
- documentType: 10,
40990
- documentFragment: 11,
40991
- notation: 12 // Deprecated
40992
- };
40993
- const getGlobal = function getGlobal() {
40994
- return typeof window === 'undefined' ? null : window;
40995
- };
40996
-
40997
- /**
40998
- * Creates a no-op policy for internal use only.
40999
- * Don't export this function outside this module!
41000
- * @param {TrustedTypePolicyFactory} trustedTypes The policy factory.
41001
- * @param {HTMLScriptElement} purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
41002
- * @return {TrustedTypePolicy} The policy created (or null, if Trusted Types
41003
- * are not supported or creating the policy failed).
41004
- */
41005
- const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
41006
- if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
41007
- return null;
41008
- }
41009
-
41010
- // Allow the callers to control the unique policy name
41011
- // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
41012
- // Policy creation with duplicate names throws in Trusted Types.
41013
- let suffix = null;
41014
- const ATTR_NAME = 'data-tt-policy-suffix';
41015
- if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
41016
- suffix = purifyHostElement.getAttribute(ATTR_NAME);
41017
- }
41018
- const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
41019
- try {
41020
- return trustedTypes.createPolicy(policyName, {
41021
- createHTML(html) {
41022
- return html;
41023
- },
41024
- createScriptURL(scriptUrl) {
41025
- return scriptUrl;
41026
- }
41027
- });
41028
- } catch (_) {
41029
- // Policy creation failed (most likely another DOMPurify script has
41030
- // already run). Skip creating the policy, as this will only cause errors
41031
- // if TT are enforced.
41032
- console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
41033
- return null;
41034
- }
41035
- };
41036
- function createDOMPurify() {
41037
- let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
41038
- const DOMPurify = root => createDOMPurify(root);
41039
-
41040
- /**
41041
- * Version label, exposed for easier checks
41042
- * if DOMPurify is up to date or not
41043
- */
41044
- DOMPurify.version = '3.1.6';
41045
-
41046
- /**
41047
- * Array of elements that DOMPurify removed during sanitation.
41048
- * Empty if nothing was removed.
41049
- */
41050
- DOMPurify.removed = [];
41051
- if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document) {
41052
- // Not running in a browser, provide a factory function
41053
- // so that you can pass your own Window
41054
- DOMPurify.isSupported = false;
41055
- return DOMPurify;
41056
- }
41057
- let {
41058
- document
41059
- } = window;
41060
- const originalDocument = document;
41061
- const currentScript = originalDocument.currentScript;
41062
- const {
41063
- DocumentFragment,
41064
- HTMLTemplateElement,
41065
- Node,
41066
- Element,
41067
- NodeFilter,
41068
- NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
41069
- HTMLFormElement,
41070
- DOMParser,
41071
- trustedTypes
41072
- } = window;
41073
- const ElementPrototype = Element.prototype;
41074
- const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
41075
- const remove = lookupGetter(ElementPrototype, 'remove');
41076
- const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
41077
- const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
41078
- const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
41079
-
41080
- // As per issue #47, the web-components registry is inherited by a
41081
- // new document created via createHTMLDocument. As per the spec
41082
- // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
41083
- // a new empty registry is used when creating a template contents owner
41084
- // document, so we use that as our parent document to ensure nothing
41085
- // is inherited.
41086
- if (typeof HTMLTemplateElement === 'function') {
41087
- const template = document.createElement('template');
41088
- if (template.content && template.content.ownerDocument) {
41089
- document = template.content.ownerDocument;
41090
- }
41091
- }
41092
- let trustedTypesPolicy;
41093
- let emptyHTML = '';
41094
- const {
41095
- implementation,
41096
- createNodeIterator,
41097
- createDocumentFragment,
41098
- getElementsByTagName
41099
- } = document;
41100
- const {
41101
- importNode
41102
- } = originalDocument;
41103
- let hooks = {};
41104
-
41105
- /**
41106
- * Expose whether this browser supports running the full DOMPurify.
41107
- */
41108
- DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
41109
- const {
41110
- MUSTACHE_EXPR,
41111
- ERB_EXPR,
41112
- TMPLIT_EXPR,
41113
- DATA_ATTR,
41114
- ARIA_ATTR,
41115
- IS_SCRIPT_OR_DATA,
41116
- ATTR_WHITESPACE,
41117
- CUSTOM_ELEMENT
41118
- } = EXPRESSIONS;
41119
- let {
41120
- IS_ALLOWED_URI: IS_ALLOWED_URI$1
41121
- } = EXPRESSIONS;
41122
-
41123
- /**
41124
- * We consider the elements and attributes below to be safe. Ideally
41125
- * don't add any new ones but feel free to remove unwanted ones.
41126
- */
41127
-
41128
- /* allowed element names */
41129
- let ALLOWED_TAGS = null;
41130
- const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
41131
-
41132
- /* Allowed attribute names */
41133
- let ALLOWED_ATTR = null;
41134
- const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
41135
-
41136
- /*
41137
- * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
41138
- * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
41139
- * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
41140
- * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
41141
- */
41142
- let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
41143
- tagNameCheck: {
41144
- writable: true,
41145
- configurable: false,
41146
- enumerable: true,
41147
- value: null
41148
- },
41149
- attributeNameCheck: {
41150
- writable: true,
41151
- configurable: false,
41152
- enumerable: true,
41153
- value: null
41154
- },
41155
- allowCustomizedBuiltInElements: {
41156
- writable: true,
41157
- configurable: false,
41158
- enumerable: true,
41159
- value: false
41160
- }
41161
- }));
41162
-
41163
- /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
41164
- let FORBID_TAGS = null;
41165
-
41166
- /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
41167
- let FORBID_ATTR = null;
41168
-
41169
- /* Decide if ARIA attributes are okay */
41170
- let ALLOW_ARIA_ATTR = true;
41171
-
41172
- /* Decide if custom data attributes are okay */
41173
- let ALLOW_DATA_ATTR = true;
41174
-
41175
- /* Decide if unknown protocols are okay */
41176
- let ALLOW_UNKNOWN_PROTOCOLS = false;
41177
-
41178
- /* Decide if self-closing tags in attributes are allowed.
41179
- * Usually removed due to a mXSS issue in jQuery 3.0 */
41180
- let ALLOW_SELF_CLOSE_IN_ATTR = true;
41181
-
41182
- /* Output should be safe for common template engines.
41183
- * This means, DOMPurify removes data attributes, mustaches and ERB
41184
- */
41185
- let SAFE_FOR_TEMPLATES = false;
41186
-
41187
- /* Output should be safe even for XML used within HTML and alike.
41188
- * This means, DOMPurify removes comments when containing risky content.
41189
- */
41190
- let SAFE_FOR_XML = true;
41191
-
41192
- /* Decide if document with <html>... should be returned */
41193
- let WHOLE_DOCUMENT = false;
41194
-
41195
- /* Track whether config is already set on this instance of DOMPurify. */
41196
- let SET_CONFIG = false;
41197
-
41198
- /* Decide if all elements (e.g. style, script) must be children of
41199
- * document.body. By default, browsers might move them to document.head */
41200
- let FORCE_BODY = false;
41201
-
41202
- /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
41203
- * string (or a TrustedHTML object if Trusted Types are supported).
41204
- * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
41205
- */
41206
- let RETURN_DOM = false;
41207
-
41208
- /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
41209
- * string (or a TrustedHTML object if Trusted Types are supported) */
41210
- let RETURN_DOM_FRAGMENT = false;
41211
-
41212
- /* Try to return a Trusted Type object instead of a string, return a string in
41213
- * case Trusted Types are not supported */
41214
- let RETURN_TRUSTED_TYPE = false;
41215
-
41216
- /* Output should be free from DOM clobbering attacks?
41217
- * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
41218
- */
41219
- let SANITIZE_DOM = true;
41220
-
41221
- /* Achieve full DOM Clobbering protection by isolating the namespace of named
41222
- * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
41223
- *
41224
- * HTML/DOM spec rules that enable DOM Clobbering:
41225
- * - Named Access on Window (§7.3.3)
41226
- * - DOM Tree Accessors (§3.1.5)
41227
- * - Form Element Parent-Child Relations (§4.10.3)
41228
- * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
41229
- * - HTMLCollection (§4.2.10.2)
41230
- *
41231
- * Namespace isolation is implemented by prefixing `id` and `name` attributes
41232
- * with a constant string, i.e., `user-content-`
41233
- */
41234
- let SANITIZE_NAMED_PROPS = false;
41235
- const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
41236
-
41237
- /* Keep element content when removing element? */
41238
- let KEEP_CONTENT = true;
41239
-
41240
- /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
41241
- * of importing it into a new Document and returning a sanitized copy */
41242
- let IN_PLACE = false;
41243
-
41244
- /* Allow usage of profiles like html, svg and mathMl */
41245
- let USE_PROFILES = {};
41246
-
41247
- /* Tags to ignore content of when KEEP_CONTENT is true */
41248
- let FORBID_CONTENTS = null;
41249
- 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']);
41250
-
41251
- /* Tags that are safe for data: URIs */
41252
- let DATA_URI_TAGS = null;
41253
- const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
41254
-
41255
- /* Attributes safe for values like "javascript:" */
41256
- let URI_SAFE_ATTRIBUTES = null;
41257
- const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
41258
- const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
41259
- const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
41260
- const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
41261
- /* Document namespace */
41262
- let NAMESPACE = HTML_NAMESPACE;
41263
- let IS_EMPTY_INPUT = false;
41264
-
41265
- /* Allowed XHTML+XML namespaces */
41266
- let ALLOWED_NAMESPACES = null;
41267
- const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
41268
-
41269
- /* Parsing of strict XHTML documents */
41270
- let PARSER_MEDIA_TYPE = null;
41271
- const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
41272
- const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
41273
- let transformCaseFunc = null;
41274
-
41275
- /* Keep a reference to config to pass to hooks */
41276
- let CONFIG = null;
41277
-
41278
- /* Ideally, do not touch anything below this line */
41279
- /* ______________________________________________ */
41280
-
41281
- const formElement = document.createElement('form');
41282
- const isRegexOrFunction = function isRegexOrFunction(testValue) {
41283
- return testValue instanceof RegExp || testValue instanceof Function;
41284
- };
41285
-
41286
- /**
41287
- * _parseConfig
41288
- *
41289
- * @param {Object} cfg optional config literal
41290
- */
41291
- // eslint-disable-next-line complexity
41292
- const _parseConfig = function _parseConfig() {
41293
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
41294
- if (CONFIG && CONFIG === cfg) {
41295
- return;
41296
- }
41297
-
41298
- /* Shield configuration object from tampering */
41299
- if (!cfg || typeof cfg !== 'object') {
41300
- cfg = {};
41301
- }
41302
-
41303
- /* Shield configuration object from prototype pollution */
41304
- cfg = clone(cfg);
41305
- PARSER_MEDIA_TYPE =
41306
- // eslint-disable-next-line unicorn/prefer-includes
41307
- SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
41308
-
41309
- // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
41310
- transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
41311
-
41312
- /* Set configuration parameters */
41313
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
41314
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
41315
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
41316
- URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES),
41317
- // eslint-disable-line indent
41318
- cfg.ADD_URI_SAFE_ATTR,
41319
- // eslint-disable-line indent
41320
- transformCaseFunc // eslint-disable-line indent
41321
- ) // eslint-disable-line indent
41322
- : DEFAULT_URI_SAFE_ATTRIBUTES;
41323
- DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS),
41324
- // eslint-disable-line indent
41325
- cfg.ADD_DATA_URI_TAGS,
41326
- // eslint-disable-line indent
41327
- transformCaseFunc // eslint-disable-line indent
41328
- ) // eslint-disable-line indent
41329
- : DEFAULT_DATA_URI_TAGS;
41330
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
41331
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
41332
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
41333
- USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
41334
- ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
41335
- ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
41336
- ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
41337
- ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
41338
- SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
41339
- SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
41340
- WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
41341
- RETURN_DOM = cfg.RETURN_DOM || false; // Default false
41342
- RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
41343
- RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
41344
- FORCE_BODY = cfg.FORCE_BODY || false; // Default false
41345
- SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
41346
- SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
41347
- KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
41348
- IN_PLACE = cfg.IN_PLACE || false; // Default false
41349
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
41350
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
41351
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
41352
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
41353
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
41354
- }
41355
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
41356
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
41357
- }
41358
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
41359
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
41360
- }
41361
- if (SAFE_FOR_TEMPLATES) {
41362
- ALLOW_DATA_ATTR = false;
41363
- }
41364
- if (RETURN_DOM_FRAGMENT) {
41365
- RETURN_DOM = true;
41366
- }
41367
-
41368
- /* Parse profile info */
41369
- if (USE_PROFILES) {
41370
- ALLOWED_TAGS = addToSet({}, text);
41371
- ALLOWED_ATTR = [];
41372
- if (USE_PROFILES.html === true) {
41373
- addToSet(ALLOWED_TAGS, html$1);
41374
- addToSet(ALLOWED_ATTR, html);
41375
- }
41376
- if (USE_PROFILES.svg === true) {
41377
- addToSet(ALLOWED_TAGS, svg$1);
41378
- addToSet(ALLOWED_ATTR, svg);
41379
- addToSet(ALLOWED_ATTR, xml);
41380
- }
41381
- if (USE_PROFILES.svgFilters === true) {
41382
- addToSet(ALLOWED_TAGS, svgFilters);
41383
- addToSet(ALLOWED_ATTR, svg);
41384
- addToSet(ALLOWED_ATTR, xml);
41385
- }
41386
- if (USE_PROFILES.mathMl === true) {
41387
- addToSet(ALLOWED_TAGS, mathMl$1);
41388
- addToSet(ALLOWED_ATTR, mathMl);
41389
- addToSet(ALLOWED_ATTR, xml);
41390
- }
41391
- }
41392
-
41393
- /* Merge configuration parameters */
41394
- if (cfg.ADD_TAGS) {
41395
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
41396
- ALLOWED_TAGS = clone(ALLOWED_TAGS);
41397
- }
41398
- addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
41399
- }
41400
- if (cfg.ADD_ATTR) {
41401
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
41402
- ALLOWED_ATTR = clone(ALLOWED_ATTR);
41403
- }
41404
- addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
41405
- }
41406
- if (cfg.ADD_URI_SAFE_ATTR) {
41407
- addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
41408
- }
41409
- if (cfg.FORBID_CONTENTS) {
41410
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
41411
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
41412
- }
41413
- addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
41414
- }
41415
-
41416
- /* Add #text in case KEEP_CONTENT is set to true */
41417
- if (KEEP_CONTENT) {
41418
- ALLOWED_TAGS['#text'] = true;
41419
- }
41420
-
41421
- /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
41422
- if (WHOLE_DOCUMENT) {
41423
- addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
41424
- }
41425
-
41426
- /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
41427
- if (ALLOWED_TAGS.table) {
41428
- addToSet(ALLOWED_TAGS, ['tbody']);
41429
- delete FORBID_TAGS.tbody;
41430
- }
41431
- if (cfg.TRUSTED_TYPES_POLICY) {
41432
- if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
41433
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
41434
- }
41435
- if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
41436
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
41437
- }
41438
-
41439
- // Overwrite existing TrustedTypes policy.
41440
- trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
41441
-
41442
- // Sign local variables required by `sanitize`.
41443
- emptyHTML = trustedTypesPolicy.createHTML('');
41444
- } else {
41445
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
41446
- if (trustedTypesPolicy === undefined) {
41447
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
41448
- }
41449
-
41450
- // If creating the internal policy succeeded sign internal variables.
41451
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
41452
- emptyHTML = trustedTypesPolicy.createHTML('');
41453
- }
41454
- }
41455
-
41456
- // Prevent further manipulation of configuration.
41457
- // Not available in IE8, Safari 5, etc.
41458
- if (freeze) {
41459
- freeze(cfg);
41460
- }
41461
- CONFIG = cfg;
41462
- };
41463
- const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
41464
- const HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'annotation-xml']);
41465
-
41466
- // Certain elements are allowed in both SVG and HTML
41467
- // namespace. We need to specify them explicitly
41468
- // so that they don't get erroneously deleted from
41469
- // HTML namespace.
41470
- const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
41471
-
41472
- /* Keep track of all possible SVG and MathML tags
41473
- * so that we can perform the namespace checks
41474
- * correctly. */
41475
- const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
41476
- const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
41477
-
41478
- /**
41479
- * @param {Element} element a DOM element whose namespace is being checked
41480
- * @returns {boolean} Return false if the element has a
41481
- * namespace that a spec-compliant parser would never
41482
- * return. Return true otherwise.
41483
- */
41484
- const _checkValidNamespace = function _checkValidNamespace(element) {
41485
- let parent = getParentNode(element);
41486
-
41487
- // In JSDOM, if we're inside shadow DOM, then parentNode
41488
- // can be null. We just simulate parent in this case.
41489
- if (!parent || !parent.tagName) {
41490
- parent = {
41491
- namespaceURI: NAMESPACE,
41492
- tagName: 'template'
41493
- };
41494
- }
41495
- const tagName = stringToLowerCase(element.tagName);
41496
- const parentTagName = stringToLowerCase(parent.tagName);
41497
- if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
41498
- return false;
41499
- }
41500
- if (element.namespaceURI === SVG_NAMESPACE) {
41501
- // The only way to switch from HTML namespace to SVG
41502
- // is via <svg>. If it happens via any other tag, then
41503
- // it should be killed.
41504
- if (parent.namespaceURI === HTML_NAMESPACE) {
41505
- return tagName === 'svg';
41506
- }
41507
-
41508
- // The only way to switch from MathML to SVG is via`
41509
- // svg if parent is either <annotation-xml> or MathML
41510
- // text integration points.
41511
- if (parent.namespaceURI === MATHML_NAMESPACE) {
41512
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
41513
- }
41514
-
41515
- // We only allow elements that are defined in SVG
41516
- // spec. All others are disallowed in SVG namespace.
41517
- return Boolean(ALL_SVG_TAGS[tagName]);
41518
- }
41519
- if (element.namespaceURI === MATHML_NAMESPACE) {
41520
- // The only way to switch from HTML namespace to MathML
41521
- // is via <math>. If it happens via any other tag, then
41522
- // it should be killed.
41523
- if (parent.namespaceURI === HTML_NAMESPACE) {
41524
- return tagName === 'math';
41525
- }
41526
-
41527
- // The only way to switch from SVG to MathML is via
41528
- // <math> and HTML integration points
41529
- if (parent.namespaceURI === SVG_NAMESPACE) {
41530
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
41531
- }
41532
-
41533
- // We only allow elements that are defined in MathML
41534
- // spec. All others are disallowed in MathML namespace.
41535
- return Boolean(ALL_MATHML_TAGS[tagName]);
41536
- }
41537
- if (element.namespaceURI === HTML_NAMESPACE) {
41538
- // The only way to switch from SVG to HTML is via
41539
- // HTML integration points, and from MathML to HTML
41540
- // is via MathML text integration points
41541
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
41542
- return false;
41543
- }
41544
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
41545
- return false;
41546
- }
41547
-
41548
- // We disallow tags that are specific for MathML
41549
- // or SVG and should never appear in HTML namespace
41550
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
41551
- }
41552
-
41553
- // For XHTML and XML documents that support custom namespaces
41554
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
41555
- return true;
41556
- }
41557
-
41558
- // The code should never reach this place (this means
41559
- // that the element somehow got namespace that is not
41560
- // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
41561
- // Return false just in case.
41562
- return false;
41563
- };
41564
-
41565
- /**
41566
- * _forceRemove
41567
- *
41568
- * @param {Node} node a DOM node
41569
- */
41570
- const _forceRemove = function _forceRemove(node) {
41571
- arrayPush(DOMPurify.removed, {
41572
- element: node
41573
- });
41574
- try {
41575
- // eslint-disable-next-line unicorn/prefer-dom-node-remove
41576
- getParentNode(node).removeChild(node);
41577
- } catch (_) {
41578
- remove(node);
41579
- }
41580
- };
41581
-
41582
- /**
41583
- * _removeAttribute
41584
- *
41585
- * @param {String} name an Attribute name
41586
- * @param {Node} node a DOM node
41587
- */
41588
- const _removeAttribute = function _removeAttribute(name, node) {
41589
- try {
41590
- arrayPush(DOMPurify.removed, {
41591
- attribute: node.getAttributeNode(name),
41592
- from: node
41593
- });
41594
- } catch (_) {
41595
- arrayPush(DOMPurify.removed, {
41596
- attribute: null,
41597
- from: node
41598
- });
41599
- }
41600
- node.removeAttribute(name);
41601
-
41602
- // We void attribute values for unremovable "is"" attributes
41603
- if (name === 'is' && !ALLOWED_ATTR[name]) {
41604
- if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
41605
- try {
41606
- _forceRemove(node);
41607
- } catch (_) {}
41608
- } else {
41609
- try {
41610
- node.setAttribute(name, '');
41611
- } catch (_) {}
41612
- }
41613
- }
41614
- };
41615
-
41616
- /**
41617
- * _initDocument
41618
- *
41619
- * @param {String} dirty a string of dirty markup
41620
- * @return {Document} a DOM, filled with the dirty markup
41621
- */
41622
- const _initDocument = function _initDocument(dirty) {
41623
- /* Create a HTML document */
41624
- let doc = null;
41625
- let leadingWhitespace = null;
41626
- if (FORCE_BODY) {
41627
- dirty = '<remove></remove>' + dirty;
41628
- } else {
41629
- /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
41630
- const matches = stringMatch(dirty, /^[\r\n\t ]+/);
41631
- leadingWhitespace = matches && matches[0];
41632
- }
41633
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
41634
- // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
41635
- dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
41636
- }
41637
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
41638
- /*
41639
- * Use the DOMParser API by default, fallback later if needs be
41640
- * DOMParser not work for svg when has multiple root element.
41641
- */
41642
- if (NAMESPACE === HTML_NAMESPACE) {
41643
- try {
41644
- doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
41645
- } catch (_) {}
41646
- }
41647
-
41648
- /* Use createHTMLDocument in case DOMParser is not available */
41649
- if (!doc || !doc.documentElement) {
41650
- doc = implementation.createDocument(NAMESPACE, 'template', null);
41651
- try {
41652
- doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
41653
- } catch (_) {
41654
- // Syntax error if dirtyPayload is invalid xml
41655
- }
41656
- }
41657
- const body = doc.body || doc.documentElement;
41658
- if (dirty && leadingWhitespace) {
41659
- body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
41660
- }
41661
-
41662
- /* Work on whole document or just its body */
41663
- if (NAMESPACE === HTML_NAMESPACE) {
41664
- return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
41665
- }
41666
- return WHOLE_DOCUMENT ? doc.documentElement : body;
41667
- };
41668
-
41669
- /**
41670
- * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
41671
- *
41672
- * @param {Node} root The root element or node to start traversing on.
41673
- * @return {NodeIterator} The created NodeIterator
41674
- */
41675
- const _createNodeIterator = function _createNodeIterator(root) {
41676
- return createNodeIterator.call(root.ownerDocument || root, root,
41677
- // eslint-disable-next-line no-bitwise
41678
- NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
41679
- };
41680
-
41681
- /**
41682
- * _isClobbered
41683
- *
41684
- * @param {Node} elm element to check for clobbering attacks
41685
- * @return {Boolean} true if clobbered, false if safe
41686
- */
41687
- const _isClobbered = function _isClobbered(elm) {
41688
- 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');
41689
- };
41690
-
41691
- /**
41692
- * Checks whether the given object is a DOM node.
41693
- *
41694
- * @param {Node} object object to check whether it's a DOM node
41695
- * @return {Boolean} true is object is a DOM node
41696
- */
41697
- const _isNode = function _isNode(object) {
41698
- return typeof Node === 'function' && object instanceof Node;
41699
- };
41700
-
41701
- /**
41702
- * _executeHook
41703
- * Execute user configurable hooks
41704
- *
41705
- * @param {String} entryPoint Name of the hook's entry point
41706
- * @param {Node} currentNode node to work on with the hook
41707
- * @param {Object} data additional hook parameters
41708
- */
41709
- const _executeHook = function _executeHook(entryPoint, currentNode, data) {
41710
- if (!hooks[entryPoint]) {
41711
- return;
41712
- }
41713
- arrayForEach(hooks[entryPoint], hook => {
41714
- hook.call(DOMPurify, currentNode, data, CONFIG);
41715
- });
41716
- };
41717
-
41718
- /**
41719
- * _sanitizeElements
41720
- *
41721
- * @protect nodeName
41722
- * @protect textContent
41723
- * @protect removeChild
41724
- *
41725
- * @param {Node} currentNode to check for permission to exist
41726
- * @return {Boolean} true if node was killed, false if left alive
41727
- */
41728
- const _sanitizeElements = function _sanitizeElements(currentNode) {
41729
- let content = null;
41730
-
41731
- /* Execute a hook if present */
41732
- _executeHook('beforeSanitizeElements', currentNode, null);
41733
-
41734
- /* Check if element is clobbered or can clobber */
41735
- if (_isClobbered(currentNode)) {
41736
- _forceRemove(currentNode);
41737
- return true;
41738
- }
41739
-
41740
- /* Now let's check the element's type and name */
41741
- const tagName = transformCaseFunc(currentNode.nodeName);
41742
-
41743
- /* Execute a hook if present */
41744
- _executeHook('uponSanitizeElement', currentNode, {
41745
- tagName,
41746
- allowedTags: ALLOWED_TAGS
41747
- });
41748
-
41749
- /* Detect mXSS attempts abusing namespace confusion */
41750
- if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
41751
- _forceRemove(currentNode);
41752
- return true;
41753
- }
41754
-
41755
- /* Remove any occurrence of processing instructions */
41756
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
41757
- _forceRemove(currentNode);
41758
- return true;
41759
- }
41760
-
41761
- /* Remove any kind of possibly harmful comments */
41762
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
41763
- _forceRemove(currentNode);
41764
- return true;
41765
- }
41766
-
41767
- /* Remove element if anything forbids its presence */
41768
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
41769
- /* Check if we have a custom element to handle */
41770
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
41771
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
41772
- return false;
41773
- }
41774
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
41775
- return false;
41776
- }
41777
- }
41778
-
41779
- /* Keep content except for bad-listed elements */
41780
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
41781
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
41782
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
41783
- if (childNodes && parentNode) {
41784
- const childCount = childNodes.length;
41785
- for (let i = childCount - 1; i >= 0; --i) {
41786
- const childClone = cloneNode(childNodes[i], true);
41787
- childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
41788
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
41789
- }
41790
- }
41791
- }
41792
- _forceRemove(currentNode);
41793
- return true;
41794
- }
41795
-
41796
- /* Check whether element has a valid namespace */
41797
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
41798
- _forceRemove(currentNode);
41799
- return true;
41800
- }
41801
-
41802
- /* Make sure that older browsers don't get fallback-tag mXSS */
41803
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
41804
- _forceRemove(currentNode);
41805
- return true;
41806
- }
41807
-
41808
- /* Sanitize element content to be template-safe */
41809
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
41810
- /* Get the element's text content */
41811
- content = currentNode.textContent;
41812
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
41813
- content = stringReplace(content, expr, ' ');
41814
- });
41815
- if (currentNode.textContent !== content) {
41816
- arrayPush(DOMPurify.removed, {
41817
- element: currentNode.cloneNode()
41818
- });
41819
- currentNode.textContent = content;
41820
- }
41821
- }
41822
-
41823
- /* Execute a hook if present */
41824
- _executeHook('afterSanitizeElements', currentNode, null);
41825
- return false;
41826
- };
41827
-
41828
- /**
41829
- * _isValidAttribute
41830
- *
41831
- * @param {string} lcTag Lowercase tag name of containing element.
41832
- * @param {string} lcName Lowercase attribute name.
41833
- * @param {string} value Attribute value.
41834
- * @return {Boolean} Returns true if `value` is valid, otherwise false.
41835
- */
41836
- // eslint-disable-next-line complexity
41837
- const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
41838
- /* Make sure attribute cannot clobber */
41839
- if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
41840
- return false;
41841
- }
41842
-
41843
- /* Allow valid data-* attributes: At least one character after "-"
41844
- (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
41845
- XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
41846
- We don't need to check the value; it's always URI safe. */
41847
- 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]) {
41848
- if (
41849
- // First condition does a very basic check if a) it's basically a valid custom element tagname AND
41850
- // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
41851
- // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
41852
- _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)) ||
41853
- // Alternative, second condition checks if it's an `is`-attribute, AND
41854
- // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
41855
- 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 {
41856
- return false;
41857
- }
41858
- /* Check value is safe. First, is attr inert? If so, is safe */
41859
- } 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) {
41860
- return false;
41861
- } else ;
41862
- return true;
41863
- };
41864
-
41865
- /**
41866
- * _isBasicCustomElement
41867
- * checks if at least one dash is included in tagName, and it's not the first char
41868
- * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
41869
- *
41870
- * @param {string} tagName name of the tag of the node to sanitize
41871
- * @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
41872
- */
41873
- const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
41874
- return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
41875
- };
41876
-
41877
- /**
41878
- * _sanitizeAttributes
41879
- *
41880
- * @protect attributes
41881
- * @protect nodeName
41882
- * @protect removeAttribute
41883
- * @protect setAttribute
41884
- *
41885
- * @param {Node} currentNode to sanitize
41886
- */
41887
- const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
41888
- /* Execute a hook if present */
41889
- _executeHook('beforeSanitizeAttributes', currentNode, null);
41890
- const {
41891
- attributes
41892
- } = currentNode;
41893
-
41894
- /* Check if we have attributes; if not we might have a text node */
41895
- if (!attributes) {
41896
- return;
41897
- }
41898
- const hookEvent = {
41899
- attrName: '',
41900
- attrValue: '',
41901
- keepAttr: true,
41902
- allowedAttributes: ALLOWED_ATTR
41903
- };
41904
- let l = attributes.length;
41905
-
41906
- /* Go backwards over all attributes; safely remove bad ones */
41907
- while (l--) {
41908
- const attr = attributes[l];
41909
- const {
41910
- name,
41911
- namespaceURI,
41912
- value: attrValue
41913
- } = attr;
41914
- const lcName = transformCaseFunc(name);
41915
- let value = name === 'value' ? attrValue : stringTrim(attrValue);
41916
-
41917
- /* Execute a hook if present */
41918
- hookEvent.attrName = lcName;
41919
- hookEvent.attrValue = value;
41920
- hookEvent.keepAttr = true;
41921
- hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
41922
- _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
41923
- value = hookEvent.attrValue;
41924
-
41925
- /* Work around a security issue with comments inside attributes */
41926
- if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
41927
- _removeAttribute(name, currentNode);
41928
- continue;
41929
- }
41930
-
41931
- /* Did the hooks approve of the attribute? */
41932
- if (hookEvent.forceKeepAttr) {
41933
- continue;
41934
- }
41935
-
41936
- /* Remove attribute */
41937
- _removeAttribute(name, currentNode);
41938
-
41939
- /* Did the hooks approve of the attribute? */
41940
- if (!hookEvent.keepAttr) {
41941
- continue;
41942
- }
41943
-
41944
- /* Work around a security issue in jQuery 3.0 */
41945
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
41946
- _removeAttribute(name, currentNode);
41947
- continue;
41948
- }
41949
-
41950
- /* Sanitize attribute content to be template-safe */
41951
- if (SAFE_FOR_TEMPLATES) {
41952
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
41953
- value = stringReplace(value, expr, ' ');
41954
- });
41955
- }
41956
-
41957
- /* Is `value` valid for this attribute? */
41958
- const lcTag = transformCaseFunc(currentNode.nodeName);
41959
- if (!_isValidAttribute(lcTag, lcName, value)) {
41960
- continue;
41961
- }
41962
-
41963
- /* Full DOM Clobbering protection via namespace isolation,
41964
- * Prefix id and name attributes with `user-content-`
41965
- */
41966
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
41967
- // Remove the attribute with this value
41968
- _removeAttribute(name, currentNode);
41969
-
41970
- // Prefix the value and later re-create the attribute with the sanitized value
41971
- value = SANITIZE_NAMED_PROPS_PREFIX + value;
41972
- }
41973
-
41974
- /* Handle attributes that require Trusted Types */
41975
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
41976
- if (namespaceURI) ; else {
41977
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
41978
- case 'TrustedHTML':
41979
- {
41980
- value = trustedTypesPolicy.createHTML(value);
41981
- break;
41982
- }
41983
- case 'TrustedScriptURL':
41984
- {
41985
- value = trustedTypesPolicy.createScriptURL(value);
41986
- break;
41987
- }
41988
- }
41989
- }
41990
- }
41991
-
41992
- /* Handle invalid data-* attribute set by try-catching it */
41993
- try {
41994
- if (namespaceURI) {
41995
- currentNode.setAttributeNS(namespaceURI, name, value);
41996
- } else {
41997
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
41998
- currentNode.setAttribute(name, value);
41999
- }
42000
- if (_isClobbered(currentNode)) {
42001
- _forceRemove(currentNode);
42002
- } else {
42003
- arrayPop(DOMPurify.removed);
42004
- }
42005
- } catch (_) {}
42006
- }
42007
-
42008
- /* Execute a hook if present */
42009
- _executeHook('afterSanitizeAttributes', currentNode, null);
42010
- };
42011
-
42012
- /**
42013
- * _sanitizeShadowDOM
42014
- *
42015
- * @param {DocumentFragment} fragment to iterate over recursively
42016
- */
42017
- const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
42018
- let shadowNode = null;
42019
- const shadowIterator = _createNodeIterator(fragment);
42020
-
42021
- /* Execute a hook if present */
42022
- _executeHook('beforeSanitizeShadowDOM', fragment, null);
42023
- while (shadowNode = shadowIterator.nextNode()) {
42024
- /* Execute a hook if present */
42025
- _executeHook('uponSanitizeShadowNode', shadowNode, null);
42026
-
42027
- /* Sanitize tags and elements */
42028
- if (_sanitizeElements(shadowNode)) {
42029
- continue;
42030
- }
42031
-
42032
- /* Deep shadow DOM detected */
42033
- if (shadowNode.content instanceof DocumentFragment) {
42034
- _sanitizeShadowDOM(shadowNode.content);
42035
- }
42036
-
42037
- /* Check attributes, sanitize if necessary */
42038
- _sanitizeAttributes(shadowNode);
42039
- }
42040
-
42041
- /* Execute a hook if present */
42042
- _executeHook('afterSanitizeShadowDOM', fragment, null);
42043
- };
42044
-
42045
- /**
42046
- * Sanitize
42047
- * Public method providing core sanitation functionality
42048
- *
42049
- * @param {String|Node} dirty string or DOM node
42050
- * @param {Object} cfg object
42051
- */
42052
- // eslint-disable-next-line complexity
42053
- DOMPurify.sanitize = function (dirty) {
42054
- let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
42055
- let body = null;
42056
- let importedNode = null;
42057
- let currentNode = null;
42058
- let returnNode = null;
42059
- /* Make sure we have a string to sanitize.
42060
- DO NOT return early, as this will return the wrong type if
42061
- the user has requested a DOM object rather than a string */
42062
- IS_EMPTY_INPUT = !dirty;
42063
- if (IS_EMPTY_INPUT) {
42064
- dirty = '<!-->';
42065
- }
42066
-
42067
- /* Stringify, in case dirty is an object */
42068
- if (typeof dirty !== 'string' && !_isNode(dirty)) {
42069
- if (typeof dirty.toString === 'function') {
42070
- dirty = dirty.toString();
42071
- if (typeof dirty !== 'string') {
42072
- throw typeErrorCreate('dirty is not a string, aborting');
42073
- }
42074
- } else {
42075
- throw typeErrorCreate('toString is not a function');
42076
- }
42077
- }
42078
-
42079
- /* Return dirty HTML if DOMPurify cannot run */
42080
- if (!DOMPurify.isSupported) {
42081
- return dirty;
42082
- }
42083
-
42084
- /* Assign config vars */
42085
- if (!SET_CONFIG) {
42086
- _parseConfig(cfg);
42087
- }
42088
-
42089
- /* Clean up removed elements */
42090
- DOMPurify.removed = [];
42091
-
42092
- /* Check if dirty is correctly typed for IN_PLACE */
42093
- if (typeof dirty === 'string') {
42094
- IN_PLACE = false;
42095
- }
42096
- if (IN_PLACE) {
42097
- /* Do some early pre-sanitization to avoid unsafe root nodes */
42098
- if (dirty.nodeName) {
42099
- const tagName = transformCaseFunc(dirty.nodeName);
42100
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
42101
- throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
42102
- }
42103
- }
42104
- } else if (dirty instanceof Node) {
42105
- /* If dirty is a DOM element, append to an empty document to avoid
42106
- elements being stripped by the parser */
42107
- body = _initDocument('<!---->');
42108
- importedNode = body.ownerDocument.importNode(dirty, true);
42109
- if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
42110
- /* Node is already a body, use as is */
42111
- body = importedNode;
42112
- } else if (importedNode.nodeName === 'HTML') {
42113
- body = importedNode;
42114
- } else {
42115
- // eslint-disable-next-line unicorn/prefer-dom-node-append
42116
- body.appendChild(importedNode);
42117
- }
42118
- } else {
42119
- /* Exit directly if we have nothing to do */
42120
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
42121
- // eslint-disable-next-line unicorn/prefer-includes
42122
- dirty.indexOf('<') === -1) {
42123
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
42124
- }
42125
-
42126
- /* Initialize the document to work on */
42127
- body = _initDocument(dirty);
42128
-
42129
- /* Check we have a DOM node from the data */
42130
- if (!body) {
42131
- return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
42132
- }
42133
- }
42134
-
42135
- /* Remove first element node (ours) if FORCE_BODY is set */
42136
- if (body && FORCE_BODY) {
42137
- _forceRemove(body.firstChild);
42138
- }
42139
-
42140
- /* Get node iterator */
42141
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
42142
-
42143
- /* Now start iterating over the created document */
42144
- while (currentNode = nodeIterator.nextNode()) {
42145
- /* Sanitize tags and elements */
42146
- if (_sanitizeElements(currentNode)) {
42147
- continue;
42148
- }
42149
-
42150
- /* Shadow DOM detected, sanitize it */
42151
- if (currentNode.content instanceof DocumentFragment) {
42152
- _sanitizeShadowDOM(currentNode.content);
42153
- }
42154
-
42155
- /* Check attributes, sanitize if necessary */
42156
- _sanitizeAttributes(currentNode);
42157
- }
42158
-
42159
- /* If we sanitized `dirty` in-place, return it. */
42160
- if (IN_PLACE) {
42161
- return dirty;
42162
- }
42163
-
42164
- /* Return sanitized string or DOM */
42165
- if (RETURN_DOM) {
42166
- if (RETURN_DOM_FRAGMENT) {
42167
- returnNode = createDocumentFragment.call(body.ownerDocument);
42168
- while (body.firstChild) {
42169
- // eslint-disable-next-line unicorn/prefer-dom-node-append
42170
- returnNode.appendChild(body.firstChild);
42171
- }
42172
- } else {
42173
- returnNode = body;
42174
- }
42175
- if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
42176
- /*
42177
- AdoptNode() is not used because internal state is not reset
42178
- (e.g. the past names map of a HTMLFormElement), this is safe
42179
- in theory but we would rather not risk another attack vector.
42180
- The state that is cloned by importNode() is explicitly defined
42181
- by the specs.
42182
- */
42183
- returnNode = importNode.call(originalDocument, returnNode, true);
42184
- }
42185
- return returnNode;
42186
- }
42187
- let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
42188
-
42189
- /* Serialize doctype if allowed */
42190
- if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
42191
- serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
42192
- }
42193
-
42194
- /* Sanitize final string template-safe */
42195
- if (SAFE_FOR_TEMPLATES) {
42196
- arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
42197
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
42198
- });
42199
- }
42200
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
42201
- };
42202
-
42203
- /**
42204
- * Public method to set the configuration once
42205
- * setConfig
42206
- *
42207
- * @param {Object} cfg configuration object
42208
- */
42209
- DOMPurify.setConfig = function () {
42210
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
42211
- _parseConfig(cfg);
42212
- SET_CONFIG = true;
42213
- };
42214
-
42215
- /**
42216
- * Public method to remove the configuration
42217
- * clearConfig
42218
- *
42219
- */
42220
- DOMPurify.clearConfig = function () {
42221
- CONFIG = null;
42222
- SET_CONFIG = false;
42223
- };
42224
-
42225
- /**
42226
- * Public method to check if an attribute value is valid.
42227
- * Uses last set config, if any. Otherwise, uses config defaults.
42228
- * isValidAttribute
42229
- *
42230
- * @param {String} tag Tag name of containing element.
42231
- * @param {String} attr Attribute name.
42232
- * @param {String} value Attribute value.
42233
- * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
42234
- */
42235
- DOMPurify.isValidAttribute = function (tag, attr, value) {
42236
- /* Initialize shared config vars if necessary. */
42237
- if (!CONFIG) {
42238
- _parseConfig({});
42239
- }
42240
- const lcTag = transformCaseFunc(tag);
42241
- const lcName = transformCaseFunc(attr);
42242
- return _isValidAttribute(lcTag, lcName, value);
42243
- };
42244
-
42245
- /**
42246
- * AddHook
42247
- * Public method to add DOMPurify hooks
42248
- *
42249
- * @param {String} entryPoint entry point for the hook to add
42250
- * @param {Function} hookFunction function to execute
42251
- */
42252
- DOMPurify.addHook = function (entryPoint, hookFunction) {
42253
- if (typeof hookFunction !== 'function') {
42254
- return;
42255
- }
42256
- hooks[entryPoint] = hooks[entryPoint] || [];
42257
- arrayPush(hooks[entryPoint], hookFunction);
42258
- };
42259
-
42260
- /**
42261
- * RemoveHook
42262
- * Public method to remove a DOMPurify hook at a given entryPoint
42263
- * (pops it from the stack of hooks if more are present)
42264
- *
42265
- * @param {String} entryPoint entry point for the hook to remove
42266
- * @return {Function} removed(popped) hook
42267
- */
42268
- DOMPurify.removeHook = function (entryPoint) {
42269
- if (hooks[entryPoint]) {
42270
- return arrayPop(hooks[entryPoint]);
42271
- }
42272
- };
42273
-
42274
- /**
42275
- * RemoveHooks
42276
- * Public method to remove all DOMPurify hooks at a given entryPoint
42277
- *
42278
- * @param {String} entryPoint entry point for the hooks to remove
42279
- */
42280
- DOMPurify.removeHooks = function (entryPoint) {
42281
- if (hooks[entryPoint]) {
42282
- hooks[entryPoint] = [];
42283
- }
42284
- };
42285
-
42286
- /**
42287
- * RemoveAllHooks
42288
- * Public method to remove all DOMPurify hooks
42289
- */
42290
- DOMPurify.removeAllHooks = function () {
42291
- hooks = {};
42292
- };
42293
- return DOMPurify;
42294
- }
42295
- var purify = createDOMPurify();
42296
-
42297
- return purify;
40744
+ (function(global, factory) {
40745
+ module.exports = factory() ;
40746
+ })(commonjsGlobal, function() {
40747
+ function _arrayLikeToArray(r, a) {
40748
+ (null == a || a > r.length) && (a = r.length);
40749
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
40750
+ return n;
40751
+ }
40752
+ function _arrayWithHoles(r) {
40753
+ if (Array.isArray(r)) return r;
40754
+ }
40755
+ function _iterableToArrayLimit(r, l) {
40756
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
40757
+ if (null != t) {
40758
+ var e, n, i, u, a = [], f = !0, o = !1;
40759
+ try {
40760
+ if (i = (t = t.call(r)).next, 0 === l) {
40761
+ if (Object(t) !== t) return;
40762
+ f = !1;
40763
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
40764
+ } catch (r) {
40765
+ o = !0, n = r;
40766
+ } finally {
40767
+ try {
40768
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
40769
+ } finally {
40770
+ if (o) throw n;
40771
+ }
40772
+ }
40773
+ return a;
40774
+ }
40775
+ }
40776
+ function _nonIterableRest() {
40777
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
40778
+ }
40779
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
40780
+ function _slicedToArray(r, e) {
40781
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
40782
+ }
40783
+ function _unsupportedIterableToArray(r, a) {
40784
+ if (r) {
40785
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
40786
+ var t = {}.toString.call(r).slice(8, -1);
40787
+ 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;
40788
+ }
40789
+ }
40790
+ const entries = Object.entries;
40791
+ const setPrototypeOf = Object.setPrototypeOf;
40792
+ const isFrozen = Object.isFrozen;
40793
+ const getPrototypeOf = Object.getPrototypeOf;
40794
+ const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
40795
+ let freeze = Object.freeze;
40796
+ let seal = Object.seal;
40797
+ let create = Object.create;
40798
+ let _ref = typeof Reflect !== "undefined" && Reflect;
40799
+ let apply = _ref.apply;
40800
+ let construct = _ref.construct;
40801
+ if (!freeze) freeze = function freeze(x) {
40802
+ return x;
40803
+ };
40804
+ if (!seal) seal = function seal(x) {
40805
+ return x;
40806
+ };
40807
+ if (!apply) apply = function apply(func, thisArg) {
40808
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) args[_key - 2] = arguments[_key];
40809
+ return func.apply(thisArg, args);
40810
+ };
40811
+ if (!construct) construct = function construct(Func) {
40812
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) args[_key2 - 1] = arguments[_key2];
40813
+ return new Func(...args);
40814
+ };
40815
+ const arrayForEach = unapply(Array.prototype.forEach);
40816
+ const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
40817
+ const arrayPop = unapply(Array.prototype.pop);
40818
+ const arrayPush = unapply(Array.prototype.push);
40819
+ const arraySlice = unapply(Array.prototype.slice);
40820
+ const arraySplice = unapply(Array.prototype.splice);
40821
+ const arrayIsArray = Array.isArray;
40822
+ const setCreate = unconstruct(Set);
40823
+ const setAdd = unapply(Set.prototype.add);
40824
+ const setHas = unapply(Set.prototype.has);
40825
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
40826
+ const stringToString = unapply(String.prototype.toString);
40827
+ const stringMatch = unapply(String.prototype.match);
40828
+ const stringReplace = unapply(String.prototype.replace);
40829
+ const stringIndexOf = unapply(String.prototype.indexOf);
40830
+ const stringTrim = unapply(String.prototype.trim);
40831
+ const numberToString = unapply(Number.prototype.toString);
40832
+ const booleanToString = unapply(Boolean.prototype.toString);
40833
+ const bigintToString = typeof BigInt === "undefined" ? null : unapply(BigInt.prototype.toString);
40834
+ const symbolToString = typeof Symbol === "undefined" ? null : unapply(Symbol.prototype.toString);
40835
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
40836
+ const objectToString = unapply(Object.prototype.toString);
40837
+ const regExpTest = unapply(RegExp.prototype.test);
40838
+ const typeErrorCreate = unconstruct(TypeError);
40839
+ /**
40840
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
40841
+ *
40842
+ * @param func - The function to be wrapped and called.
40843
+ * @returns A new function that calls the given function with a specified thisArg and arguments.
40844
+ */
40845
+ function unapply(func) {
40846
+ return function(thisArg) {
40847
+ if (thisArg instanceof RegExp) thisArg.lastIndex = 0;
40848
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) args[_key3 - 1] = arguments[_key3];
40849
+ return apply(func, thisArg, args);
40850
+ };
40851
+ }
40852
+ /**
40853
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
40854
+ *
40855
+ * @param func - The constructor function to be wrapped and called.
40856
+ * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
40857
+ */
40858
+ function unconstruct(Func) {
40859
+ return function() {
40860
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) args[_key4] = arguments[_key4];
40861
+ return construct(Func, args);
40862
+ };
40863
+ }
40864
+ /**
40865
+ * Add properties to a lookup table
40866
+ *
40867
+ * @param set - The set to which elements will be added.
40868
+ * @param array - The array containing elements to be added to the set.
40869
+ * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
40870
+ * @returns The modified set with added elements.
40871
+ */
40872
+ function addToSet(set, array) {
40873
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
40874
+ if (setPrototypeOf) setPrototypeOf(set, null);
40875
+ if (!arrayIsArray(array)) return set;
40876
+ let l = array.length;
40877
+ while (l--) {
40878
+ let element = array[l];
40879
+ if (typeof element === "string") {
40880
+ const lcElement = transformCaseFunc(element);
40881
+ if (lcElement !== element) {
40882
+ if (!isFrozen(array)) array[l] = lcElement;
40883
+ element = lcElement;
40884
+ }
40885
+ }
40886
+ set[element] = true;
40887
+ }
40888
+ return set;
40889
+ }
40890
+ /**
40891
+ * Clean up an array to harden against CSPP
40892
+ *
40893
+ * @param array - The array to be cleaned.
40894
+ * @returns The cleaned version of the array
40895
+ */
40896
+ function cleanArray(array) {
40897
+ for (let index = 0; index < array.length; index++) if (!objectHasOwnProperty(array, index)) array[index] = null;
40898
+ return array;
40899
+ }
40900
+ /**
40901
+ * Shallow clone an object
40902
+ *
40903
+ * @param object - The object to be cloned.
40904
+ * @returns A new object that copies the original.
40905
+ */
40906
+ function clone(object) {
40907
+ const newObject = create(null);
40908
+ for (const _ref2 of entries(object)) {
40909
+ var _ref3 = _slicedToArray(_ref2, 2);
40910
+ const property = _ref3[0];
40911
+ const value = _ref3[1];
40912
+ if (objectHasOwnProperty(object, property)) {
40913
+ if (arrayIsArray(value)) newObject[property] = cleanArray(value);
40914
+ else if (value && typeof value === "object" && value.constructor === Object) newObject[property] = clone(value);
40915
+ else newObject[property] = value;
40916
+ }
40917
+ }
40918
+ return newObject;
40919
+ }
40920
+ /**
40921
+ * Convert non-node values into strings without depending on direct property access.
40922
+ *
40923
+ * @param value - The value to stringify.
40924
+ * @returns A string representation of the provided value.
40925
+ */
40926
+ function stringifyValue(value) {
40927
+ switch (typeof value) {
40928
+ case "string": return value;
40929
+ case "number": return numberToString(value);
40930
+ case "boolean": return booleanToString(value);
40931
+ case "bigint": return bigintToString ? bigintToString(value) : "0";
40932
+ case "symbol": return symbolToString ? symbolToString(value) : "Symbol()";
40933
+ case "undefined": return objectToString(value);
40934
+ case "function":
40935
+ case "object": {
40936
+ if (value === null) return objectToString(value);
40937
+ const valueAsRecord = value;
40938
+ const valueToString = lookupGetter(valueAsRecord, "toString");
40939
+ if (typeof valueToString === "function") {
40940
+ const stringified = valueToString(valueAsRecord);
40941
+ return typeof stringified === "string" ? stringified : objectToString(stringified);
40942
+ }
40943
+ return objectToString(value);
40944
+ }
40945
+ default: return objectToString(value);
40946
+ }
40947
+ }
40948
+ /**
40949
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
40950
+ *
40951
+ * @param object - The object to look up the getter function in its prototype chain.
40952
+ * @param prop - The property name for which to find the getter function.
40953
+ * @returns The getter function found in the prototype chain or a fallback function.
40954
+ */
40955
+ function lookupGetter(object, prop) {
40956
+ while (object !== null) {
40957
+ const desc = getOwnPropertyDescriptor(object, prop);
40958
+ if (desc) {
40959
+ if (desc.get) return unapply(desc.get);
40960
+ if (typeof desc.value === "function") return unapply(desc.value);
40961
+ }
40962
+ object = getPrototypeOf(object);
40963
+ }
40964
+ function fallbackValue() {
40965
+ return null;
40966
+ }
40967
+ return fallbackValue;
40968
+ }
40969
+ /**
40970
+ * Like lookupGetter, but for accessor properties only, and returns null
40971
+ * instead of a null-returning fallback when no getter exists on the chain.
40972
+ * Lets a caller fall back to a direct property read in environments that
40973
+ * lack the getter, where a fallback returning null would be indistinguishable
40974
+ * from a legitimate null value (e.g. namespaceURI of a no-namespace element).
40975
+ *
40976
+ * @param object - The object (usually a prototype) to start the lookup at.
40977
+ * @param prop - The accessor property name.
40978
+ * @returns The unapplied getter, or null if none was found.
40979
+ */
40980
+ function lookupAccessor(object, prop) {
40981
+ while (object !== null) {
40982
+ const desc = getOwnPropertyDescriptor(object, prop);
40983
+ if (desc) return desc.get ? unapply(desc.get) : null;
40984
+ object = getPrototypeOf(object);
40985
+ }
40986
+ return null;
40987
+ }
40988
+ function isRegex(value) {
40989
+ try {
40990
+ regExpTest(value, "");
40991
+ return true;
40992
+ } catch (_unused) {
40993
+ return false;
40994
+ }
40995
+ }
40996
+ const html$1 = freeze([
40997
+ "a",
40998
+ "abbr",
40999
+ "acronym",
41000
+ "address",
41001
+ "area",
41002
+ "article",
41003
+ "aside",
41004
+ "audio",
41005
+ "b",
41006
+ "bdi",
41007
+ "bdo",
41008
+ "big",
41009
+ "blink",
41010
+ "blockquote",
41011
+ "body",
41012
+ "br",
41013
+ "button",
41014
+ "canvas",
41015
+ "caption",
41016
+ "center",
41017
+ "cite",
41018
+ "code",
41019
+ "col",
41020
+ "colgroup",
41021
+ "content",
41022
+ "data",
41023
+ "datalist",
41024
+ "dd",
41025
+ "decorator",
41026
+ "del",
41027
+ "details",
41028
+ "dfn",
41029
+ "dialog",
41030
+ "dir",
41031
+ "div",
41032
+ "dl",
41033
+ "dt",
41034
+ "element",
41035
+ "em",
41036
+ "fieldset",
41037
+ "figcaption",
41038
+ "figure",
41039
+ "font",
41040
+ "footer",
41041
+ "form",
41042
+ "h1",
41043
+ "h2",
41044
+ "h3",
41045
+ "h4",
41046
+ "h5",
41047
+ "h6",
41048
+ "head",
41049
+ "header",
41050
+ "hgroup",
41051
+ "hr",
41052
+ "html",
41053
+ "i",
41054
+ "img",
41055
+ "input",
41056
+ "ins",
41057
+ "kbd",
41058
+ "label",
41059
+ "legend",
41060
+ "li",
41061
+ "main",
41062
+ "map",
41063
+ "mark",
41064
+ "marquee",
41065
+ "menu",
41066
+ "menuitem",
41067
+ "meter",
41068
+ "nav",
41069
+ "nobr",
41070
+ "ol",
41071
+ "optgroup",
41072
+ "option",
41073
+ "output",
41074
+ "p",
41075
+ "picture",
41076
+ "pre",
41077
+ "progress",
41078
+ "q",
41079
+ "rp",
41080
+ "rt",
41081
+ "ruby",
41082
+ "s",
41083
+ "samp",
41084
+ "search",
41085
+ "section",
41086
+ "select",
41087
+ "shadow",
41088
+ "slot",
41089
+ "small",
41090
+ "source",
41091
+ "spacer",
41092
+ "span",
41093
+ "strike",
41094
+ "strong",
41095
+ "style",
41096
+ "sub",
41097
+ "summary",
41098
+ "sup",
41099
+ "table",
41100
+ "tbody",
41101
+ "td",
41102
+ "template",
41103
+ "textarea",
41104
+ "tfoot",
41105
+ "th",
41106
+ "thead",
41107
+ "time",
41108
+ "tr",
41109
+ "track",
41110
+ "tt",
41111
+ "u",
41112
+ "ul",
41113
+ "var",
41114
+ "video",
41115
+ "wbr"
41116
+ ]);
41117
+ const svg$1 = freeze([
41118
+ "svg",
41119
+ "a",
41120
+ "altglyph",
41121
+ "altglyphdef",
41122
+ "altglyphitem",
41123
+ "animatecolor",
41124
+ "animatemotion",
41125
+ "animatetransform",
41126
+ "circle",
41127
+ "clippath",
41128
+ "defs",
41129
+ "desc",
41130
+ "ellipse",
41131
+ "enterkeyhint",
41132
+ "exportparts",
41133
+ "filter",
41134
+ "font",
41135
+ "g",
41136
+ "glyph",
41137
+ "glyphref",
41138
+ "hkern",
41139
+ "image",
41140
+ "inputmode",
41141
+ "line",
41142
+ "lineargradient",
41143
+ "marker",
41144
+ "mask",
41145
+ "metadata",
41146
+ "mpath",
41147
+ "part",
41148
+ "path",
41149
+ "pattern",
41150
+ "polygon",
41151
+ "polyline",
41152
+ "radialgradient",
41153
+ "rect",
41154
+ "stop",
41155
+ "style",
41156
+ "switch",
41157
+ "symbol",
41158
+ "text",
41159
+ "textpath",
41160
+ "title",
41161
+ "tref",
41162
+ "tspan",
41163
+ "view",
41164
+ "vkern"
41165
+ ]);
41166
+ const svgFilters = freeze([
41167
+ "feBlend",
41168
+ "feColorMatrix",
41169
+ "feComponentTransfer",
41170
+ "feComposite",
41171
+ "feConvolveMatrix",
41172
+ "feDiffuseLighting",
41173
+ "feDisplacementMap",
41174
+ "feDistantLight",
41175
+ "feDropShadow",
41176
+ "feFlood",
41177
+ "feFuncA",
41178
+ "feFuncB",
41179
+ "feFuncG",
41180
+ "feFuncR",
41181
+ "feGaussianBlur",
41182
+ "feImage",
41183
+ "feMerge",
41184
+ "feMergeNode",
41185
+ "feMorphology",
41186
+ "feOffset",
41187
+ "fePointLight",
41188
+ "feSpecularLighting",
41189
+ "feSpotLight",
41190
+ "feTile",
41191
+ "feTurbulence"
41192
+ ]);
41193
+ const svgDisallowed = freeze([
41194
+ "animate",
41195
+ "color-profile",
41196
+ "cursor",
41197
+ "discard",
41198
+ "font-face",
41199
+ "font-face-format",
41200
+ "font-face-name",
41201
+ "font-face-src",
41202
+ "font-face-uri",
41203
+ "foreignobject",
41204
+ "hatch",
41205
+ "hatchpath",
41206
+ "mesh",
41207
+ "meshgradient",
41208
+ "meshpatch",
41209
+ "meshrow",
41210
+ "missing-glyph",
41211
+ "script",
41212
+ "set",
41213
+ "solidcolor",
41214
+ "unknown",
41215
+ "use"
41216
+ ]);
41217
+ const mathMl$1 = freeze([
41218
+ "math",
41219
+ "menclose",
41220
+ "merror",
41221
+ "mfenced",
41222
+ "mfrac",
41223
+ "mglyph",
41224
+ "mi",
41225
+ "mlabeledtr",
41226
+ "mmultiscripts",
41227
+ "mn",
41228
+ "mo",
41229
+ "mover",
41230
+ "mpadded",
41231
+ "mphantom",
41232
+ "mroot",
41233
+ "mrow",
41234
+ "ms",
41235
+ "mspace",
41236
+ "msqrt",
41237
+ "mstyle",
41238
+ "msub",
41239
+ "msup",
41240
+ "msubsup",
41241
+ "mtable",
41242
+ "mtd",
41243
+ "mtext",
41244
+ "mtr",
41245
+ "munder",
41246
+ "munderover",
41247
+ "mprescripts"
41248
+ ]);
41249
+ const mathMlDisallowed = freeze([
41250
+ "maction",
41251
+ "maligngroup",
41252
+ "malignmark",
41253
+ "mlongdiv",
41254
+ "mscarries",
41255
+ "mscarry",
41256
+ "msgroup",
41257
+ "mstack",
41258
+ "msline",
41259
+ "msrow",
41260
+ "semantics",
41261
+ "annotation",
41262
+ "annotation-xml",
41263
+ "mprescripts",
41264
+ "none"
41265
+ ]);
41266
+ const text = freeze(["#text"]);
41267
+ const html = freeze([
41268
+ "accept",
41269
+ "action",
41270
+ "align",
41271
+ "alt",
41272
+ "autocapitalize",
41273
+ "autocomplete",
41274
+ "autopictureinpicture",
41275
+ "autoplay",
41276
+ "background",
41277
+ "bgcolor",
41278
+ "border",
41279
+ "capture",
41280
+ "cellpadding",
41281
+ "cellspacing",
41282
+ "checked",
41283
+ "cite",
41284
+ "class",
41285
+ "clear",
41286
+ "color",
41287
+ "cols",
41288
+ "colspan",
41289
+ "command",
41290
+ "commandfor",
41291
+ "controls",
41292
+ "controlslist",
41293
+ "coords",
41294
+ "crossorigin",
41295
+ "datetime",
41296
+ "decoding",
41297
+ "default",
41298
+ "dir",
41299
+ "disabled",
41300
+ "disablepictureinpicture",
41301
+ "disableremoteplayback",
41302
+ "download",
41303
+ "draggable",
41304
+ "enctype",
41305
+ "enterkeyhint",
41306
+ "exportparts",
41307
+ "face",
41308
+ "for",
41309
+ "headers",
41310
+ "height",
41311
+ "hidden",
41312
+ "high",
41313
+ "href",
41314
+ "hreflang",
41315
+ "id",
41316
+ "inert",
41317
+ "inputmode",
41318
+ "integrity",
41319
+ "ismap",
41320
+ "kind",
41321
+ "label",
41322
+ "lang",
41323
+ "list",
41324
+ "loading",
41325
+ "loop",
41326
+ "low",
41327
+ "max",
41328
+ "maxlength",
41329
+ "media",
41330
+ "method",
41331
+ "min",
41332
+ "minlength",
41333
+ "multiple",
41334
+ "muted",
41335
+ "name",
41336
+ "nonce",
41337
+ "noshade",
41338
+ "novalidate",
41339
+ "nowrap",
41340
+ "open",
41341
+ "optimum",
41342
+ "part",
41343
+ "pattern",
41344
+ "placeholder",
41345
+ "playsinline",
41346
+ "popover",
41347
+ "popovertarget",
41348
+ "popovertargetaction",
41349
+ "poster",
41350
+ "preload",
41351
+ "pubdate",
41352
+ "radiogroup",
41353
+ "readonly",
41354
+ "rel",
41355
+ "required",
41356
+ "rev",
41357
+ "reversed",
41358
+ "role",
41359
+ "rows",
41360
+ "rowspan",
41361
+ "spellcheck",
41362
+ "scope",
41363
+ "selected",
41364
+ "shape",
41365
+ "size",
41366
+ "sizes",
41367
+ "slot",
41368
+ "span",
41369
+ "srclang",
41370
+ "start",
41371
+ "src",
41372
+ "srcset",
41373
+ "step",
41374
+ "style",
41375
+ "summary",
41376
+ "tabindex",
41377
+ "title",
41378
+ "translate",
41379
+ "type",
41380
+ "usemap",
41381
+ "valign",
41382
+ "value",
41383
+ "width",
41384
+ "wrap",
41385
+ "xmlns"
41386
+ ]);
41387
+ const svg = freeze([
41388
+ "accent-height",
41389
+ "accumulate",
41390
+ "additive",
41391
+ "alignment-baseline",
41392
+ "amplitude",
41393
+ "ascent",
41394
+ "attributename",
41395
+ "attributetype",
41396
+ "azimuth",
41397
+ "basefrequency",
41398
+ "baseline-shift",
41399
+ "begin",
41400
+ "bias",
41401
+ "by",
41402
+ "class",
41403
+ "clip",
41404
+ "clippathunits",
41405
+ "clip-path",
41406
+ "clip-rule",
41407
+ "color",
41408
+ "color-interpolation",
41409
+ "color-interpolation-filters",
41410
+ "color-profile",
41411
+ "color-rendering",
41412
+ "cx",
41413
+ "cy",
41414
+ "d",
41415
+ "dx",
41416
+ "dy",
41417
+ "diffuseconstant",
41418
+ "direction",
41419
+ "display",
41420
+ "divisor",
41421
+ "dominant-baseline",
41422
+ "dur",
41423
+ "edgemode",
41424
+ "elevation",
41425
+ "end",
41426
+ "exponent",
41427
+ "fill",
41428
+ "fill-opacity",
41429
+ "fill-rule",
41430
+ "filter",
41431
+ "filterunits",
41432
+ "flood-color",
41433
+ "flood-opacity",
41434
+ "font-family",
41435
+ "font-size",
41436
+ "font-size-adjust",
41437
+ "font-stretch",
41438
+ "font-style",
41439
+ "font-variant",
41440
+ "font-weight",
41441
+ "fx",
41442
+ "fy",
41443
+ "g1",
41444
+ "g2",
41445
+ "glyph-name",
41446
+ "glyphref",
41447
+ "gradientunits",
41448
+ "gradienttransform",
41449
+ "height",
41450
+ "href",
41451
+ "id",
41452
+ "image-rendering",
41453
+ "in",
41454
+ "in2",
41455
+ "intercept",
41456
+ "k",
41457
+ "k1",
41458
+ "k2",
41459
+ "k3",
41460
+ "k4",
41461
+ "kerning",
41462
+ "keypoints",
41463
+ "keysplines",
41464
+ "keytimes",
41465
+ "lang",
41466
+ "lengthadjust",
41467
+ "letter-spacing",
41468
+ "kernelmatrix",
41469
+ "kernelunitlength",
41470
+ "lighting-color",
41471
+ "local",
41472
+ "marker-end",
41473
+ "marker-mid",
41474
+ "marker-start",
41475
+ "markerheight",
41476
+ "markerunits",
41477
+ "markerwidth",
41478
+ "maskcontentunits",
41479
+ "maskunits",
41480
+ "max",
41481
+ "mask",
41482
+ "mask-type",
41483
+ "media",
41484
+ "method",
41485
+ "mode",
41486
+ "min",
41487
+ "name",
41488
+ "numoctaves",
41489
+ "offset",
41490
+ "operator",
41491
+ "opacity",
41492
+ "order",
41493
+ "orient",
41494
+ "orientation",
41495
+ "origin",
41496
+ "overflow",
41497
+ "paint-order",
41498
+ "path",
41499
+ "pathlength",
41500
+ "patterncontentunits",
41501
+ "patterntransform",
41502
+ "patternunits",
41503
+ "pointer-events",
41504
+ "points",
41505
+ "preservealpha",
41506
+ "preserveaspectratio",
41507
+ "primitiveunits",
41508
+ "r",
41509
+ "rx",
41510
+ "ry",
41511
+ "radius",
41512
+ "refx",
41513
+ "refy",
41514
+ "repeatcount",
41515
+ "repeatdur",
41516
+ "restart",
41517
+ "result",
41518
+ "rotate",
41519
+ "scale",
41520
+ "seed",
41521
+ "shape-rendering",
41522
+ "slope",
41523
+ "specularconstant",
41524
+ "specularexponent",
41525
+ "spreadmethod",
41526
+ "startoffset",
41527
+ "stddeviation",
41528
+ "stitchtiles",
41529
+ "stop-color",
41530
+ "stop-opacity",
41531
+ "stroke-dasharray",
41532
+ "stroke-dashoffset",
41533
+ "stroke-linecap",
41534
+ "stroke-linejoin",
41535
+ "stroke-miterlimit",
41536
+ "stroke-opacity",
41537
+ "stroke",
41538
+ "stroke-width",
41539
+ "style",
41540
+ "surfacescale",
41541
+ "systemlanguage",
41542
+ "tabindex",
41543
+ "tablevalues",
41544
+ "targetx",
41545
+ "targety",
41546
+ "transform",
41547
+ "transform-origin",
41548
+ "text-anchor",
41549
+ "text-decoration",
41550
+ "text-orientation",
41551
+ "text-rendering",
41552
+ "textlength",
41553
+ "type",
41554
+ "u1",
41555
+ "u2",
41556
+ "unicode",
41557
+ "values",
41558
+ "vector-effect",
41559
+ "viewbox",
41560
+ "visibility",
41561
+ "version",
41562
+ "vert-adv-y",
41563
+ "vert-origin-x",
41564
+ "vert-origin-y",
41565
+ "width",
41566
+ "word-spacing",
41567
+ "wrap",
41568
+ "writing-mode",
41569
+ "xchannelselector",
41570
+ "ychannelselector",
41571
+ "x",
41572
+ "x1",
41573
+ "x2",
41574
+ "xmlns",
41575
+ "y",
41576
+ "y1",
41577
+ "y2",
41578
+ "z",
41579
+ "zoomandpan"
41580
+ ]);
41581
+ const mathMl = freeze([
41582
+ "accent",
41583
+ "accentunder",
41584
+ "align",
41585
+ "bevelled",
41586
+ "close",
41587
+ "columnalign",
41588
+ "columnlines",
41589
+ "columnspacing",
41590
+ "columnspan",
41591
+ "denomalign",
41592
+ "depth",
41593
+ "dir",
41594
+ "display",
41595
+ "displaystyle",
41596
+ "encoding",
41597
+ "fence",
41598
+ "frame",
41599
+ "height",
41600
+ "href",
41601
+ "id",
41602
+ "largeop",
41603
+ "length",
41604
+ "linethickness",
41605
+ "lquote",
41606
+ "lspace",
41607
+ "mathbackground",
41608
+ "mathcolor",
41609
+ "mathsize",
41610
+ "mathvariant",
41611
+ "maxsize",
41612
+ "minsize",
41613
+ "movablelimits",
41614
+ "notation",
41615
+ "numalign",
41616
+ "open",
41617
+ "rowalign",
41618
+ "rowlines",
41619
+ "rowspacing",
41620
+ "rowspan",
41621
+ "rspace",
41622
+ "rquote",
41623
+ "scriptlevel",
41624
+ "scriptminsize",
41625
+ "scriptsizemultiplier",
41626
+ "selection",
41627
+ "separator",
41628
+ "separators",
41629
+ "stretchy",
41630
+ "subscriptshift",
41631
+ "supscriptshift",
41632
+ "symmetric",
41633
+ "voffset",
41634
+ "width",
41635
+ "xmlns"
41636
+ ]);
41637
+ const xml = freeze([
41638
+ "xlink:href",
41639
+ "xml:id",
41640
+ "xlink:title",
41641
+ "xml:space",
41642
+ "xmlns:xlink"
41643
+ ]);
41644
+ const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
41645
+ const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
41646
+ const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
41647
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
41648
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/);
41649
+ const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
41650
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
41651
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g);
41652
+ const DOCTYPE_NAME = seal(/^html$/i);
41653
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
41654
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
41655
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
41656
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
41657
+ const SELF_CLOSING_TAG = seal(/\/>/i);
41658
+ const NODE_TYPE = {
41659
+ element: 1,
41660
+ attribute: 2,
41661
+ text: 3,
41662
+ cdataSection: 4,
41663
+ entityReference: 5,
41664
+ entityNode: 6,
41665
+ processingInstruction: 7,
41666
+ comment: 8,
41667
+ document: 9,
41668
+ documentType: 10,
41669
+ documentFragment: 11,
41670
+ notation: 12
41671
+ };
41672
+ const LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, [
41673
+ "style",
41674
+ "script",
41675
+ "xmp",
41676
+ "iframe",
41677
+ "noembed",
41678
+ "noframes",
41679
+ "plaintext",
41680
+ "noscript"
41681
+ ]));
41682
+ const getGlobal = function getGlobal() {
41683
+ return typeof window === "undefined" ? null : window;
41684
+ };
41685
+ /**
41686
+ * Creates a no-op policy for internal use only.
41687
+ * Don't export this function outside this module!
41688
+ * @param trustedTypes The policy factory.
41689
+ * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
41690
+ * @return The policy created (or null, if Trusted Types
41691
+ * are not supported or creating the policy failed).
41692
+ */
41693
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
41694
+ if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") return null;
41695
+ let suffix = null;
41696
+ const ATTR_NAME = "data-tt-policy-suffix";
41697
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) suffix = purifyHostElement.getAttribute(ATTR_NAME);
41698
+ const policyName = "dompurify" + (suffix ? "#" + suffix : "");
41699
+ try {
41700
+ return trustedTypes.createPolicy(policyName, {
41701
+ createHTML(html) {
41702
+ return html;
41703
+ },
41704
+ createScriptURL(scriptUrl) {
41705
+ return scriptUrl;
41706
+ }
41707
+ });
41708
+ } catch (_) {
41709
+ console.warn("TrustedTypes policy " + policyName + " could not be created.");
41710
+ return null;
41711
+ }
41712
+ };
41713
+ const _createHooksMap = function _createHooksMap() {
41714
+ return {
41715
+ afterSanitizeAttributes: [],
41716
+ afterSanitizeElements: [],
41717
+ afterSanitizeShadowDOM: [],
41718
+ beforeSanitizeAttributes: [],
41719
+ beforeSanitizeElements: [],
41720
+ beforeSanitizeShadowDOM: [],
41721
+ uponSanitizeAttribute: [],
41722
+ uponSanitizeElement: [],
41723
+ uponSanitizeShadowNode: []
41724
+ };
41725
+ };
41726
+ /**
41727
+ * Resolve a set-valued configuration option: a fresh set built from
41728
+ * cfg[key] when it is an own array property (seeded with a clone of
41729
+ * options.base when given, case-normalized via options.transform),
41730
+ * the fallback set otherwise.
41731
+ *
41732
+ * @param cfg the cloned, prototype-free configuration object
41733
+ * @param key the configuration property to read
41734
+ * @param fallback the set to use when the option is absent or not an array
41735
+ * @param options transform and optional base set to merge into
41736
+ * @returns the resolved set
41737
+ */
41738
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
41739
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
41740
+ };
41741
+ /**
41742
+ * Resolve an object-valued configuration option: a prototype-free clone
41743
+ * of cfg[key] when it is an own, truthy object property, else a fresh
41744
+ * fallback built by makeFallback (fresh on every parse, so a previous
41745
+ * parse can never leak state into the next one).
41746
+ *
41747
+ * @param cfg the cloned, prototype-free configuration object
41748
+ * @param key the configuration property to read
41749
+ * @param makeFallback builds the fallback value when the option is absent
41750
+ * @returns the resolved object
41751
+ */
41752
+ const _resolveObjectOption = function _resolveObjectOption(cfg, key, makeFallback) {
41753
+ const value = objectHasOwnProperty(cfg, key) ? cfg[key] : void 0;
41754
+ return value && typeof value === "object" ? clone(value) : makeFallback();
41755
+ };
41756
+ function createDOMPurify() {
41757
+ let window = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
41758
+ const DOMPurify = (root) => createDOMPurify(root);
41759
+ DOMPurify.version = "3.4.17";
41760
+ DOMPurify.removed = [];
41761
+ if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
41762
+ DOMPurify.isSupported = false;
41763
+ return DOMPurify;
41764
+ }
41765
+ let document = window.document;
41766
+ const originalDocument = document;
41767
+ const currentScript = originalDocument.currentScript;
41768
+ const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter;
41769
+ const DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
41770
+ const ElementPrototype = Element.prototype;
41771
+ const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
41772
+ const remove = lookupGetter(ElementPrototype, "remove");
41773
+ const removeAttributeNode = lookupGetter(ElementPrototype, "removeAttributeNode");
41774
+ const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
41775
+ const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
41776
+ const getParentNode = lookupGetter(ElementPrototype, "parentNode");
41777
+ const getShadowRoot = lookupGetter(ElementPrototype, "shadowRoot");
41778
+ const getAttributes = lookupGetter(ElementPrototype, "attributes");
41779
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeType") : null;
41780
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeName") : null;
41781
+ const getOwnerDocument = Node && Node.prototype ? lookupGetter(Node.prototype, "ownerDocument") : null;
41782
+ const _readNodeType = function _readNodeType(node) {
41783
+ return getNodeType ? getNodeType(node) : node.nodeType;
41784
+ };
41785
+ const _readNodeName = function _readNodeName(node) {
41786
+ return getNodeName ? getNodeName(node) : node.nodeName;
41787
+ };
41788
+ const getNamespaceURI = lookupAccessor(ElementPrototype, "namespaceURI");
41789
+ const _readNamespaceURI = function _readNamespaceURI(element) {
41790
+ return getNamespaceURI ? getNamespaceURI(element) : element.namespaceURI;
41791
+ };
41792
+ if (typeof HTMLTemplateElement === "function") {
41793
+ const template = document.createElement("template");
41794
+ if (template.content && template.content.ownerDocument) document = template.content.ownerDocument;
41795
+ }
41796
+ let trustedTypesPolicy;
41797
+ let emptyHTML = "";
41798
+ let defaultTrustedTypesPolicy;
41799
+ let defaultTrustedTypesPolicyResolved = false;
41800
+ let IN_TRUSTED_TYPES_POLICY = 0;
41801
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
41802
+ 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.");
41803
+ };
41804
+ const _createTrustedHTML = function _createTrustedHTML(html) {
41805
+ _assertNotInTrustedTypesPolicy();
41806
+ IN_TRUSTED_TYPES_POLICY++;
41807
+ try {
41808
+ return trustedTypesPolicy.createHTML(html);
41809
+ } finally {
41810
+ IN_TRUSTED_TYPES_POLICY--;
41811
+ }
41812
+ };
41813
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
41814
+ _assertNotInTrustedTypesPolicy();
41815
+ IN_TRUSTED_TYPES_POLICY++;
41816
+ try {
41817
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
41818
+ } finally {
41819
+ IN_TRUSTED_TYPES_POLICY--;
41820
+ }
41821
+ };
41822
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
41823
+ if (!defaultTrustedTypesPolicyResolved) {
41824
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
41825
+ defaultTrustedTypesPolicyResolved = true;
41826
+ }
41827
+ return defaultTrustedTypesPolicy;
41828
+ };
41829
+ const _document = document, implementation = _document.implementation, createNodeIterator = _document.createNodeIterator, createDocumentFragment = _document.createDocumentFragment, getElementsByTagName = _document.getElementsByTagName;
41830
+ const importNode = originalDocument.importNode;
41831
+ let hooks = _createHooksMap();
41832
+ /**
41833
+ * Expose whether this browser supports running the full DOMPurify.
41834
+ */
41835
+ DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
41836
+ 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;
41837
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
41838
+ /**
41839
+ * We consider the elements and attributes below to be safe. Ideally
41840
+ * don't add any new ones but feel free to remove unwanted ones.
41841
+ */
41842
+ let ALLOWED_TAGS = null;
41843
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [
41844
+ ...html$1,
41845
+ ...svg$1,
41846
+ ...svgFilters,
41847
+ ...mathMl$1,
41848
+ ...text
41849
+ ]);
41850
+ let ALLOWED_ATTR = null;
41851
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [
41852
+ ...html,
41853
+ ...svg,
41854
+ ...mathMl,
41855
+ ...xml
41856
+ ]);
41857
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
41858
+ tagNameCheck: {
41859
+ writable: true,
41860
+ configurable: false,
41861
+ enumerable: true,
41862
+ value: null
41863
+ },
41864
+ attributeNameCheck: {
41865
+ writable: true,
41866
+ configurable: false,
41867
+ enumerable: true,
41868
+ value: null
41869
+ },
41870
+ allowCustomizedBuiltInElements: {
41871
+ writable: true,
41872
+ configurable: false,
41873
+ enumerable: true,
41874
+ value: false
41875
+ }
41876
+ }));
41877
+ let FORBID_TAGS = null;
41878
+ let FORBID_ATTR = null;
41879
+ const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
41880
+ tagCheck: {
41881
+ writable: true,
41882
+ configurable: false,
41883
+ enumerable: true,
41884
+ value: null
41885
+ },
41886
+ attributeCheck: {
41887
+ writable: true,
41888
+ configurable: false,
41889
+ enumerable: true,
41890
+ value: null
41891
+ }
41892
+ }));
41893
+ let ALLOW_ARIA_ATTR = true;
41894
+ let ALLOW_DATA_ATTR = true;
41895
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
41896
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
41897
+ let SAFE_FOR_TEMPLATES = false;
41898
+ let SAFE_FOR_XML = true;
41899
+ let WHOLE_DOCUMENT = false;
41900
+ let SET_CONFIG = false;
41901
+ let SET_CONFIG_ALLOWED_TAGS = null;
41902
+ let SET_CONFIG_ALLOWED_ATTR = null;
41903
+ let FORCE_BODY = false;
41904
+ let RETURN_DOM = false;
41905
+ let RETURN_DOM_FRAGMENT = false;
41906
+ let RETURN_TRUSTED_TYPE = false;
41907
+ let SANITIZE_DOM = true;
41908
+ let SANITIZE_NAMED_PROPS = false;
41909
+ const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
41910
+ let KEEP_CONTENT = true;
41911
+ let IN_PLACE = false;
41912
+ let IN_PLACE_VISITED = null;
41913
+ let USE_PROFILES = {};
41914
+ let FORBID_CONTENTS = null;
41915
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, [
41916
+ "annotation-xml",
41917
+ "audio",
41918
+ "colgroup",
41919
+ "desc",
41920
+ "foreignobject",
41921
+ "head",
41922
+ "iframe",
41923
+ "math",
41924
+ "mi",
41925
+ "mn",
41926
+ "mo",
41927
+ "ms",
41928
+ "mtext",
41929
+ "noembed",
41930
+ "noframes",
41931
+ "noscript",
41932
+ "plaintext",
41933
+ "script",
41934
+ "selectedcontent",
41935
+ "style",
41936
+ "svg",
41937
+ "template",
41938
+ "thead",
41939
+ "title",
41940
+ "video",
41941
+ "xmp"
41942
+ ]);
41943
+ let DATA_URI_TAGS = null;
41944
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, [
41945
+ "audio",
41946
+ "video",
41947
+ "img",
41948
+ "source",
41949
+ "image",
41950
+ "track"
41951
+ ]);
41952
+ let URI_SAFE_ATTRIBUTES = null;
41953
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
41954
+ "alt",
41955
+ "class",
41956
+ "for",
41957
+ "id",
41958
+ "label",
41959
+ "name",
41960
+ "pattern",
41961
+ "placeholder",
41962
+ "role",
41963
+ "summary",
41964
+ "title",
41965
+ "value",
41966
+ "style",
41967
+ "xmlns"
41968
+ ]);
41969
+ const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
41970
+ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
41971
+ const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
41972
+ let NAMESPACE = HTML_NAMESPACE;
41973
+ let IS_EMPTY_INPUT = false;
41974
+ let ALLOWED_NAMESPACES = null;
41975
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [
41976
+ MATHML_NAMESPACE,
41977
+ SVG_NAMESPACE,
41978
+ HTML_NAMESPACE
41979
+ ], stringToString);
41980
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze([
41981
+ "mi",
41982
+ "mo",
41983
+ "mn",
41984
+ "ms",
41985
+ "mtext"
41986
+ ]);
41987
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
41988
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(["annotation-xml"]);
41989
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
41990
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
41991
+ "title",
41992
+ "style",
41993
+ "font",
41994
+ "a",
41995
+ "script"
41996
+ ]);
41997
+ let PARSER_MEDIA_TYPE = null;
41998
+ const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
41999
+ const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
42000
+ let transformCaseFunc = null;
42001
+ let CONFIG = null;
42002
+ const formElement = document.createElement("form");
42003
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
42004
+ return testValue instanceof RegExp || testValue instanceof Function;
42005
+ };
42006
+ /**
42007
+ * _parseConfig
42008
+ *
42009
+ * @param cfg optional config literal
42010
+ */
42011
+ const _parseConfig = function _parseConfig() {
42012
+ let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
42013
+ if (CONFIG && CONFIG === cfg) return;
42014
+ if (!cfg || typeof cfg !== "object") cfg = {};
42015
+ cfg = clone(cfg);
42016
+ PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
42017
+ transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
42018
+ ALLOWED_TAGS = _resolveSetOption(cfg, "ALLOWED_TAGS", DEFAULT_ALLOWED_TAGS, { transform: transformCaseFunc });
42019
+ ALLOWED_ATTR = _resolveSetOption(cfg, "ALLOWED_ATTR", DEFAULT_ALLOWED_ATTR, { transform: transformCaseFunc });
42020
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, "ALLOWED_NAMESPACES", DEFAULT_ALLOWED_NAMESPACES, { transform: stringToString });
42021
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, "ADD_URI_SAFE_ATTR", DEFAULT_URI_SAFE_ATTRIBUTES, {
42022
+ transform: transformCaseFunc,
42023
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
42024
+ });
42025
+ DATA_URI_TAGS = _resolveSetOption(cfg, "ADD_DATA_URI_TAGS", DEFAULT_DATA_URI_TAGS, {
42026
+ transform: transformCaseFunc,
42027
+ base: DEFAULT_DATA_URI_TAGS
42028
+ });
42029
+ FORBID_CONTENTS = _resolveSetOption(cfg, "FORBID_CONTENTS", DEFAULT_FORBID_CONTENTS, { transform: transformCaseFunc });
42030
+ FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", clone({}), { transform: transformCaseFunc });
42031
+ FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", clone({}), { transform: transformCaseFunc });
42032
+ USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === "object" ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
42033
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
42034
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
42035
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
42036
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
42037
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
42038
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
42039
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
42040
+ RETURN_DOM = cfg.RETURN_DOM || false;
42041
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
42042
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
42043
+ FORCE_BODY = cfg.FORCE_BODY || false;
42044
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
42045
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
42046
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
42047
+ IN_PLACE = cfg.IN_PLACE || false;
42048
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI;
42049
+ NAMESPACE = typeof cfg.NAMESPACE === "string" ? cfg.NAMESPACE : HTML_NAMESPACE;
42050
+ MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS));
42051
+ HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS));
42052
+ const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", () => create(null));
42053
+ CUSTOM_ELEMENT_HANDLING = create(null);
42054
+ if (objectHasOwnProperty(customElementHandling, "tagNameCheck") && isRegexOrFunction(customElementHandling.tagNameCheck)) CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck;
42055
+ if (objectHasOwnProperty(customElementHandling, "attributeNameCheck") && isRegexOrFunction(customElementHandling.attributeNameCheck)) CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck;
42056
+ if (objectHasOwnProperty(customElementHandling, "allowCustomizedBuiltInElements") && typeof customElementHandling.allowCustomizedBuiltInElements === "boolean") CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements;
42057
+ seal(CUSTOM_ELEMENT_HANDLING);
42058
+ if (SAFE_FOR_TEMPLATES) ALLOW_DATA_ATTR = false;
42059
+ if (RETURN_DOM_FRAGMENT) RETURN_DOM = true;
42060
+ if (USE_PROFILES) {
42061
+ ALLOWED_TAGS = addToSet({}, text);
42062
+ ALLOWED_ATTR = create(null);
42063
+ if (USE_PROFILES.html === true) {
42064
+ addToSet(ALLOWED_TAGS, html$1);
42065
+ addToSet(ALLOWED_ATTR, html);
42066
+ }
42067
+ if (USE_PROFILES.svg === true) {
42068
+ addToSet(ALLOWED_TAGS, svg$1);
42069
+ addToSet(ALLOWED_ATTR, svg);
42070
+ addToSet(ALLOWED_ATTR, xml);
42071
+ }
42072
+ if (USE_PROFILES.svgFilters === true) {
42073
+ addToSet(ALLOWED_TAGS, svgFilters);
42074
+ addToSet(ALLOWED_ATTR, svg);
42075
+ addToSet(ALLOWED_ATTR, xml);
42076
+ }
42077
+ if (USE_PROFILES.mathMl === true) {
42078
+ addToSet(ALLOWED_TAGS, mathMl$1);
42079
+ addToSet(ALLOWED_ATTR, mathMl);
42080
+ addToSet(ALLOWED_ATTR, xml);
42081
+ }
42082
+ }
42083
+ EXTRA_ELEMENT_HANDLING.tagCheck = null;
42084
+ EXTRA_ELEMENT_HANDLING.attributeCheck = null;
42085
+ if (objectHasOwnProperty(cfg, "ADD_TAGS")) {
42086
+ if (typeof cfg.ADD_TAGS === "function") EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
42087
+ else if (arrayIsArray(cfg.ADD_TAGS)) {
42088
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = clone(ALLOWED_TAGS);
42089
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
42090
+ }
42091
+ }
42092
+ if (objectHasOwnProperty(cfg, "ADD_ATTR")) {
42093
+ if (typeof cfg.ADD_ATTR === "function") EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
42094
+ else if (arrayIsArray(cfg.ADD_ATTR)) {
42095
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = clone(ALLOWED_ATTR);
42096
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
42097
+ }
42098
+ }
42099
+ if (objectHasOwnProperty(cfg, "ADD_FORBID_CONTENTS") && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
42100
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = clone(FORBID_CONTENTS);
42101
+ addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
42102
+ }
42103
+ if (KEEP_CONTENT) ALLOWED_TAGS["#text"] = true;
42104
+ if (WHOLE_DOCUMENT) addToSet(ALLOWED_TAGS, [
42105
+ "html",
42106
+ "head",
42107
+ "body"
42108
+ ]);
42109
+ if (ALLOWED_TAGS.table) {
42110
+ addToSet(ALLOWED_TAGS, ["tbody"]);
42111
+ delete FORBID_TAGS.tbody;
42112
+ }
42113
+ if (cfg.TRUSTED_TYPES_POLICY) {
42114
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") throw typeErrorCreate("TRUSTED_TYPES_POLICY configuration option must provide a \"createHTML\" hook.");
42115
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") throw typeErrorCreate("TRUSTED_TYPES_POLICY configuration option must provide a \"createScriptURL\" hook.");
42116
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
42117
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
42118
+ try {
42119
+ emptyHTML = _createTrustedHTML("");
42120
+ } catch (error) {
42121
+ trustedTypesPolicy = previousTrustedTypesPolicy;
42122
+ throw error;
42123
+ }
42124
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
42125
+ trustedTypesPolicy = void 0;
42126
+ emptyHTML = "";
42127
+ } else {
42128
+ if (trustedTypesPolicy === void 0) trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
42129
+ if (trustedTypesPolicy && typeof emptyHTML === "string") emptyHTML = _createTrustedHTML("");
42130
+ }
42131
+ if (freeze) freeze(cfg);
42132
+ CONFIG = cfg;
42133
+ };
42134
+ const ALL_SVG_TAGS = addToSet({}, [
42135
+ ...svg$1,
42136
+ ...svgFilters,
42137
+ ...svgDisallowed
42138
+ ]);
42139
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
42140
+ /**
42141
+ * Namespace rules for an element in the SVG namespace.
42142
+ *
42143
+ * @param tagName the element's lowercase tag name
42144
+ * @param parent the (possibly simulated) parent node
42145
+ * @param parentTagName the parent's lowercase tag name
42146
+ * @returns true if a spec-compliant parser could produce this element
42147
+ */
42148
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
42149
+ if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "svg";
42150
+ if (parent.namespaceURI === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
42151
+ return Boolean(ALL_SVG_TAGS[tagName]);
42152
+ };
42153
+ /**
42154
+ * Namespace rules for an element in the MathML namespace.
42155
+ *
42156
+ * @param tagName the element's lowercase tag name
42157
+ * @param parent the (possibly simulated) parent node
42158
+ * @param parentTagName the parent's lowercase tag name
42159
+ * @returns true if a spec-compliant parser could produce this element
42160
+ */
42161
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
42162
+ if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "math";
42163
+ if (parent.namespaceURI === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
42164
+ return Boolean(ALL_MATHML_TAGS[tagName]);
42165
+ };
42166
+ /**
42167
+ * Namespace rules for an element in the HTML namespace.
42168
+ *
42169
+ * @param tagName the element's lowercase tag name
42170
+ * @param parent the (possibly simulated) parent node
42171
+ * @param parentTagName the parent's lowercase tag name
42172
+ * @returns true if a spec-compliant parser could produce this element
42173
+ */
42174
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
42175
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
42176
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
42177
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
42178
+ };
42179
+ /**
42180
+ * @param element a DOM element whose namespace is being checked
42181
+ * @returns Return false if the element has a
42182
+ * namespace that a spec-compliant parser would never
42183
+ * return. Return true otherwise.
42184
+ */
42185
+ const _checkValidNamespace = function _checkValidNamespace(element) {
42186
+ const elementNamespace = _readNamespaceURI(element);
42187
+ const tagName = stringToLowerCase(_readNodeName(element));
42188
+ const parentNode = getParentNode(element);
42189
+ let parent;
42190
+ let parentTagName;
42191
+ if (parentNode && _readNodeType(parentNode) === NODE_TYPE.element) {
42192
+ parent = { namespaceURI: _readNamespaceURI(parentNode) };
42193
+ parentTagName = stringToLowerCase(_readNodeName(parentNode));
42194
+ } else {
42195
+ parent = { namespaceURI: NAMESPACE };
42196
+ parentTagName = "template";
42197
+ }
42198
+ if (!ALLOWED_NAMESPACES[elementNamespace]) return false;
42199
+ if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parent, parentTagName);
42200
+ if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parent, parentTagName);
42201
+ if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parent, parentTagName);
42202
+ if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[elementNamespace]) return true;
42203
+ return false;
42204
+ };
42205
+ /**
42206
+ * _forceRemove
42207
+ *
42208
+ * @param node a DOM node
42209
+ */
42210
+ const _forceRemove = function _forceRemove(node) {
42211
+ arrayPush(DOMPurify.removed, { element: node });
42212
+ try {
42213
+ getParentNode(node).removeChild(node);
42214
+ } catch (_) {
42215
+ remove(node);
42216
+ 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");
42217
+ }
42218
+ };
42219
+ /**
42220
+ * _stripAttributeNode
42221
+ *
42222
+ * Remove a single Attr node case/namespace-exactly on an attribute-teardown
42223
+ * path. Name-based removeAttribute() ASCII-lowercases its lookup key for an
42224
+ * HTML element in an HTML document and so silently misses a case-preserved
42225
+ * handler (e.g. `ONERROR` off an XML/XHTML import) - the same defect
42226
+ * _removeAttribute() was fixed for, which a name-based call would reintroduce
42227
+ * on these IN_PLACE teardown paths. Unlike _removeAttribute this does not
42228
+ * record into DOMPurify.removed: the neutralize passes intentionally do not
42229
+ * book-keep. A clobbered/detached node falls back to best-effort name-based
42230
+ * removal.
42231
+ *
42232
+ * @param element the element to strip the attribute from
42233
+ * @param attribute the Attr node to remove
42234
+ * @param name the attribute's name, for the fallback path
42235
+ */
42236
+ const _stripAttributeNode = function _stripAttributeNode(element, attribute, name) {
42237
+ try {
42238
+ removeAttributeNode(element, attribute);
42239
+ } catch (_) {
42240
+ try {
42241
+ element.removeAttribute(name);
42242
+ } catch (_) {}
42243
+ }
42244
+ };
42245
+ /**
42246
+ * Fail-closed teardown of an in-place root: strip every disallowed attribute
42247
+ * in the subtree first, so nothing armed is left behind, then remove all
42248
+ * children and the root's own attributes.
42249
+ *
42250
+ * @param root the in-place root to empty
42251
+ */
42252
+ const _neutralizeRoot = function _neutralizeRoot(root) {
42253
+ _neutralizeSubtree(root);
42254
+ const childNodes = getChildNodes(root);
42255
+ if (childNodes) arrayForEach(arraySlice(childNodes), (child) => {
42256
+ try {
42257
+ remove(child);
42258
+ } catch (_) {}
42259
+ });
42260
+ const attributes = _readNodeType(root) === NODE_TYPE.element ? getAttributes(root) : null;
42261
+ if (attributes) for (let i = attributes.length - 1; i >= 0; --i) {
42262
+ const attribute = attributes[i];
42263
+ const name = attribute && attribute.name;
42264
+ if (typeof name === "string") _stripAttributeNode(root, attribute, name);
42265
+ }
42266
+ };
42267
+ /**
42268
+ * Removes an attribute, preferably as its exact Attr node: name-based
42269
+ * removal lowercases the name in HTML documents and misses case-preserved
42270
+ * names, e.g. from imported XHTML.
42271
+ *
42272
+ * @param name an Attribute name
42273
+ * @param element a DOM node
42274
+ * @param attr the exact Attr node to remove, when the caller has it
42275
+ */
42276
+ const _removeAttribute = function _removeAttribute(name, element, attr) {
42277
+ if (!attr) try {
42278
+ attr = element.getAttributeNode(name);
42279
+ } catch (_) {
42280
+ attr = null;
42281
+ }
42282
+ arrayPush(DOMPurify.removed, {
42283
+ attribute: attr || null,
42284
+ from: element
42285
+ });
42286
+ try {
42287
+ if (attr) removeAttributeNode(element, attr);
42288
+ else element.removeAttribute(name);
42289
+ } catch (_) {
42290
+ try {
42291
+ element.removeAttribute(name);
42292
+ } catch (_) {}
42293
+ }
42294
+ if (name === "is") {
42295
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) try {
42296
+ _forceRemove(element);
42297
+ } catch (_) {}
42298
+ else try {
42299
+ element.setAttribute(name, "");
42300
+ } catch (_) {}
42301
+ }
42302
+ };
42303
+ /**
42304
+ * Removes every attribute the configuration does not allow. Used to
42305
+ * neutralize nodes discarded from an in-place tree.
42306
+ *
42307
+ * @param element the element to strip
42308
+ */
42309
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
42310
+ const attributes = getAttributes(element);
42311
+ if (!attributes) return;
42312
+ for (let i = attributes.length - 1; i >= 0; --i) {
42313
+ const attribute = attributes[i];
42314
+ const name = attribute && attribute.name;
42315
+ if (typeof name !== "string" || ALLOWED_ATTR[transformCaseFunc(name)]) continue;
42316
+ _stripAttributeNode(element, attribute, name);
42317
+ }
42318
+ };
42319
+ /**
42320
+ * Iterative depth-first walk, so deep trees cannot overflow the call stack,
42321
+ * reading through the cached getters, so clobbering cannot hide children.
42322
+ * When `visit` returns false, the node's children are skipped. With
42323
+ * `intoShadow`, open shadow roots are walked after their host's children.
42324
+ *
42325
+ * @param root where to start
42326
+ * @param visit called for every node
42327
+ * @param intoShadow whether to enter open shadow roots
42328
+ */
42329
+ const _walkTree = function _walkTree(root, visit) {
42330
+ let intoShadow = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
42331
+ const stack = [root];
42332
+ while (stack.length > 0) {
42333
+ const node = stack.pop();
42334
+ if (visit(node) === false) continue;
42335
+ if (intoShadow && _readNodeType(node) === NODE_TYPE.element) {
42336
+ const shadowRoot = getShadowRoot(node);
42337
+ if (_isDocumentFragment(shadowRoot)) stack.push(shadowRoot);
42338
+ }
42339
+ const childNodes = getChildNodes(node);
42340
+ if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push(childNodes[i]);
42341
+ }
42342
+ };
42343
+ /**
42344
+ * Strips disallowed attributes from every element of a discarded subtree,
42345
+ * so a handler that is already queued (a loading image) cannot fire.
42346
+ *
42347
+ * @param root the root of a removed subtree
42348
+ */
42349
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
42350
+ _walkTree(root, (node) => {
42351
+ if (_readNodeType(node) === NODE_TYPE.element) _stripDisallowedAttributes(node);
42352
+ });
42353
+ };
42354
+ /**
42355
+ * All nodes under `root`, root first, including open shadow roots. Template
42356
+ * content is not entered, it is inert.
42357
+ *
42358
+ * @param root the in-place root
42359
+ * @return the nodes
42360
+ */
42361
+ const _collectLiveNodes = function _collectLiveNodes(root) {
42362
+ const nodes = [];
42363
+ _walkTree(root, (node) => {
42364
+ nodes.push(node);
42365
+ }, true);
42366
+ return nodes;
42367
+ };
42368
+ /**
42369
+ * Strips disallowed attributes from every element that was under the
42370
+ * in-place root when the call started and no longer is, whatever removed
42371
+ * or moved it.
42372
+ *
42373
+ * @param root the in-place root
42374
+ * @param before the root's nodes, collected before the walk
42375
+ */
42376
+ const _neutralizeEscapedElements = function _neutralizeEscapedElements(root, before) {
42377
+ const reachable = setCreate();
42378
+ arrayForEach(_collectLiveNodes(root), (node) => {
42379
+ if (_readNodeType(node) === NODE_TYPE.element) setAdd(reachable, node);
42380
+ });
42381
+ arrayForEach(before, (node) => {
42382
+ if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node)) _stripDisallowedAttributes(node);
42383
+ });
42384
+ };
42385
+ /**
42386
+ * Neutralizes everything that left the in-place tree during the call: what
42387
+ * DOMPurify removed, and what hooks or custom elements removed or moved out.
42388
+ *
42389
+ * @param root the in-place root
42390
+ * @param before the root's nodes, collected before the walk
42391
+ * @return true if the root itself was removed
42392
+ */
42393
+ const _neutralizeDiscarded = function _neutralizeDiscarded(root, before) {
42394
+ let rootRemoved = false;
42395
+ arrayForEach(DOMPurify.removed, (entry) => {
42396
+ if (entry.element) {
42397
+ rootRemoved = rootRemoved || entry.element === root;
42398
+ _neutralizeSubtree(entry.element);
42399
+ }
42400
+ });
42401
+ _neutralizeEscapedElements(root, before);
42402
+ return rootRemoved;
42403
+ };
42404
+ const MAX_UNVISITED_ROUNDS = 8;
42405
+ /**
42406
+ * The walk only moves forward, so a node moved to a position it already
42407
+ * passed is never visited. Give every original node that is still in the
42408
+ * tree but unvisited the normal treatment, hooks included. Nodes created
42409
+ * during the call are left alone. Fails closed if the tree keeps changing.
42410
+ *
42411
+ * @param root the in-place root
42412
+ * @param before the root's nodes, collected before the walk
42413
+ */
42414
+ const _sanitizeUnvisitedNodes = function _sanitizeUnvisitedNodes(root, before) {
42415
+ const visited = IN_PLACE_VISITED;
42416
+ let original = null;
42417
+ const getOriginal = () => {
42418
+ if (!original) {
42419
+ original = setCreate();
42420
+ arrayForEach(before, (beforeNode) => {
42421
+ setAdd(original, beforeNode);
42422
+ });
42423
+ }
42424
+ return original;
42425
+ };
42426
+ for (let round = 0;; round++) {
42427
+ const live = _collectLiveNodes(root);
42428
+ const containers = [root];
42429
+ let pending = false;
42430
+ arrayForEach(live, (node) => {
42431
+ if (_readNodeType(node) === NODE_TYPE.documentFragment) arrayPush(containers, node);
42432
+ else if (!pending && !setHas(visited, node)) pending = setHas(getOriginal(), node);
42433
+ });
42434
+ if (!pending) return;
42435
+ if (round >= MAX_UNVISITED_ROUNDS) throw typeErrorCreate("the tree kept changing during in-place sanitization; refusing to return it");
42436
+ arrayForEach(containers, (container, index) => {
42437
+ _sanitizeUnvisitedIn(container, index > 0, root, getOriginal());
42438
+ });
42439
+ }
42440
+ };
42441
+ /**
42442
+ * One _sanitizeUnvisitedNodes pass over the root or an open shadow root.
42443
+ *
42444
+ * @param container the root or an open shadow root
42445
+ * @param inShadow whether container is a shadow root
42446
+ * @param root the in-place root
42447
+ * @param original the root's nodes collected before the walk, as a set
42448
+ */
42449
+ const _sanitizeUnvisitedIn = function _sanitizeUnvisitedIn(container, inShadow, root, original) {
42450
+ const iterator = _createNodeIterator(container);
42451
+ let node;
42452
+ while (node = iterator.nextNode()) {
42453
+ if (!setHas(original, node) || setHas(IN_PLACE_VISITED, node)) continue;
42454
+ if (inShadow) _executeHooks(hooks.uponSanitizeShadowNode, node, null);
42455
+ _sanitizeElements(node, root);
42456
+ _sanitizeAttributes(node, root);
42457
+ if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
42458
+ }
42459
+ };
42460
+ /**
42461
+ * Records that _sanitizeElements processed `node`. No-op outside IN_PLACE.
42462
+ *
42463
+ * @param node the node being processed
42464
+ */
42465
+ const _markVisited = function _markVisited(node) {
42466
+ if (IN_PLACE_VISITED) setAdd(IN_PLACE_VISITED, node);
42467
+ };
42468
+ /**
42469
+ * Patch-linkage attributes (declarative partial updates): `patchsrc`
42470
+ * always, `for` everywhere except on <label> and <output>. Gated on
42471
+ * SAFE_FOR_XML. Shared by the IN_PLACE pre-pass and _isValidAttribute.
42472
+ *
42473
+ * @param lcName the transformCaseFunc'd attribute name
42474
+ * @param lcTag the transformCaseFunc'd tag name of the carrying element
42475
+ * @return true if the attribute is patch linkage and must be dropped
42476
+ */
42477
+ const _isPatchLinkageAttribute = function _isPatchLinkageAttribute(lcName, lcTag) {
42478
+ if (!SAFE_FOR_XML) return false;
42479
+ if (lcName === "patchsrc") return true;
42480
+ return lcName === "for" && lcTag !== "label" && lcTag !== "output";
42481
+ };
42482
+ /**
42483
+ * IN_PLACE pre-pass: sever all patch linkage before the walk, so no patch
42484
+ * can fire mid-walk into a part of the tree the walker already passed.
42485
+ * Removes range markers (processing instructions, comments with markup)
42486
+ * and strips linkage attributes. It cannot undo a patch that already fired.
42487
+ *
42488
+ * TODO: if the shipped feature can patch through `for` on <label>/<output>,
42489
+ * drop that pair here too (see test/declarative-patch-probe.html).
42490
+ *
42491
+ * @param root the in-place root to sweep
42492
+ */
42493
+ const _neutralizePatchLinkage = function _neutralizePatchLinkage(root) {
42494
+ if (!SAFE_FOR_XML) return;
42495
+ _walkTree(root, (node) => {
42496
+ const nodeType = _readNodeType(node);
42497
+ if (nodeType === NODE_TYPE.processingInstruction || nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, node.data)) {
42498
+ try {
42499
+ remove(node);
42500
+ } catch (_) {}
42501
+ return false;
42502
+ }
42503
+ if (nodeType === NODE_TYPE.element) {
42504
+ const element = node;
42505
+ const lcTag = transformCaseFunc(_readNodeName(node));
42506
+ try {
42507
+ if (element.hasAttribute && element.hasAttribute("patchsrc")) element.removeAttribute("patchsrc");
42508
+ if (element.hasAttribute && element.hasAttribute("for") && _isPatchLinkageAttribute("for", lcTag)) element.removeAttribute("for");
42509
+ } catch (_) {}
42510
+ }
42511
+ return true;
42512
+ });
42513
+ };
42514
+ /**
42515
+ * _initDocument
42516
+ *
42517
+ * @param dirty - a string of dirty markup
42518
+ * @return a DOM, filled with the dirty markup
42519
+ */
42520
+ const _initDocument = function _initDocument(dirty) {
42521
+ let doc = null;
42522
+ let leadingWhitespace = null;
42523
+ if (FORCE_BODY) dirty = "<remove></remove>" + dirty;
42524
+ else {
42525
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
42526
+ leadingWhitespace = matches && matches[0];
42527
+ }
42528
+ 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>";
42529
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
42530
+ if (NAMESPACE === HTML_NAMESPACE) try {
42531
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
42532
+ } catch (_) {}
42533
+ if (!doc || !doc.documentElement) {
42534
+ doc = implementation.createDocument(NAMESPACE, "template", null);
42535
+ try {
42536
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
42537
+ } catch (_) {}
42538
+ }
42539
+ const body = doc.body || doc.documentElement;
42540
+ if (dirty && leadingWhitespace) body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
42541
+ if (NAMESPACE === HTML_NAMESPACE) return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
42542
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
42543
+ };
42544
+ /**
42545
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
42546
+ *
42547
+ * @param root The root element or node to start traversing on.
42548
+ * @return The created NodeIterator
42549
+ */
42550
+ const _createNodeIterator = function _createNodeIterator(root) {
42551
+ const doc = getOwnerDocument ? getOwnerDocument(root) : root.ownerDocument;
42552
+ return createNodeIterator.call(doc || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
42553
+ };
42554
+ /**
42555
+ * Replace template expression syntax (mustache, ERB, template
42556
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
42557
+ * sites. Order matters: mustache, then ERB, then template literal.
42558
+ *
42559
+ * @param value the string to scrub
42560
+ * @returns the scrubbed string
42561
+ */
42562
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
42563
+ value = stringReplace(value, MUSTACHE_EXPR$1, " ");
42564
+ value = stringReplace(value, ERB_EXPR$1, " ");
42565
+ value = stringReplace(value, TMPLIT_EXPR$1, " ");
42566
+ return value;
42567
+ };
42568
+ /**
42569
+ * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
42570
+ * character data of an element subtree. Used as the final safety net for
42571
+ * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
42572
+ * which only form after text-node normalization (e.g. fragments split across
42573
+ * stripped elements) cannot survive into a template-evaluating framework.
42574
+ *
42575
+ * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
42576
+ * in place rather than round-tripping through innerHTML. This preserves
42577
+ * descendant node references (important for IN_PLACE callers), avoids a
42578
+ * serialize/reparse cycle, and reads literal character data — which means
42579
+ * `<%...%>` in text content matches the ERB regex against its real bytes
42580
+ * instead of the HTML-entity-escaped form innerHTML would produce.
42581
+ *
42582
+ * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
42583
+ * attributes is performed during the per-node `_sanitizeAttributes` pass.
42584
+ *
42585
+ * @param node The root element whose character data should be scrubbed.
42586
+ */
42587
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
42588
+ var _node$querySelectorAl;
42589
+ _scrubOwnCharacterData(node);
42590
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, "template");
42591
+ if (templates) arrayForEach(templates, (tmpl) => {
42592
+ if (_isDocumentFragment(tmpl.content)) _scrubTemplateExpressions2(tmpl.content);
42593
+ });
42594
+ };
42595
+ /**
42596
+ * _scrubOwnCharacterData
42597
+ *
42598
+ * Non-recursive core of _scrubTemplateExpressions: normalize `node` and
42599
+ * strip template expressions from its own character data only. Does not
42600
+ * enter <template>.content or attached shadow roots (NodeIterator never
42601
+ * does). Used by _sanitizeShadowDOM, where every nested template content
42602
+ * and shadow root is already walked - and therefore scrubbed - by its own
42603
+ * recursive _sanitizeShadowDOM call; recursing here as well would rescrub
42604
+ * each nested fragment once per ancestor, which is quadratic in nesting
42605
+ * depth.
42606
+ *
42607
+ * @param node The root whose own character data should be scrubbed.
42608
+ */
42609
+ const _scrubOwnCharacterData = function _scrubOwnCharacterData(node) {
42610
+ node.normalize();
42611
+ const doc = getOwnerDocument ? getOwnerDocument(node) : node.ownerDocument;
42612
+ const walker = createNodeIterator.call(doc || node, node, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
42613
+ let currentNode = walker.nextNode();
42614
+ while (currentNode) {
42615
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
42616
+ currentNode = walker.nextNode();
42617
+ }
42618
+ };
42619
+ /**
42620
+ * _isClobbered
42621
+ *
42622
+ * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
42623
+ * interface with [LegacyOverrideBuiltIns]; a descendant element with a
42624
+ * `name` attribute matching a prototype property shadows that property
42625
+ * on direct reads. We use this check at the IN_PLACE entry-point and
42626
+ * during attribute sanitization to refuse clobbered forms.
42627
+ *
42628
+ * @param element element to check for clobbering attacks
42629
+ * @return true if clobbered, false if safe
42630
+ */
42631
+ const _isClobbered = function _isClobbered(element) {
42632
+ const realTagName = getNodeName ? getNodeName(element) : null;
42633
+ if (typeof realTagName !== "string") return false;
42634
+ if (transformCaseFunc(realTagName) !== "form") return false;
42635
+ 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);
42636
+ };
42637
+ /**
42638
+ * Checks whether the given value is a DocumentFragment from any realm.
42639
+ *
42640
+ * The realm-independent replacement reads `nodeType` through the cached
42641
+ * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
42642
+ * constant (11). nodeType is a numeric value resolved from the node's
42643
+ * internal slot, identical across realms for the same kind of node.
42644
+ *
42645
+ * @param value object to check
42646
+ * @return true if value is a DocumentFragment-shaped node from any realm
42647
+ */
42648
+ const _isDocumentFragment = function _isDocumentFragment(value) {
42649
+ if (!getNodeType || typeof value !== "object" || value === null) return false;
42650
+ try {
42651
+ return getNodeType(value) === NODE_TYPE.documentFragment;
42652
+ } catch (_) {
42653
+ return false;
42654
+ }
42655
+ };
42656
+ /**
42657
+ * Checks whether the given object is a DOM node, including nodes that
42658
+ * originate from a different window/realm (e.g. an iframe's
42659
+ * contentDocument). The previous `value instanceof Node` check was
42660
+ * realm-bound: nodes from a different window failed it, causing
42661
+ * sanitize() to silently stringify them and reset IN_PLACE to false,
42662
+ * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
42663
+ *
42664
+ * @param value object to check whether it's a DOM node
42665
+ * @return true if value is a DOM node from any realm
42666
+ */
42667
+ const _isNode = function _isNode(value) {
42668
+ if (!getNodeType || typeof value !== "object" || value === null) return false;
42669
+ try {
42670
+ return typeof getNodeType(value) === "number";
42671
+ } catch (_) {
42672
+ return false;
42673
+ }
42674
+ };
42675
+ function _executeHooks(hooks, currentNode, data) {
42676
+ if (hooks.length === 0) return;
42677
+ arrayForEach(hooks, (hook) => {
42678
+ hook.call(DOMPurify, currentNode, data, CONFIG);
42679
+ });
42680
+ }
42681
+ /**
42682
+ * Structural-threat checks that condemn a node regardless of the
42683
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
42684
+ * processing instructions, markup-bearing comments. Pure predicate;
42685
+ * the caller removes. Check order is load-bearing.
42686
+ *
42687
+ * @param currentNode the node to inspect
42688
+ * @param tagName the node's transformCaseFunc'd tag name
42689
+ * @return true if the node must be removed
42690
+ */
42691
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
42692
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
42693
+ 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;
42694
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) return true;
42695
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
42696
+ return false;
42697
+ };
42698
+ /**
42699
+ * Evaluate a CUSTOM_ELEMENT_HANDLING check (a RegExp or a predicate
42700
+ * function, per the validation in _parseConfig) against a name.
42701
+ * Additional arguments are forwarded to predicate functions - the
42702
+ * attributeNameCheck predicate receives the tag name as its second
42703
+ * argument. A null/absent check never matches.
42704
+ *
42705
+ * @param check the configured tagNameCheck / attributeNameCheck value
42706
+ * @param name the name to test
42707
+ * @param args extra arguments forwarded to a predicate function
42708
+ * @return true if the check matches the name
42709
+ */
42710
+ const _matchesNameCheck = function _matchesNameCheck(check, name) {
42711
+ if (check instanceof RegExp) return regExpTest(check, name);
42712
+ if (check instanceof Function) {
42713
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) args[_key - 2] = arguments[_key];
42714
+ return Boolean(check(name, ...args));
42715
+ }
42716
+ return false;
42717
+ };
42718
+ /**
42719
+ * Handle a node whose tag is forbidden or not allowlisted: keep
42720
+ * allowed custom elements (false return exits _sanitizeElements
42721
+ * early - the namespace and fallback-tag removal checks are
42722
+ * intentionally skipped for kept custom elements), else hoist
42723
+ * content per KEEP_CONTENT and remove.
42724
+ *
42725
+ * A kept custom element is the ONLY case in which this function
42726
+ * returns false, so the caller uses that return value to run the
42727
+ * afterSanitizeElements hook on the kept element and keep the
42728
+ * element-hook lifecycle consistent with normal allowlisted
42729
+ * elements (GHSA-c2j3-45gr-mqc4).
42730
+ *
42731
+ * @param currentNode the disallowed node
42732
+ * @param tagName the node's transformCaseFunc'd tag name
42733
+ * @return true if the node was removed, false if kept
42734
+ */
42735
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName, root) {
42736
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
42737
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName] && !FORBID_CONTENTS[stringToLowerCase(tagName)]) {
42738
+ const parentNode = getParentNode(currentNode);
42739
+ const childNodes = getChildNodes(currentNode);
42740
+ if (childNodes && parentNode) {
42741
+ const childCount = childNodes.length;
42742
+ for (let i = childCount - 1; i >= 0; --i) {
42743
+ const hoisted = currentNode === root ? cloneNode(childNodes[i], true) : childNodes[i];
42744
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
42745
+ }
42746
+ }
42747
+ }
42748
+ _forceRemove(currentNode);
42749
+ return true;
42750
+ };
42751
+ /**
42752
+ * Fork a hook-mutable allowlist off its shared binding the first time a
42753
+ * (possibly lazily-installed) uponSanitize* hook is about to see it, so the
42754
+ * hook cannot widen the per-instance default or the setConfig binding by
42755
+ * reference and leak past the call. Returns the set unchanged once it is
42756
+ * already call-local, so repeated calls across elements are idempotent.
42757
+ *
42758
+ * @param hookList the uponSanitize* hook array for this event
42759
+ * @param set the current ALLOWED_TAGS / ALLOWED_ATTR binding
42760
+ * @param defaultSet the per-instance DEFAULT_ALLOWED_* constant
42761
+ * @param setConfigSet the captured setConfig() binding, or null
42762
+ * @return a call-local clone if a hook is present and set is still shared,
42763
+ * else set unchanged
42764
+ */
42765
+ const _forkSharedAllowlist = function _forkSharedAllowlist(hookList, set, defaultSet, setConfigSet) {
42766
+ if (hookList.length === 0) return set;
42767
+ return set === defaultSet || set === setConfigSet ? clone(set) : set;
42768
+ };
42769
+ /**
42770
+ * A hook may have detached the node it was called for. If so, treat it as
42771
+ * removed and stop processing it; the walk root is exempt. On the IN_PLACE
42772
+ * path the detached subtree is neutralized right away.
42773
+ *
42774
+ * @param currentNode the node a hook may have detached
42775
+ * @param root the current walk root
42776
+ * @return true if the node was detached
42777
+ */
42778
+ const _handleHookDetachedNode = function _handleHookDetachedNode(currentNode, root) {
42779
+ if (currentNode === root || getParentNode(currentNode) !== null) return false;
42780
+ if (IN_PLACE) _neutralizeSubtree(currentNode);
42781
+ return true;
42782
+ };
42783
+ /**
42784
+ * _sanitizeElements
42785
+ *
42786
+ * @protect nodeName
42787
+ * @protect textContent
42788
+ * @protect removeChild
42789
+ * @param currentNode to check for permission to exist
42790
+ * @return true if node was killed, false if left alive
42791
+ */
42792
+ const _sanitizeElements = function _sanitizeElements(currentNode, root) {
42793
+ _markVisited(currentNode);
42794
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
42795
+ if (_handleHookDetachedNode(currentNode, root)) return true;
42796
+ if (_isClobbered(currentNode)) {
42797
+ _forceRemove(currentNode);
42798
+ return true;
42799
+ }
42800
+ const tagName = transformCaseFunc(_readNodeName(currentNode));
42801
+ ALLOWED_TAGS = _forkSharedAllowlist(hooks.uponSanitizeElement, ALLOWED_TAGS, DEFAULT_ALLOWED_TAGS, SET_CONFIG_ALLOWED_TAGS);
42802
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
42803
+ tagName,
42804
+ allowedTags: ALLOWED_TAGS
42805
+ });
42806
+ if (_handleHookDetachedNode(currentNode, root)) return true;
42807
+ if (_isUnsafeNode(currentNode, tagName)) {
42808
+ _forceRemove(currentNode);
42809
+ return true;
42810
+ }
42811
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
42812
+ const removed = _sanitizeDisallowedNode(currentNode, tagName, root);
42813
+ if (removed === false) {
42814
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
42815
+ if (_handleHookDetachedNode(currentNode, root)) return true;
42816
+ }
42817
+ return removed;
42818
+ }
42819
+ if (_readNodeType(currentNode) === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
42820
+ _forceRemove(currentNode);
42821
+ return true;
42822
+ }
42823
+ if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
42824
+ _forceRemove(currentNode);
42825
+ return true;
42826
+ }
42827
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
42828
+ const content = _stripTemplateExpressions(currentNode.textContent);
42829
+ if (currentNode.textContent !== content) {
42830
+ arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
42831
+ currentNode.textContent = content;
42832
+ }
42833
+ }
42834
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
42835
+ return _handleHookDetachedNode(currentNode, root);
42836
+ };
42837
+ /**
42838
+ * _isValidAttribute
42839
+ *
42840
+ * @param lcTag Lowercase tag name of containing element.
42841
+ * @param lcName Lowercase attribute name.
42842
+ * @param value Attribute value.
42843
+ * @return Returns true if `value` is valid, otherwise false.
42844
+ */
42845
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
42846
+ if (FORBID_ATTR[lcName]) return false;
42847
+ if (_isPatchLinkageAttribute(lcName, lcTag)) return false;
42848
+ if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document || value in formElement)) return false;
42849
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
42850
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) return true;
42851
+ if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) return true;
42852
+ 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);
42853
+ if (URI_SAFE_ATTRIBUTES[lcName]) return true;
42854
+ if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
42855
+ if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) return true;
42856
+ if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
42857
+ return !value;
42858
+ };
42859
+ const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, [
42860
+ "annotation-xml",
42861
+ "color-profile",
42862
+ "font-face",
42863
+ "font-face-format",
42864
+ "font-face-name",
42865
+ "font-face-src",
42866
+ "font-face-uri",
42867
+ "missing-glyph"
42868
+ ]);
42869
+ /**
42870
+ * _isBasicCustomElement
42871
+ * checks if at least one dash is included in tagName, and it's not the first char
42872
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
42873
+ *
42874
+ * @param tagName name of the tag of the node to sanitize
42875
+ * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
42876
+ */
42877
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
42878
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
42879
+ };
42880
+ /**
42881
+ * Wrap an attribute value in the matching Trusted Types object when
42882
+ * the active policy requires it. Namespaced attributes pass through
42883
+ * unchanged (no TT support yet, see
42884
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
42885
+ *
42886
+ * @param lcTag lowercase tag name of the containing element
42887
+ * @param lcName lowercase attribute name
42888
+ * @param namespaceURI the attribute's namespace, if any
42889
+ * @param value the attribute value to wrap
42890
+ * @return the value, wrapped when Trusted Types demand it
42891
+ */
42892
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
42893
+ if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function" && !namespaceURI) switch (trustedTypes.getAttributeType(lcTag, lcName)) {
42894
+ case "TrustedHTML": return _createTrustedHTML(value);
42895
+ case "TrustedScriptURL": return _createTrustedScriptURL(value);
42896
+ }
42897
+ return value;
42898
+ };
42899
+ /**
42900
+ * Write a modified attribute value back onto the element. On
42901
+ * success, re-probe for clobbering introduced by the new value and
42902
+ * remove the element when found; otherwise, when this writeback is the
42903
+ * recreate half of the SANITIZE_NAMED_PROPS remove-and-recreate, pop the
42904
+ * removal entry that path recorded so it does not show as removed. On
42905
+ * failure, remove the attribute instead.
42906
+ *
42907
+ * Returns true only on a clean write (the value was set and the new value
42908
+ * introduced no clobbering). The caller uses that, together with its own
42909
+ * knowledge of whether this attribute pushed a DOMPurify.removed record, to
42910
+ * decide whether to pop that record. The pop must happen ONLY for the
42911
+ * named-prop remove-and-recreate; popping on any other value change (trim,
42912
+ * template scrubbing, Trusted Types) would consume an unrelated _forceRemove
42913
+ * subtree-cleanup record and let that detached subtree keep a live event
42914
+ * handler through the IN_PLACE neutralization pass (SO-001).
42915
+ *
42916
+ * @param currentNode the element carrying the attribute
42917
+ * @param name the attribute name as present on the element
42918
+ * @param namespaceURI the attribute's namespace, if any
42919
+ * @param value the new attribute value
42920
+ * @return true if the value was written without introducing clobbering
42921
+ */
42922
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
42923
+ try {
42924
+ if (namespaceURI) currentNode.setAttributeNS(namespaceURI, name, value);
42925
+ else currentNode.setAttribute(name, value);
42926
+ if (_isClobbered(currentNode)) {
42927
+ _forceRemove(currentNode);
42928
+ return false;
42929
+ }
42930
+ return true;
42931
+ } catch (_) {
42932
+ _removeAttribute(name, currentNode);
42933
+ return false;
42934
+ }
42935
+ };
42936
+ /**
42937
+ * _isUnsafeAttributeValue
42938
+ *
42939
+ * Value-based attribute checks that the attribute walk applies before any
42940
+ * hook can force-keep an attribute, shared with the public
42941
+ * isValidAttribute() so that it never approves a value sanitize() would
42942
+ * strip.
42943
+ *
42944
+ * @param name the attribute name as found on the node (case preserved)
42945
+ * @param value the attribute value
42946
+ * @returns true if the attribute must be removed because of its value
42947
+ */
42948
+ const _isUnsafeAttributeValue = function _isUnsafeAttributeValue(name, value) {
42949
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) return true;
42950
+ return stringToLowerCase(name) === "attributename" && stringMatch(value, "href") !== null;
42951
+ };
42952
+ /**
42953
+ * _sanitizeAttributes
42954
+ *
42955
+ * @protect attributes
42956
+ * @protect nodeName
42957
+ * @protect removeAttribute
42958
+ * @protect setAttribute
42959
+ *
42960
+ * @param currentNode to sanitize
42961
+ * @param root the current walk root
42962
+ */
42963
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode, root) {
42964
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
42965
+ if (_handleHookDetachedNode(currentNode, root)) return;
42966
+ const attributes = currentNode.attributes;
42967
+ if (!attributes || _isClobbered(currentNode)) return;
42968
+ ALLOWED_ATTR = _forkSharedAllowlist(hooks.uponSanitizeAttribute, ALLOWED_ATTR, DEFAULT_ALLOWED_ATTR, SET_CONFIG_ALLOWED_ATTR);
42969
+ const hookEvent = {
42970
+ attrName: "",
42971
+ attrValue: "",
42972
+ keepAttr: true,
42973
+ allowedAttributes: ALLOWED_ATTR,
42974
+ forceKeepAttr: void 0
42975
+ };
42976
+ let l = attributes.length;
42977
+ const lcTag = transformCaseFunc(currentNode.nodeName);
42978
+ while (l--) {
42979
+ const attr = attributes[l];
42980
+ const name = attr.name, namespaceURI = attr.namespaceURI, attrValue = attr.value;
42981
+ const lcName = transformCaseFunc(name);
42982
+ const initValue = attrValue;
42983
+ let value = name === "value" ? initValue : stringTrim(initValue);
42984
+ let recreatedNamedProp = false;
42985
+ hookEvent.attrName = lcName;
42986
+ hookEvent.attrValue = value;
42987
+ hookEvent.keepAttr = true;
42988
+ hookEvent.forceKeepAttr = void 0;
42989
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
42990
+ value = hookEvent.attrValue;
42991
+ if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name") && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
42992
+ _removeAttribute(name, currentNode, attr);
42993
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
42994
+ recreatedNamedProp = true;
42995
+ }
42996
+ if (_isUnsafeAttributeValue(name, value)) {
42997
+ _removeAttribute(name, currentNode, attr);
42998
+ continue;
42999
+ }
43000
+ if (hookEvent.forceKeepAttr) continue;
43001
+ if (!hookEvent.keepAttr) {
43002
+ _removeAttribute(name, currentNode, attr);
43003
+ continue;
43004
+ }
43005
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
43006
+ _removeAttribute(name, currentNode, attr);
43007
+ continue;
43008
+ }
43009
+ if (SAFE_FOR_TEMPLATES) value = _stripTemplateExpressions(value);
43010
+ if (!_isValidAttribute(lcTag, lcName, value)) {
43011
+ _removeAttribute(name, currentNode, attr);
43012
+ continue;
43013
+ }
43014
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
43015
+ if (value !== initValue) {
43016
+ if (_setAttributeValue(currentNode, name, namespaceURI, value) && recreatedNamedProp) arrayPop(DOMPurify.removed);
43017
+ }
43018
+ }
43019
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
43020
+ _handleHookDetachedNode(currentNode, root);
43021
+ };
43022
+ /**
43023
+ * _sanitizeShadowDOM
43024
+ *
43025
+ * @param fragment to iterate over recursively
43026
+ */
43027
+ const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
43028
+ let shadowNode = null;
43029
+ const shadowIterator = _createNodeIterator(fragment);
43030
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
43031
+ while (shadowNode = shadowIterator.nextNode()) {
43032
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
43033
+ _sanitizeElements(shadowNode, fragment);
43034
+ _sanitizeAttributes(shadowNode, fragment);
43035
+ if (_isDocumentFragment(shadowNode.content)) _sanitizeShadowDOM2(shadowNode.content);
43036
+ if (_readNodeType(shadowNode) === NODE_TYPE.element) {
43037
+ const innerSr = getShadowRoot(shadowNode);
43038
+ if (_isDocumentFragment(innerSr)) {
43039
+ _sanitizeAttachedShadowRoots(innerSr);
43040
+ _sanitizeShadowDOM2(innerSr);
43041
+ }
43042
+ }
43043
+ }
43044
+ if (SAFE_FOR_TEMPLATES) _scrubOwnCharacterData(fragment);
43045
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
43046
+ };
43047
+ /**
43048
+ * Sanitizes every attached shadow root under `root`, since the node
43049
+ * iterator does not enter shadow trees. Needed for IN_PLACE input and for
43050
+ * DOM input whose clonable shadow roots were copied by importNode().
43051
+ *
43052
+ * @param root the subtree root to walk for attached shadow roots
43053
+ */
43054
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
43055
+ const stack = [{
43056
+ node: root,
43057
+ shadow: null
43058
+ }];
43059
+ while (stack.length > 0) {
43060
+ const item = stack.pop();
43061
+ if (item.shadow) {
43062
+ _sanitizeShadowDOM2(item.shadow);
43063
+ continue;
43064
+ }
43065
+ const node = item.node;
43066
+ const isElement = _readNodeType(node) === NODE_TYPE.element;
43067
+ const childNodes = getChildNodes(node);
43068
+ if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push({
43069
+ node: childNodes[i],
43070
+ shadow: null
43071
+ });
43072
+ if (isElement) {
43073
+ const rootName = getNodeName ? getNodeName(node) : null;
43074
+ if (typeof rootName === "string" && transformCaseFunc(rootName) === "template") {
43075
+ const content = node.content;
43076
+ if (_isDocumentFragment(content)) stack.push({
43077
+ node: content,
43078
+ shadow: null
43079
+ });
43080
+ }
43081
+ }
43082
+ if (isElement) {
43083
+ const sr = getShadowRoot(node);
43084
+ if (_isDocumentFragment(sr)) stack.push({
43085
+ node: null,
43086
+ shadow: sr
43087
+ }, {
43088
+ node: sr,
43089
+ shadow: null
43090
+ });
43091
+ }
43092
+ }
43093
+ };
43094
+ DOMPurify.sanitize = function(dirty) {
43095
+ let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
43096
+ let body = null;
43097
+ let importedNode = null;
43098
+ let currentNode = null;
43099
+ let returnNode = null;
43100
+ IS_EMPTY_INPUT = !dirty;
43101
+ if (IS_EMPTY_INPUT) dirty = "<!-->";
43102
+ if (typeof dirty !== "string" && !_isNode(dirty)) {
43103
+ dirty = stringifyValue(dirty);
43104
+ if (typeof dirty !== "string") throw typeErrorCreate("dirty is not a string, aborting");
43105
+ }
43106
+ if (!DOMPurify.isSupported) return dirty;
43107
+ if (SET_CONFIG) {
43108
+ ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
43109
+ ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
43110
+ } else _parseConfig(cfg);
43111
+ if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) ALLOWED_TAGS = clone(ALLOWED_TAGS);
43112
+ if (hooks.uponSanitizeAttribute.length > 0) ALLOWED_ATTR = clone(ALLOWED_ATTR);
43113
+ DOMPurify.removed = [];
43114
+ const inPlace = IN_PLACE && typeof dirty !== "string" && _isNode(dirty);
43115
+ let inPlaceNodes = [];
43116
+ const outerVisited = IN_PLACE_VISITED;
43117
+ if (inPlace) {
43118
+ _neutralizePatchLinkage(dirty);
43119
+ const nn = _readNodeName(dirty);
43120
+ if (typeof nn === "string") {
43121
+ const tagName = transformCaseFunc(nn);
43122
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
43123
+ _neutralizeRoot(dirty);
43124
+ throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
43125
+ }
43126
+ }
43127
+ if (_isClobbered(dirty)) {
43128
+ _neutralizeRoot(dirty);
43129
+ throw typeErrorCreate("root node is clobbered and cannot be sanitized in-place");
43130
+ }
43131
+ inPlaceNodes = _collectLiveNodes(dirty);
43132
+ IN_PLACE_VISITED = setCreate();
43133
+ } else if (_isNode(dirty)) {
43134
+ body = _initDocument("<!---->");
43135
+ importedNode = body.ownerDocument.importNode(dirty, true);
43136
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") body = importedNode;
43137
+ else if (importedNode.nodeName === "HTML") body = importedNode;
43138
+ else body.appendChild(importedNode);
43139
+ _sanitizeAttachedShadowRoots(body);
43140
+ } else {
43141
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
43142
+ body = _initDocument(dirty);
43143
+ if (!body) return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
43144
+ }
43145
+ if (body && FORCE_BODY) _forceRemove(body.firstChild);
43146
+ const walkRoot = inPlace ? dirty : body;
43147
+ try {
43148
+ if (inPlace) _sanitizeAttachedShadowRoots(dirty);
43149
+ const nodeIterator = _createNodeIterator(walkRoot);
43150
+ while (currentNode = nodeIterator.nextNode()) {
43151
+ _sanitizeElements(currentNode, walkRoot);
43152
+ _sanitizeAttributes(currentNode, walkRoot);
43153
+ if (_isDocumentFragment(currentNode.content)) _sanitizeShadowDOM2(currentNode.content);
43154
+ }
43155
+ if (inPlace) _sanitizeUnvisitedNodes(dirty, inPlaceNodes);
43156
+ } catch (error) {
43157
+ if (inPlace) {
43158
+ _neutralizeRoot(dirty);
43159
+ _neutralizeDiscarded(dirty, inPlaceNodes);
43160
+ }
43161
+ throw error;
43162
+ } finally {
43163
+ IN_PLACE_VISITED = outerVisited;
43164
+ }
43165
+ if (inPlace) {
43166
+ if (_neutralizeDiscarded(dirty, inPlaceNodes)) throw typeErrorCreate("a node selected for removal could not be safely returned; refusing to sanitize in place");
43167
+ if (SAFE_FOR_TEMPLATES) _scrubTemplateExpressions2(dirty);
43168
+ return dirty;
43169
+ }
43170
+ if (RETURN_DOM) {
43171
+ if (SAFE_FOR_TEMPLATES) _scrubTemplateExpressions2(body);
43172
+ if (RETURN_DOM_FRAGMENT) {
43173
+ returnNode = createDocumentFragment.call(body.ownerDocument);
43174
+ while (body.firstChild) returnNode.appendChild(body.firstChild);
43175
+ } else returnNode = body;
43176
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) returnNode = importNode.call(originalDocument, returnNode, true);
43177
+ return returnNode;
43178
+ }
43179
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
43180
+ 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;
43181
+ if (SAFE_FOR_TEMPLATES) serializedHTML = _stripTemplateExpressions(serializedHTML);
43182
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
43183
+ };
43184
+ DOMPurify.setConfig = function() {
43185
+ let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
43186
+ _parseConfig(cfg);
43187
+ SET_CONFIG = true;
43188
+ SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
43189
+ SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
43190
+ };
43191
+ DOMPurify.clearConfig = function() {
43192
+ CONFIG = null;
43193
+ SET_CONFIG = false;
43194
+ SET_CONFIG_ALLOWED_TAGS = null;
43195
+ SET_CONFIG_ALLOWED_ATTR = null;
43196
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
43197
+ emptyHTML = "";
43198
+ };
43199
+ DOMPurify.isValidAttribute = function(tag, attr, value) {
43200
+ if (!CONFIG) _parseConfig({});
43201
+ const lcTag = transformCaseFunc(tag);
43202
+ const lcName = transformCaseFunc(attr);
43203
+ if (typeof value === "string" && (_isUnsafeAttributeValue(attr, value) || !ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value))) return false;
43204
+ return _isValidAttribute(lcTag, lcName, value);
43205
+ };
43206
+ DOMPurify.addHook = function(entryPoint, hookFunction) {
43207
+ if (typeof hookFunction !== "function") return;
43208
+ if (!objectHasOwnProperty(hooks, entryPoint)) return;
43209
+ arrayPush(hooks[entryPoint], hookFunction);
43210
+ };
43211
+ DOMPurify.removeHook = function(entryPoint, hookFunction) {
43212
+ if (!objectHasOwnProperty(hooks, entryPoint)) return;
43213
+ if (hookFunction !== void 0) {
43214
+ const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
43215
+ return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
43216
+ }
43217
+ return arrayPop(hooks[entryPoint]);
43218
+ };
43219
+ DOMPurify.removeHooks = function(entryPoint) {
43220
+ if (!objectHasOwnProperty(hooks, entryPoint)) return;
43221
+ hooks[entryPoint] = [];
43222
+ };
43223
+ DOMPurify.removeAllHooks = function() {
43224
+ hooks = _createHooksMap();
43225
+ };
43226
+ return DOMPurify;
43227
+ }
43228
+ return createDOMPurify();
43229
+ });
42298
43230
 
42299
- }));
42300
43231
 
42301
43232
  }(purify));
42302
43233