@everymatrix/nuts-inbox-widget 1.99.56 → 1.99.59

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