@carbon/ai-chat 0.1.6 → 0.1.7-alpha0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/cjs/{cds-aichat-internal.js → AppContainer.js} +615 -7203
  2. package/dist/cjs/Carousel.js +24 -16
  3. package/dist/cjs/Chat.js +813 -805
  4. package/dist/cjs/GenesysMessengerServiceDesk.js +60 -52
  5. package/dist/cjs/HumanAgentServiceImpl.js +103 -95
  6. package/dist/cjs/NiceDFOServiceDesk.js +56 -48
  7. package/dist/cjs/PDFViewerContainer.js +58 -149
  8. package/dist/cjs/ReactPlayer.js +2 -2
  9. package/dist/cjs/SFServiceDesk.js +66 -58
  10. package/dist/cjs/ServiceDeskImpl.js +2 -2
  11. package/dist/cjs/Table.js +457 -341
  12. package/dist/cjs/ZendeskServiceDesk.js +36 -28
  13. package/dist/cjs/_node-resolve_empty.js +2 -2
  14. package/dist/cjs/agentActions.js +5 -5
  15. package/dist/cjs/aiChatEntry.js +163 -144
  16. package/dist/cjs/anonymousUserIDStorage.js +8 -8
  17. package/dist/cjs/ar-dz.js +4 -4
  18. package/dist/cjs/ar-kw.js +4 -4
  19. package/dist/cjs/ar-ly.js +4 -4
  20. package/dist/cjs/ar-ma.js +4 -4
  21. package/dist/cjs/ar-sa.js +4 -4
  22. package/dist/cjs/ar-tn.js +4 -4
  23. package/dist/cjs/ar.js +4 -4
  24. package/dist/cjs/ar2.js +2 -2
  25. package/dist/cjs/cds-aichat-container.js +111 -23
  26. package/dist/cjs/cds-aichat-custom-element.js +42 -30
  27. package/dist/cjs/cs.js +4 -4
  28. package/dist/cjs/cs2.js +2 -2
  29. package/dist/cjs/de-at.js +4 -4
  30. package/dist/cjs/de-ch.js +4 -4
  31. package/dist/cjs/de.js +4 -4
  32. package/dist/cjs/de2.js +2 -2
  33. package/dist/cjs/en-au.js +4 -4
  34. package/dist/cjs/en-ca.js +4 -4
  35. package/dist/cjs/en-gb.js +4 -4
  36. package/dist/cjs/en-ie.js +4 -4
  37. package/dist/cjs/en-il.js +4 -4
  38. package/dist/cjs/en-nz.js +4 -4
  39. package/dist/cjs/es-do.js +4 -4
  40. package/dist/cjs/es-us.js +4 -4
  41. package/dist/cjs/es.js +4 -4
  42. package/dist/cjs/es2.js +2 -2
  43. package/dist/cjs/export.js +3 -3
  44. package/dist/cjs/export.legacy.js +3 -3
  45. package/dist/cjs/fontUtils.js +2 -2
  46. package/dist/cjs/fr-ca.js +4 -4
  47. package/dist/cjs/fr-ch.js +4 -4
  48. package/dist/cjs/fr.js +4 -4
  49. package/dist/cjs/fr2.js +2 -2
  50. package/dist/cjs/highlight_js.js +2 -2
  51. package/dist/cjs/it-ch.js +4 -4
  52. package/dist/cjs/it.js +4 -4
  53. package/dist/cjs/it2.js +2 -2
  54. package/dist/cjs/ja.js +4 -4
  55. package/dist/cjs/ja2.js +2 -2
  56. package/dist/cjs/ko.js +4 -4
  57. package/dist/cjs/ko2.js +2 -2
  58. package/dist/cjs/markdown.js +2362 -14
  59. package/dist/cjs/mockServiceDesk.js +42 -34
  60. package/dist/cjs/nl.js +4 -4
  61. package/dist/cjs/nl2.js +2 -2
  62. package/dist/cjs/pt-br.js +4 -4
  63. package/dist/cjs/pt-br2.js +2 -2
  64. package/dist/cjs/pt.js +4 -4
  65. package/dist/cjs/render.js +18 -10
  66. package/dist/cjs/zh-cn.js +4 -4
  67. package/dist/cjs/zh-tw.js +4 -4
  68. package/dist/cjs/zh-tw2.js +2 -2
  69. package/dist/cjs/zh.js +2 -2
  70. package/dist/es/{cds-aichat-internal.js → AppContainer.js} +1117 -7671
  71. package/dist/es/Carousel.js +16 -8
  72. package/dist/es/Chat.js +16 -8
  73. package/dist/es/GenesysMessengerServiceDesk.js +16 -8
  74. package/dist/es/HumanAgentServiceImpl.js +16 -8
  75. package/dist/es/NiceDFOServiceDesk.js +16 -8
  76. package/dist/es/PDFViewerContainer.js +16 -107
  77. package/dist/es/ReactPlayer.js +2 -2
  78. package/dist/es/SFServiceDesk.js +16 -8
  79. package/dist/es/ServiceDeskImpl.js +2 -2
  80. package/dist/es/Table.js +426 -310
  81. package/dist/es/ZendeskServiceDesk.js +16 -8
  82. package/dist/es/_node-resolve_empty.js +2 -2
  83. package/dist/es/agentActions.js +3 -3
  84. package/dist/es/aiChatEntry.js +136 -117
  85. package/dist/es/anonymousUserIDStorage.js +3 -3
  86. package/dist/es/ar-dz.js +3 -3
  87. package/dist/es/ar-kw.js +3 -3
  88. package/dist/es/ar-ly.js +3 -3
  89. package/dist/es/ar-ma.js +3 -3
  90. package/dist/es/ar-sa.js +3 -3
  91. package/dist/es/ar-tn.js +3 -3
  92. package/dist/es/ar.js +3 -3
  93. package/dist/es/ar2.js +2 -2
  94. package/dist/es/cds-aichat-container.js +103 -15
  95. package/dist/es/cds-aichat-custom-element.js +30 -18
  96. package/dist/es/cs.js +3 -3
  97. package/dist/es/cs2.js +2 -2
  98. package/dist/es/de-at.js +3 -3
  99. package/dist/es/de-ch.js +3 -3
  100. package/dist/es/de.js +3 -3
  101. package/dist/es/de2.js +2 -2
  102. package/dist/es/en-au.js +3 -3
  103. package/dist/es/en-ca.js +3 -3
  104. package/dist/es/en-gb.js +3 -3
  105. package/dist/es/en-ie.js +3 -3
  106. package/dist/es/en-il.js +3 -3
  107. package/dist/es/en-nz.js +3 -3
  108. package/dist/es/es-do.js +3 -3
  109. package/dist/es/es-us.js +3 -3
  110. package/dist/es/es.js +3 -3
  111. package/dist/es/es2.js +2 -2
  112. package/dist/es/export.js +3 -3
  113. package/dist/es/export.legacy.js +3 -3
  114. package/dist/es/fontUtils.js +2 -2
  115. package/dist/es/fr-ca.js +3 -3
  116. package/dist/es/fr-ch.js +3 -3
  117. package/dist/es/fr.js +3 -3
  118. package/dist/es/fr2.js +2 -2
  119. package/dist/es/highlight_js.js +2 -2
  120. package/dist/es/it-ch.js +3 -3
  121. package/dist/es/it.js +3 -3
  122. package/dist/es/it2.js +2 -2
  123. package/dist/es/ja.js +3 -3
  124. package/dist/es/ja2.js +2 -2
  125. package/dist/es/ko.js +3 -3
  126. package/dist/es/ko2.js +2 -2
  127. package/dist/es/markdown.js +2361 -15
  128. package/dist/es/mockServiceDesk.js +16 -8
  129. package/dist/es/nl.js +3 -3
  130. package/dist/es/nl2.js +2 -2
  131. package/dist/es/pt-br.js +3 -3
  132. package/dist/es/pt-br2.js +2 -2
  133. package/dist/es/pt.js +3 -3
  134. package/dist/es/render.js +17 -9
  135. package/dist/es/zh-cn.js +3 -3
  136. package/dist/es/zh-tw.js +3 -3
  137. package/dist/es/zh-tw2.js +2 -2
  138. package/dist/es/zh.js +2 -2
  139. package/dist/types/aiChatEntry.d.ts +69 -9
  140. package/package.json +27 -14
  141. package/dist/cjs/jstz.min.js +0 -43
  142. package/dist/cjs/markdown_attrs.js +0 -805
  143. package/dist/es/jstz.min.js +0 -41
  144. package/dist/es/markdown_attrs.js +0 -803
@@ -13,15 +13,17 @@ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND
13
13
  or implied. See the License for the specific language governing permissions and limitations under
14
14
  the License.
15
15
 
16
- @carbon/ai-chat 0.1.6
16
+ @carbon/ai-chat 0.1.7-alpha0
17
17
 
18
- Built: Feb 3 2025 9:58 am -05:00
18
+ Built: Feb 12 2025 9:14 am -05:00
19
19
 
20
20
 
21
21
 
22
22
  */
23
23
  'use strict';
24
24
 
25
+ var highlight_js = require('./highlight_js.js');
26
+
25
27
  /* eslint-disable no-bitwise */
26
28
 
27
29
  const decodeCache = {};
@@ -1234,22 +1236,22 @@ function unescapeAll (str) {
1234
1236
  })
1235
1237
  }
1236
1238
 
1237
- const HTML_ESCAPE_TEST_RE = /[&<>"]/;
1238
- const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g;
1239
- const HTML_REPLACEMENTS = {
1239
+ const HTML_ESCAPE_TEST_RE$1 = /[&<>"]/;
1240
+ const HTML_ESCAPE_REPLACE_RE$1 = /[&<>"]/g;
1241
+ const HTML_REPLACEMENTS$1 = {
1240
1242
  '&': '&amp;',
1241
1243
  '<': '&lt;',
1242
1244
  '>': '&gt;',
1243
1245
  '"': '&quot;'
1244
1246
  };
1245
1247
 
1246
- function replaceUnsafeChar (ch) {
1247
- return HTML_REPLACEMENTS[ch]
1248
+ function replaceUnsafeChar$1 (ch) {
1249
+ return HTML_REPLACEMENTS$1[ch]
1248
1250
  }
1249
1251
 
1250
1252
  function escapeHtml (str) {
1251
- if (HTML_ESCAPE_TEST_RE.test(str)) {
1252
- return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar)
1253
+ if (HTML_ESCAPE_TEST_RE$1.test(str)) {
1254
+ return str.replace(HTML_ESCAPE_REPLACE_RE$1, replaceUnsafeChar$1)
1253
1255
  }
1254
1256
  return str
1255
1257
  }
@@ -1401,7 +1403,7 @@ function normalizeReference (str) {
1401
1403
  //
1402
1404
  const lib = { mdurl, ucmicro };
1403
1405
 
1404
- var utils = /*#__PURE__*/Object.freeze({
1406
+ var utils$2 = /*#__PURE__*/Object.freeze({
1405
1407
  __proto__: null,
1406
1408
  arrayReplaceAt: arrayReplaceAt,
1407
1409
  assign: assign$1,
@@ -6570,7 +6572,7 @@ function escapeRE (str) { return str.replace(/[.?*+^$[\]\\(){}|-]/g, '\\$&') }
6570
6572
 
6571
6573
  //
6572
6574
 
6573
- const defaultOptions = {
6575
+ const defaultOptions$1 = {
6574
6576
  fuzzyLink: true,
6575
6577
  fuzzyEmail: true,
6576
6578
  fuzzyIP: false
@@ -6579,7 +6581,7 @@ const defaultOptions = {
6579
6581
  function isOptionsObj (obj) {
6580
6582
  return Object.keys(obj || {}).reduce(function (acc, k) {
6581
6583
  /* eslint-disable-next-line no-prototype-builtins */
6582
- return acc || defaultOptions.hasOwnProperty(k)
6584
+ return acc || defaultOptions$1.hasOwnProperty(k)
6583
6585
  }, false)
6584
6586
  }
6585
6587
 
@@ -6907,7 +6909,7 @@ function LinkifyIt (schemas, options) {
6907
6909
  }
6908
6910
  }
6909
6911
 
6910
- this.__opts__ = assign({}, defaultOptions, options);
6912
+ this.__opts__ = assign({}, defaultOptions$1, options);
6911
6913
 
6912
6914
  // Cache last tested result. Used to skip repeating steps on next `match` call.
6913
6915
  this.__index__ = -1;
@@ -8141,7 +8143,7 @@ function MarkdownIt (presetName, options) {
8141
8143
  * Assorted utility functions, useful to write plugins. See details
8142
8144
  * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/common/utils.mjs).
8143
8145
  **/
8144
- this.utils = utils;
8146
+ this.utils = utils$2;
8145
8147
 
8146
8148
  /**
8147
8149
  * MarkdownIt#helpers -> helpers
@@ -8378,6 +8380,784 @@ MarkdownIt.prototype.renderInline = function (src, env) {
8378
8380
  return this.renderer.render(this.parseInline(src, env), this.options, env)
8379
8381
  };
8380
8382
 
8383
+ var utils$1 = {};
8384
+
8385
+ /**
8386
+ * parse {.class #id key=val} strings
8387
+ * @param {string} str: string to parse
8388
+ * @param {int} start: where to start parsing (including {)
8389
+ * @returns {2d array}: [['key', 'val'], ['class', 'red']]
8390
+ */
8391
+
8392
+ utils$1.getAttrs = function (str, start, options) {
8393
+ // not tab, line feed, form feed, space, solidus, greater than sign, quotation mark, apostrophe and equals sign
8394
+ const allowedKeyChars = /[^\t\n\f />"'=]/;
8395
+ const pairSeparator = ' ';
8396
+ const keySeparator = '=';
8397
+ const classChar = '.';
8398
+ const idChar = '#';
8399
+
8400
+ const attrs = [];
8401
+ let key = '';
8402
+ let value = '';
8403
+ let parsingKey = true;
8404
+ let valueInsideQuotes = false;
8405
+
8406
+ // read inside {}
8407
+ // start + left delimiter length to avoid beginning {
8408
+ // breaks when } is found or end of string
8409
+ for (let i = start + options.leftDelimiter.length; i < str.length; i++) {
8410
+ if (str.slice(i, i + options.rightDelimiter.length) === options.rightDelimiter) {
8411
+ if (key !== '') { attrs.push([key, value]); }
8412
+ break;
8413
+ }
8414
+ const char_ = str.charAt(i);
8415
+
8416
+ // switch to reading value if equal sign
8417
+ if (char_ === keySeparator && parsingKey) {
8418
+ parsingKey = false;
8419
+ continue;
8420
+ }
8421
+
8422
+ // {.class} {..css-module}
8423
+ if (char_ === classChar && key === '') {
8424
+ if (str.charAt(i + 1) === classChar) {
8425
+ key = 'css-module';
8426
+ i += 1;
8427
+ } else {
8428
+ key = 'class';
8429
+ }
8430
+ parsingKey = false;
8431
+ continue;
8432
+ }
8433
+
8434
+ // {#id}
8435
+ if (char_ === idChar && key === '') {
8436
+ key = 'id';
8437
+ parsingKey = false;
8438
+ continue;
8439
+ }
8440
+
8441
+ // {value="inside quotes"}
8442
+ if (char_ === '"' && value === '' && !valueInsideQuotes) {
8443
+ valueInsideQuotes = true;
8444
+ continue;
8445
+ }
8446
+ if (char_ === '"' && valueInsideQuotes) {
8447
+ valueInsideQuotes = false;
8448
+ continue;
8449
+ }
8450
+
8451
+ // read next key/value pair
8452
+ if ((char_ === pairSeparator && !valueInsideQuotes)) {
8453
+ if (key === '') {
8454
+ // beginning or ending space: { .red } vs {.red}
8455
+ continue;
8456
+ }
8457
+ attrs.push([key, value]);
8458
+ key = '';
8459
+ value = '';
8460
+ parsingKey = true;
8461
+ continue;
8462
+ }
8463
+
8464
+ // continue if character not allowed
8465
+ if (parsingKey && char_.search(allowedKeyChars) === -1) {
8466
+ continue;
8467
+ }
8468
+
8469
+ // no other conditions met; append to key/value
8470
+ if (parsingKey) {
8471
+ key += char_;
8472
+ continue;
8473
+ }
8474
+ value += char_;
8475
+ }
8476
+
8477
+ if (options.allowedAttributes && options.allowedAttributes.length) {
8478
+ const allowedAttributes = options.allowedAttributes;
8479
+
8480
+ return attrs.filter(function (attrPair) {
8481
+ const attr = attrPair[0];
8482
+
8483
+ function isAllowedAttribute (allowedAttribute) {
8484
+ return (attr === allowedAttribute
8485
+ || (allowedAttribute instanceof RegExp && allowedAttribute.test(attr))
8486
+ );
8487
+ }
8488
+
8489
+ return allowedAttributes.some(isAllowedAttribute);
8490
+ });
8491
+
8492
+ }
8493
+ return attrs;
8494
+
8495
+ };
8496
+
8497
+ /**
8498
+ * add attributes from [['key', 'val']] list
8499
+ * @param {array} attrs: [['key', 'val']]
8500
+ * @param {token} token: which token to add attributes
8501
+ * @returns token
8502
+ */
8503
+ utils$1.addAttrs = function (attrs, token) {
8504
+ for (let j = 0, l = attrs.length; j < l; ++j) {
8505
+ const key = attrs[j][0];
8506
+ if (key === 'class') {
8507
+ token.attrJoin('class', attrs[j][1]);
8508
+ } else if (key === 'css-module') {
8509
+ token.attrJoin('css-module', attrs[j][1]);
8510
+ } else {
8511
+ token.attrPush(attrs[j]);
8512
+ }
8513
+ }
8514
+ return token;
8515
+ };
8516
+
8517
+ /**
8518
+ * Does string have properly formatted curly?
8519
+ *
8520
+ * start: '{.a} asdf'
8521
+ * end: 'asdf {.a}'
8522
+ * only: '{.a}'
8523
+ *
8524
+ * @param {string} where to expect {} curly. start, end or only.
8525
+ * @return {function(string)} Function which testes if string has curly.
8526
+ */
8527
+ utils$1.hasDelimiters = function (where, options) {
8528
+
8529
+ if (!where) {
8530
+ throw new Error('Parameter `where` not passed. Should be "start", "end" or "only".');
8531
+ }
8532
+
8533
+ /**
8534
+ * @param {string} str
8535
+ * @return {boolean}
8536
+ */
8537
+ return function (str) {
8538
+ // we need minimum three chars, for example {b}
8539
+ const minCurlyLength = options.leftDelimiter.length + 1 + options.rightDelimiter.length;
8540
+ if (!str || typeof str !== 'string' || str.length < minCurlyLength) {
8541
+ return false;
8542
+ }
8543
+
8544
+ function validCurlyLength (curly) {
8545
+ const isClass = curly.charAt(options.leftDelimiter.length) === '.';
8546
+ const isId = curly.charAt(options.leftDelimiter.length) === '#';
8547
+ return (isClass || isId)
8548
+ ? curly.length >= (minCurlyLength + 1)
8549
+ : curly.length >= minCurlyLength;
8550
+ }
8551
+
8552
+ let start, end, slice, nextChar;
8553
+ const rightDelimiterMinimumShift = minCurlyLength - options.rightDelimiter.length;
8554
+ switch (where) {
8555
+ case 'start':
8556
+ // first char should be {, } found in char 2 or more
8557
+ slice = str.slice(0, options.leftDelimiter.length);
8558
+ start = slice === options.leftDelimiter ? 0 : -1;
8559
+ end = start === -1 ? -1 : str.indexOf(options.rightDelimiter, rightDelimiterMinimumShift);
8560
+ // check if next character is not one of the delimiters
8561
+ nextChar = str.charAt(end + options.rightDelimiter.length);
8562
+ if (nextChar && options.rightDelimiter.indexOf(nextChar) !== -1) {
8563
+ end = -1;
8564
+ }
8565
+ break;
8566
+
8567
+ case 'end':
8568
+ // last char should be }
8569
+ start = str.lastIndexOf(options.leftDelimiter);
8570
+ end = start === -1 ? -1 : str.indexOf(options.rightDelimiter, start + rightDelimiterMinimumShift);
8571
+ end = end === str.length - options.rightDelimiter.length ? end : -1;
8572
+ break;
8573
+
8574
+ case 'only':
8575
+ // '{.a}'
8576
+ slice = str.slice(0, options.leftDelimiter.length);
8577
+ start = slice === options.leftDelimiter ? 0 : -1;
8578
+ slice = str.slice(str.length - options.rightDelimiter.length);
8579
+ end = slice === options.rightDelimiter ? str.length - options.rightDelimiter.length : -1;
8580
+ break;
8581
+
8582
+ default:
8583
+ throw new Error(`Unexpected case ${where}, expected 'start', 'end' or 'only'`);
8584
+ }
8585
+
8586
+ return start !== -1 && end !== -1 && validCurlyLength(str.substring(start, end + options.rightDelimiter.length));
8587
+ };
8588
+ };
8589
+
8590
+ /**
8591
+ * Removes last curly from string.
8592
+ */
8593
+ utils$1.removeDelimiter = function (str, options) {
8594
+ const start = escapeRegExp(options.leftDelimiter);
8595
+ const end = escapeRegExp(options.rightDelimiter);
8596
+
8597
+ const curly = new RegExp(
8598
+ '[ \\n]?' + start + '[^' + start + end + ']+' + end + '$'
8599
+ );
8600
+ const pos = str.search(curly);
8601
+
8602
+ return pos !== -1 ? str.slice(0, pos) : str;
8603
+ };
8604
+
8605
+ /**
8606
+ * Escapes special characters in string s such that the string
8607
+ * can be used in `new RegExp`. For example "[" becomes "\\[".
8608
+ *
8609
+ * @param {string} s Regex string.
8610
+ * @return {string} Escaped string.
8611
+ */
8612
+ function escapeRegExp (s) {
8613
+ return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
8614
+ }
8615
+ utils$1.escapeRegExp = escapeRegExp;
8616
+
8617
+ /**
8618
+ * find corresponding opening block
8619
+ */
8620
+ utils$1.getMatchingOpeningToken = function (tokens, i) {
8621
+ if (tokens[i].type === 'softbreak') {
8622
+ return false;
8623
+ }
8624
+ // non closing blocks, example img
8625
+ if (tokens[i].nesting === 0) {
8626
+ return tokens[i];
8627
+ }
8628
+
8629
+ const level = tokens[i].level;
8630
+ const type = tokens[i].type.replace('_close', '_open');
8631
+
8632
+ for (; i >= 0; --i) {
8633
+ if (tokens[i].type === type && tokens[i].level === level) {
8634
+ return tokens[i];
8635
+ }
8636
+ }
8637
+
8638
+ return false;
8639
+ };
8640
+
8641
+
8642
+ /**
8643
+ * from https://github.com/markdown-it/markdown-it/blob/master/lib/common/utils.js
8644
+ */
8645
+ const HTML_ESCAPE_TEST_RE = /[&<>"]/;
8646
+ const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g;
8647
+ const HTML_REPLACEMENTS = {
8648
+ '&': '&amp;',
8649
+ '<': '&lt;',
8650
+ '>': '&gt;',
8651
+ '"': '&quot;'
8652
+ };
8653
+
8654
+ function replaceUnsafeChar(ch) {
8655
+ return HTML_REPLACEMENTS[ch];
8656
+ }
8657
+
8658
+ utils$1.escapeHtml = function (str) {
8659
+ if (HTML_ESCAPE_TEST_RE.test(str)) {
8660
+ return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar);
8661
+ }
8662
+ return str;
8663
+ };
8664
+
8665
+ /**
8666
+ * If a pattern matches the token stream,
8667
+ * then run transform.
8668
+ */
8669
+
8670
+ const utils = utils$1;
8671
+
8672
+ var patterns = options => {
8673
+ const __hr = new RegExp('^ {0,3}[-*_]{3,} ?'
8674
+ + utils.escapeRegExp(options.leftDelimiter)
8675
+ + '[^' + utils.escapeRegExp(options.rightDelimiter) + ']');
8676
+
8677
+ return ([
8678
+ {
8679
+ /**
8680
+ * ```python {.cls}
8681
+ * for i in range(10):
8682
+ * print(i)
8683
+ * ```
8684
+ */
8685
+ name: 'fenced code blocks',
8686
+ tests: [
8687
+ {
8688
+ shift: 0,
8689
+ block: true,
8690
+ info: utils.hasDelimiters('end', options)
8691
+ }
8692
+ ],
8693
+ transform: (tokens, i) => {
8694
+ const token = tokens[i];
8695
+ const start = token.info.lastIndexOf(options.leftDelimiter);
8696
+ const attrs = utils.getAttrs(token.info, start, options);
8697
+ utils.addAttrs(attrs, token);
8698
+ token.info = utils.removeDelimiter(token.info, options);
8699
+ }
8700
+ }, {
8701
+ /**
8702
+ * bla `click()`{.c} ![](img.png){.d}
8703
+ *
8704
+ * differs from 'inline attributes' as it does
8705
+ * not have a closing tag (nesting: -1)
8706
+ */
8707
+ name: 'inline nesting 0',
8708
+ tests: [
8709
+ {
8710
+ shift: 0,
8711
+ type: 'inline',
8712
+ children: [
8713
+ {
8714
+ shift: -1,
8715
+ type: (str) => str === 'image' || str === 'code_inline'
8716
+ }, {
8717
+ shift: 0,
8718
+ type: 'text',
8719
+ content: utils.hasDelimiters('start', options)
8720
+ }
8721
+ ]
8722
+ }
8723
+ ],
8724
+ transform: (tokens, i, j) => {
8725
+ const token = tokens[i].children[j];
8726
+ const endChar = token.content.indexOf(options.rightDelimiter);
8727
+ const attrToken = tokens[i].children[j - 1];
8728
+ const attrs = utils.getAttrs(token.content, 0, options);
8729
+ utils.addAttrs(attrs, attrToken);
8730
+ if (token.content.length === (endChar + options.rightDelimiter.length)) {
8731
+ tokens[i].children.splice(j, 1);
8732
+ } else {
8733
+ token.content = token.content.slice(endChar + options.rightDelimiter.length);
8734
+ }
8735
+ }
8736
+ }, {
8737
+ /**
8738
+ * | h1 |
8739
+ * | -- |
8740
+ * | c1 |
8741
+ *
8742
+ * {.c}
8743
+ */
8744
+ name: 'tables',
8745
+ tests: [
8746
+ {
8747
+ // let this token be i, such that for-loop continues at
8748
+ // next token after tokens.splice
8749
+ shift: 0,
8750
+ type: 'table_close'
8751
+ }, {
8752
+ shift: 1,
8753
+ type: 'paragraph_open'
8754
+ }, {
8755
+ shift: 2,
8756
+ type: 'inline',
8757
+ content: utils.hasDelimiters('only', options)
8758
+ }
8759
+ ],
8760
+ transform: (tokens, i) => {
8761
+ const token = tokens[i + 2];
8762
+ const tableOpen = utils.getMatchingOpeningToken(tokens, i);
8763
+ const attrs = utils.getAttrs(token.content, 0, options);
8764
+ // add attributes
8765
+ utils.addAttrs(attrs, tableOpen);
8766
+ // remove <p>{.c}</p>
8767
+ tokens.splice(i + 1, 3);
8768
+ }
8769
+ }, {
8770
+ /**
8771
+ * *emphasis*{.with attrs=1}
8772
+ */
8773
+ name: 'inline attributes',
8774
+ tests: [
8775
+ {
8776
+ shift: 0,
8777
+ type: 'inline',
8778
+ children: [
8779
+ {
8780
+ shift: -1,
8781
+ nesting: -1 // closing inline tag, </em>{.a}
8782
+ }, {
8783
+ shift: 0,
8784
+ type: 'text',
8785
+ content: utils.hasDelimiters('start', options)
8786
+ }
8787
+ ]
8788
+ }
8789
+ ],
8790
+ transform: (tokens, i, j) => {
8791
+ const token = tokens[i].children[j];
8792
+ const content = token.content;
8793
+ const attrs = utils.getAttrs(content, 0, options);
8794
+ const openingToken = utils.getMatchingOpeningToken(tokens[i].children, j - 1);
8795
+ utils.addAttrs(attrs, openingToken);
8796
+ token.content = content.slice(content.indexOf(options.rightDelimiter) + options.rightDelimiter.length);
8797
+ }
8798
+ }, {
8799
+ /**
8800
+ * - item
8801
+ * {.a}
8802
+ */
8803
+ name: 'list softbreak',
8804
+ tests: [
8805
+ {
8806
+ shift: -2,
8807
+ type: 'list_item_open'
8808
+ }, {
8809
+ shift: 0,
8810
+ type: 'inline',
8811
+ children: [
8812
+ {
8813
+ position: -2,
8814
+ type: 'softbreak'
8815
+ }, {
8816
+ position: -1,
8817
+ type: 'text',
8818
+ content: utils.hasDelimiters('only', options)
8819
+ }
8820
+ ]
8821
+ }
8822
+ ],
8823
+ transform: (tokens, i, j) => {
8824
+ const token = tokens[i].children[j];
8825
+ const content = token.content;
8826
+ const attrs = utils.getAttrs(content, 0, options);
8827
+ let ii = i - 2;
8828
+ while (tokens[ii - 1] &&
8829
+ tokens[ii - 1].type !== 'ordered_list_open' &&
8830
+ tokens[ii - 1].type !== 'bullet_list_open') { ii--; }
8831
+ utils.addAttrs(attrs, tokens[ii - 1]);
8832
+ tokens[i].children = tokens[i].children.slice(0, -2);
8833
+ }
8834
+ }, {
8835
+ /**
8836
+ * - nested list
8837
+ * - with double \n
8838
+ * {.a} <-- apply to nested ul
8839
+ *
8840
+ * {.b} <-- apply to root <ul>
8841
+ */
8842
+ name: 'list double softbreak',
8843
+ tests: [
8844
+ {
8845
+ // let this token be i = 0 so that we can erase
8846
+ // the <p>{.a}</p> tokens below
8847
+ shift: 0,
8848
+ type: (str) =>
8849
+ str === 'bullet_list_close' ||
8850
+ str === 'ordered_list_close'
8851
+ }, {
8852
+ shift: 1,
8853
+ type: 'paragraph_open'
8854
+ }, {
8855
+ shift: 2,
8856
+ type: 'inline',
8857
+ content: utils.hasDelimiters('only', options),
8858
+ children: (arr) => arr.length === 1
8859
+ }, {
8860
+ shift: 3,
8861
+ type: 'paragraph_close'
8862
+ }
8863
+ ],
8864
+ transform: (tokens, i) => {
8865
+ const token = tokens[i + 2];
8866
+ const content = token.content;
8867
+ const attrs = utils.getAttrs(content, 0, options);
8868
+ const openingToken = utils.getMatchingOpeningToken(tokens, i);
8869
+ utils.addAttrs(attrs, openingToken);
8870
+ tokens.splice(i + 1, 3);
8871
+ }
8872
+ }, {
8873
+ /**
8874
+ * - end of {.list-item}
8875
+ */
8876
+ name: 'list item end',
8877
+ tests: [
8878
+ {
8879
+ shift: -2,
8880
+ type: 'list_item_open'
8881
+ }, {
8882
+ shift: 0,
8883
+ type: 'inline',
8884
+ children: [
8885
+ {
8886
+ position: -1,
8887
+ type: 'text',
8888
+ content: utils.hasDelimiters('end', options)
8889
+ }
8890
+ ]
8891
+ }
8892
+ ],
8893
+ transform: (tokens, i, j) => {
8894
+ const token = tokens[i].children[j];
8895
+ const content = token.content;
8896
+ const attrs = utils.getAttrs(content, content.lastIndexOf(options.leftDelimiter), options);
8897
+ utils.addAttrs(attrs, tokens[i - 2]);
8898
+ const trimmed = content.slice(0, content.lastIndexOf(options.leftDelimiter));
8899
+ token.content = last$1(trimmed) !== ' ' ?
8900
+ trimmed : trimmed.slice(0, -1);
8901
+ }
8902
+ }, {
8903
+ /**
8904
+ * something with softbreak
8905
+ * {.cls}
8906
+ */
8907
+ name: '\n{.a} softbreak then curly in start',
8908
+ tests: [
8909
+ {
8910
+ shift: 0,
8911
+ type: 'inline',
8912
+ children: [
8913
+ {
8914
+ position: -2,
8915
+ type: 'softbreak'
8916
+ }, {
8917
+ position: -1,
8918
+ type: 'text',
8919
+ content: utils.hasDelimiters('only', options)
8920
+ }
8921
+ ]
8922
+ }
8923
+ ],
8924
+ transform: (tokens, i, j) => {
8925
+ const token = tokens[i].children[j];
8926
+ const attrs = utils.getAttrs(token.content, 0, options);
8927
+ // find last closing tag
8928
+ let ii = i + 1;
8929
+ while (tokens[ii + 1] && tokens[ii + 1].nesting === -1) { ii++; }
8930
+ const openingToken = utils.getMatchingOpeningToken(tokens, ii);
8931
+ utils.addAttrs(attrs, openingToken);
8932
+ tokens[i].children = tokens[i].children.slice(0, -2);
8933
+ }
8934
+ }, {
8935
+ /**
8936
+ * horizontal rule --- {#id}
8937
+ */
8938
+ name: 'horizontal rule',
8939
+ tests: [
8940
+ {
8941
+ shift: 0,
8942
+ type: 'paragraph_open'
8943
+ },
8944
+ {
8945
+ shift: 1,
8946
+ type: 'inline',
8947
+ children: (arr) => arr.length === 1,
8948
+ content: (str) => str.match(__hr) !== null,
8949
+ },
8950
+ {
8951
+ shift: 2,
8952
+ type: 'paragraph_close'
8953
+ }
8954
+ ],
8955
+ transform: (tokens, i) => {
8956
+ const token = tokens[i];
8957
+ token.type = 'hr';
8958
+ token.tag = 'hr';
8959
+ token.nesting = 0;
8960
+ const content = tokens[i + 1].content;
8961
+ const start = content.lastIndexOf(options.leftDelimiter);
8962
+ const attrs = utils.getAttrs(content, start, options);
8963
+ utils.addAttrs(attrs, token);
8964
+ token.markup = content;
8965
+ tokens.splice(i + 1, 2);
8966
+ }
8967
+ }, {
8968
+ /**
8969
+ * end of {.block}
8970
+ */
8971
+ name: 'end of block',
8972
+ tests: [
8973
+ {
8974
+ shift: 0,
8975
+ type: 'inline',
8976
+ children: [
8977
+ {
8978
+ position: -1,
8979
+ content: utils.hasDelimiters('end', options),
8980
+ type: (t) => t !== 'code_inline' && t !== 'math_inline'
8981
+ }
8982
+ ]
8983
+ }
8984
+ ],
8985
+ transform: (tokens, i, j) => {
8986
+ const token = tokens[i].children[j];
8987
+ const content = token.content;
8988
+ const attrs = utils.getAttrs(content, content.lastIndexOf(options.leftDelimiter), options);
8989
+ let ii = i + 1;
8990
+ while (tokens[ii + 1] && tokens[ii + 1].nesting === -1) { ii++; }
8991
+ const openingToken = utils.getMatchingOpeningToken(tokens, ii);
8992
+ utils.addAttrs(attrs, openingToken);
8993
+ const trimmed = content.slice(0, content.lastIndexOf(options.leftDelimiter));
8994
+ token.content = last$1(trimmed) !== ' ' ?
8995
+ trimmed : trimmed.slice(0, -1);
8996
+ }
8997
+ }
8998
+ ]);
8999
+ };
9000
+
9001
+ // get last element of array or string
9002
+ function last$1(arr) {
9003
+ return arr.slice(-1)[0];
9004
+ }
9005
+
9006
+ const patternsConfig = patterns;
9007
+
9008
+ const defaultOptions = {
9009
+ leftDelimiter: '{',
9010
+ rightDelimiter: '}',
9011
+ allowedAttributes: []
9012
+ };
9013
+
9014
+ var markdownItAttrs = function attributes(md, options_) {
9015
+ let options = Object.assign({}, defaultOptions);
9016
+ options = Object.assign(options, options_);
9017
+
9018
+ const patterns = patternsConfig(options);
9019
+
9020
+ function curlyAttrs(state) {
9021
+ const tokens = state.tokens;
9022
+
9023
+ for (let i = 0; i < tokens.length; i++) {
9024
+ for (let p = 0; p < patterns.length; p++) {
9025
+ const pattern = patterns[p];
9026
+ let j = null; // position of child with offset 0
9027
+ const match = pattern.tests.every(t => {
9028
+ const res = test(tokens, i, t);
9029
+ if (res.j !== null) { j = res.j; }
9030
+ return res.match;
9031
+ });
9032
+ if (match) {
9033
+ pattern.transform(tokens, i, j);
9034
+ if (pattern.name === 'inline attributes' || pattern.name === 'inline nesting 0') {
9035
+ // retry, may be several inline attributes
9036
+ p--;
9037
+ }
9038
+ }
9039
+ }
9040
+ }
9041
+ }
9042
+
9043
+ md.core.ruler.before('linkify', 'curly_attributes', curlyAttrs);
9044
+ };
9045
+
9046
+ /**
9047
+ * Test if t matches token stream.
9048
+ *
9049
+ * @param {array} tokens
9050
+ * @param {number} i
9051
+ * @param {object} t Test to match.
9052
+ * @return {object} { match: true|false, j: null|number }
9053
+ */
9054
+ function test(tokens, i, t) {
9055
+ const res = {
9056
+ match: false,
9057
+ j: null // position of child
9058
+ };
9059
+
9060
+ const ii = t.shift !== undefined
9061
+ ? i + t.shift
9062
+ : t.position;
9063
+
9064
+ if (t.shift !== undefined && ii < 0) {
9065
+ // we should never shift to negative indexes (rolling around to back of array)
9066
+ return res;
9067
+ }
9068
+
9069
+ const token = get(tokens, ii); // supports negative ii
9070
+
9071
+
9072
+ if (token === undefined) { return res; }
9073
+
9074
+ for (const key of Object.keys(t)) {
9075
+ if (key === 'shift' || key === 'position') { continue; }
9076
+
9077
+ if (token[key] === undefined) { return res; }
9078
+
9079
+ if (key === 'children' && isArrayOfObjects(t.children)) {
9080
+ if (token.children.length === 0) {
9081
+ return res;
9082
+ }
9083
+ let match;
9084
+ const childTests = t.children;
9085
+ const children = token.children;
9086
+ if (childTests.every(tt => tt.position !== undefined)) {
9087
+ // positions instead of shifts, do not loop all children
9088
+ match = childTests.every(tt => test(children, tt.position, tt).match);
9089
+ if (match) {
9090
+ // we may need position of child in transform
9091
+ const j = last(childTests).position;
9092
+ res.j = j >= 0 ? j : children.length + j;
9093
+ }
9094
+ } else {
9095
+ for (let j = 0; j < children.length; j++) {
9096
+ match = childTests.every(tt => test(children, j, tt).match);
9097
+ if (match) {
9098
+ res.j = j;
9099
+ // all tests true, continue with next key of pattern t
9100
+ break;
9101
+ }
9102
+ }
9103
+ }
9104
+
9105
+ if (match === false) { return res; }
9106
+
9107
+ continue;
9108
+ }
9109
+
9110
+ switch (typeof t[key]) {
9111
+ case 'boolean':
9112
+ case 'number':
9113
+ case 'string':
9114
+ if (token[key] !== t[key]) { return res; }
9115
+ break;
9116
+ case 'function':
9117
+ if (!t[key](token[key])) { return res; }
9118
+ break;
9119
+ case 'object':
9120
+ if (isArrayOfFunctions(t[key])) {
9121
+ const r = t[key].every(tt => tt(token[key]));
9122
+ if (r === false) { return res; }
9123
+ break;
9124
+ }
9125
+ // fall through for objects !== arrays of functions
9126
+ default:
9127
+ throw new Error(`Unknown type of pattern test (key: ${key}). Test should be of type boolean, number, string, function or array of functions.`);
9128
+ }
9129
+ }
9130
+
9131
+ // no tests returned false -> all tests returns true
9132
+ res.match = true;
9133
+ return res;
9134
+ }
9135
+
9136
+ function isArrayOfObjects(arr) {
9137
+ return Array.isArray(arr) && arr.length && arr.every(i => typeof i === 'object');
9138
+ }
9139
+
9140
+ function isArrayOfFunctions(arr) {
9141
+ return Array.isArray(arr) && arr.length && arr.every(i => typeof i === 'function');
9142
+ }
9143
+
9144
+ /**
9145
+ * Get n item of array. Supports negative n, where -1 is last
9146
+ * element in array.
9147
+ * @param {array} arr
9148
+ * @param {number} n
9149
+ */
9150
+ function get(arr, n) {
9151
+ return n >= 0 ? arr[n] : arr[arr.length + n];
9152
+ }
9153
+
9154
+ // get last element of array, safe - returns {} if not found
9155
+ function last(arr) {
9156
+ return arr.slice(-1)[0] || {};
9157
+ }
9158
+
9159
+ var markdownItAttrs$1 = /*@__PURE__*/highlight_js.getDefaultExportFromCjs(markdownItAttrs);
9160
+
8381
9161
  // Process ~subscript~
8382
9162
 
8383
9163
  // same as UNESCAPE_MD_RE plus a space
@@ -8500,6 +9280,1574 @@ function sup_plugin (md) {
8500
9280
  md.inline.ruler.after('emphasis', 'sup', superscript);
8501
9281
  }
8502
9282
 
9283
+ var purify = {exports: {}};
9284
+
9285
+ /*! @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 */
9286
+
9287
+ (function (module, exports) {
9288
+ (function (global, factory) {
9289
+ module.exports = factory() ;
9290
+ })(highlight_js.commonjsGlobal, (function () {
9291
+ const {
9292
+ entries,
9293
+ setPrototypeOf,
9294
+ isFrozen,
9295
+ getPrototypeOf,
9296
+ getOwnPropertyDescriptor
9297
+ } = Object;
9298
+ let {
9299
+ freeze,
9300
+ seal,
9301
+ create
9302
+ } = Object; // eslint-disable-line import/no-mutable-exports
9303
+ let {
9304
+ apply,
9305
+ construct
9306
+ } = typeof Reflect !== 'undefined' && Reflect;
9307
+ if (!freeze) {
9308
+ freeze = function freeze(x) {
9309
+ return x;
9310
+ };
9311
+ }
9312
+ if (!seal) {
9313
+ seal = function seal(x) {
9314
+ return x;
9315
+ };
9316
+ }
9317
+ if (!apply) {
9318
+ apply = function apply(fun, thisValue, args) {
9319
+ return fun.apply(thisValue, args);
9320
+ };
9321
+ }
9322
+ if (!construct) {
9323
+ construct = function construct(Func, args) {
9324
+ return new Func(...args);
9325
+ };
9326
+ }
9327
+ const arrayForEach = unapply(Array.prototype.forEach);
9328
+ const arrayPop = unapply(Array.prototype.pop);
9329
+ const arrayPush = unapply(Array.prototype.push);
9330
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
9331
+ const stringToString = unapply(String.prototype.toString);
9332
+ const stringMatch = unapply(String.prototype.match);
9333
+ const stringReplace = unapply(String.prototype.replace);
9334
+ const stringIndexOf = unapply(String.prototype.indexOf);
9335
+ const stringTrim = unapply(String.prototype.trim);
9336
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
9337
+ const regExpTest = unapply(RegExp.prototype.test);
9338
+ const typeErrorCreate = unconstruct(TypeError);
9339
+
9340
+ /**
9341
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
9342
+ *
9343
+ * @param {Function} func - The function to be wrapped and called.
9344
+ * @returns {Function} A new function that calls the given function with a specified thisArg and arguments.
9345
+ */
9346
+ function unapply(func) {
9347
+ return function (thisArg) {
9348
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
9349
+ args[_key - 1] = arguments[_key];
9350
+ }
9351
+ return apply(func, thisArg, args);
9352
+ };
9353
+ }
9354
+
9355
+ /**
9356
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
9357
+ *
9358
+ * @param {Function} func - The constructor function to be wrapped and called.
9359
+ * @returns {Function} A new function that constructs an instance of the given constructor function with the provided arguments.
9360
+ */
9361
+ function unconstruct(func) {
9362
+ return function () {
9363
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
9364
+ args[_key2] = arguments[_key2];
9365
+ }
9366
+ return construct(func, args);
9367
+ };
9368
+ }
9369
+
9370
+ /**
9371
+ * Add properties to a lookup table
9372
+ *
9373
+ * @param {Object} set - The set to which elements will be added.
9374
+ * @param {Array} array - The array containing elements to be added to the set.
9375
+ * @param {Function} transformCaseFunc - An optional function to transform the case of each element before adding to the set.
9376
+ * @returns {Object} The modified set with added elements.
9377
+ */
9378
+ function addToSet(set, array) {
9379
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
9380
+ if (setPrototypeOf) {
9381
+ // Make 'in' and truthy checks like Boolean(set.constructor)
9382
+ // independent of any properties defined on Object.prototype.
9383
+ // Prevent prototype setters from intercepting set as a this value.
9384
+ setPrototypeOf(set, null);
9385
+ }
9386
+ let l = array.length;
9387
+ while (l--) {
9388
+ let element = array[l];
9389
+ if (typeof element === 'string') {
9390
+ const lcElement = transformCaseFunc(element);
9391
+ if (lcElement !== element) {
9392
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
9393
+ if (!isFrozen(array)) {
9394
+ array[l] = lcElement;
9395
+ }
9396
+ element = lcElement;
9397
+ }
9398
+ }
9399
+ set[element] = true;
9400
+ }
9401
+ return set;
9402
+ }
9403
+
9404
+ /**
9405
+ * Clean up an array to harden against CSPP
9406
+ *
9407
+ * @param {Array} array - The array to be cleaned.
9408
+ * @returns {Array} The cleaned version of the array
9409
+ */
9410
+ function cleanArray(array) {
9411
+ for (let index = 0; index < array.length; index++) {
9412
+ const isPropertyExist = objectHasOwnProperty(array, index);
9413
+ if (!isPropertyExist) {
9414
+ array[index] = null;
9415
+ }
9416
+ }
9417
+ return array;
9418
+ }
9419
+
9420
+ /**
9421
+ * Shallow clone an object
9422
+ *
9423
+ * @param {Object} object - The object to be cloned.
9424
+ * @returns {Object} A new object that copies the original.
9425
+ */
9426
+ function clone(object) {
9427
+ const newObject = create(null);
9428
+ for (const [property, value] of entries(object)) {
9429
+ const isPropertyExist = objectHasOwnProperty(object, property);
9430
+ if (isPropertyExist) {
9431
+ if (Array.isArray(value)) {
9432
+ newObject[property] = cleanArray(value);
9433
+ } else if (value && typeof value === 'object' && value.constructor === Object) {
9434
+ newObject[property] = clone(value);
9435
+ } else {
9436
+ newObject[property] = value;
9437
+ }
9438
+ }
9439
+ }
9440
+ return newObject;
9441
+ }
9442
+
9443
+ /**
9444
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
9445
+ *
9446
+ * @param {Object} object - The object to look up the getter function in its prototype chain.
9447
+ * @param {String} prop - The property name for which to find the getter function.
9448
+ * @returns {Function} The getter function found in the prototype chain or a fallback function.
9449
+ */
9450
+ function lookupGetter(object, prop) {
9451
+ while (object !== null) {
9452
+ const desc = getOwnPropertyDescriptor(object, prop);
9453
+ if (desc) {
9454
+ if (desc.get) {
9455
+ return unapply(desc.get);
9456
+ }
9457
+ if (typeof desc.value === 'function') {
9458
+ return unapply(desc.value);
9459
+ }
9460
+ }
9461
+ object = getPrototypeOf(object);
9462
+ }
9463
+ function fallbackValue() {
9464
+ return null;
9465
+ }
9466
+ return fallbackValue;
9467
+ }
9468
+
9469
+ 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']);
9470
+
9471
+ // SVG
9472
+ 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']);
9473
+ 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']);
9474
+
9475
+ // List of SVG elements that are disallowed by default.
9476
+ // We still need to know them so that we can do namespace
9477
+ // checks properly in case one wants to add them to
9478
+ // allow-list.
9479
+ 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']);
9480
+ 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']);
9481
+
9482
+ // Similarly to SVG, we want to know all MathML elements,
9483
+ // even those that we disallow by default.
9484
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
9485
+ const text = freeze(['#text']);
9486
+
9487
+ 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']);
9488
+ 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']);
9489
+ 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']);
9490
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
9491
+
9492
+ // eslint-disable-next-line unicorn/better-regex
9493
+ const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
9494
+ const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
9495
+ const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
9496
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
9497
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
9498
+ 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
9499
+ );
9500
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
9501
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
9502
+ );
9503
+ const DOCTYPE_NAME = seal(/^html$/i);
9504
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
9505
+
9506
+ var EXPRESSIONS = /*#__PURE__*/Object.freeze({
9507
+ __proto__: null,
9508
+ MUSTACHE_EXPR: MUSTACHE_EXPR,
9509
+ ERB_EXPR: ERB_EXPR,
9510
+ TMPLIT_EXPR: TMPLIT_EXPR,
9511
+ DATA_ATTR: DATA_ATTR,
9512
+ ARIA_ATTR: ARIA_ATTR,
9513
+ IS_ALLOWED_URI: IS_ALLOWED_URI,
9514
+ IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
9515
+ ATTR_WHITESPACE: ATTR_WHITESPACE,
9516
+ DOCTYPE_NAME: DOCTYPE_NAME,
9517
+ CUSTOM_ELEMENT: CUSTOM_ELEMENT
9518
+ });
9519
+
9520
+ // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
9521
+ const NODE_TYPE = {
9522
+ element: 1,
9523
+ attribute: 2,
9524
+ text: 3,
9525
+ cdataSection: 4,
9526
+ entityReference: 5,
9527
+ // Deprecated
9528
+ entityNode: 6,
9529
+ // Deprecated
9530
+ progressingInstruction: 7,
9531
+ comment: 8,
9532
+ document: 9,
9533
+ documentType: 10,
9534
+ documentFragment: 11,
9535
+ notation: 12 // Deprecated
9536
+ };
9537
+ const getGlobal = function getGlobal() {
9538
+ return typeof window === 'undefined' ? null : window;
9539
+ };
9540
+
9541
+ /**
9542
+ * Creates a no-op policy for internal use only.
9543
+ * Don't export this function outside this module!
9544
+ * @param {TrustedTypePolicyFactory} trustedTypes The policy factory.
9545
+ * @param {HTMLScriptElement} purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
9546
+ * @return {TrustedTypePolicy} The policy created (or null, if Trusted Types
9547
+ * are not supported or creating the policy failed).
9548
+ */
9549
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
9550
+ if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
9551
+ return null;
9552
+ }
9553
+
9554
+ // Allow the callers to control the unique policy name
9555
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
9556
+ // Policy creation with duplicate names throws in Trusted Types.
9557
+ let suffix = null;
9558
+ const ATTR_NAME = 'data-tt-policy-suffix';
9559
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
9560
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
9561
+ }
9562
+ const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
9563
+ try {
9564
+ return trustedTypes.createPolicy(policyName, {
9565
+ createHTML(html) {
9566
+ return html;
9567
+ },
9568
+ createScriptURL(scriptUrl) {
9569
+ return scriptUrl;
9570
+ }
9571
+ });
9572
+ } catch (_) {
9573
+ // Policy creation failed (most likely another DOMPurify script has
9574
+ // already run). Skip creating the policy, as this will only cause errors
9575
+ // if TT are enforced.
9576
+ console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
9577
+ return null;
9578
+ }
9579
+ };
9580
+ function createDOMPurify() {
9581
+ let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
9582
+ const DOMPurify = root => createDOMPurify(root);
9583
+
9584
+ /**
9585
+ * Version label, exposed for easier checks
9586
+ * if DOMPurify is up to date or not
9587
+ */
9588
+ DOMPurify.version = '3.1.6';
9589
+
9590
+ /**
9591
+ * Array of elements that DOMPurify removed during sanitation.
9592
+ * Empty if nothing was removed.
9593
+ */
9594
+ DOMPurify.removed = [];
9595
+ if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document) {
9596
+ // Not running in a browser, provide a factory function
9597
+ // so that you can pass your own Window
9598
+ DOMPurify.isSupported = false;
9599
+ return DOMPurify;
9600
+ }
9601
+ let {
9602
+ document
9603
+ } = window;
9604
+ const originalDocument = document;
9605
+ const currentScript = originalDocument.currentScript;
9606
+ const {
9607
+ DocumentFragment,
9608
+ HTMLTemplateElement,
9609
+ Node,
9610
+ Element,
9611
+ NodeFilter,
9612
+ NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
9613
+ HTMLFormElement,
9614
+ DOMParser,
9615
+ trustedTypes
9616
+ } = window;
9617
+ const ElementPrototype = Element.prototype;
9618
+ const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
9619
+ const remove = lookupGetter(ElementPrototype, 'remove');
9620
+ const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
9621
+ const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
9622
+ const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
9623
+
9624
+ // As per issue #47, the web-components registry is inherited by a
9625
+ // new document created via createHTMLDocument. As per the spec
9626
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
9627
+ // a new empty registry is used when creating a template contents owner
9628
+ // document, so we use that as our parent document to ensure nothing
9629
+ // is inherited.
9630
+ if (typeof HTMLTemplateElement === 'function') {
9631
+ const template = document.createElement('template');
9632
+ if (template.content && template.content.ownerDocument) {
9633
+ document = template.content.ownerDocument;
9634
+ }
9635
+ }
9636
+ let trustedTypesPolicy;
9637
+ let emptyHTML = '';
9638
+ const {
9639
+ implementation,
9640
+ createNodeIterator,
9641
+ createDocumentFragment,
9642
+ getElementsByTagName
9643
+ } = document;
9644
+ const {
9645
+ importNode
9646
+ } = originalDocument;
9647
+ let hooks = {};
9648
+
9649
+ /**
9650
+ * Expose whether this browser supports running the full DOMPurify.
9651
+ */
9652
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
9653
+ const {
9654
+ MUSTACHE_EXPR,
9655
+ ERB_EXPR,
9656
+ TMPLIT_EXPR,
9657
+ DATA_ATTR,
9658
+ ARIA_ATTR,
9659
+ IS_SCRIPT_OR_DATA,
9660
+ ATTR_WHITESPACE,
9661
+ CUSTOM_ELEMENT
9662
+ } = EXPRESSIONS;
9663
+ let {
9664
+ IS_ALLOWED_URI: IS_ALLOWED_URI$1
9665
+ } = EXPRESSIONS;
9666
+
9667
+ /**
9668
+ * We consider the elements and attributes below to be safe. Ideally
9669
+ * don't add any new ones but feel free to remove unwanted ones.
9670
+ */
9671
+
9672
+ /* allowed element names */
9673
+ let ALLOWED_TAGS = null;
9674
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
9675
+
9676
+ /* Allowed attribute names */
9677
+ let ALLOWED_ATTR = null;
9678
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
9679
+
9680
+ /*
9681
+ * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
9682
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
9683
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
9684
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
9685
+ */
9686
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
9687
+ tagNameCheck: {
9688
+ writable: true,
9689
+ configurable: false,
9690
+ enumerable: true,
9691
+ value: null
9692
+ },
9693
+ attributeNameCheck: {
9694
+ writable: true,
9695
+ configurable: false,
9696
+ enumerable: true,
9697
+ value: null
9698
+ },
9699
+ allowCustomizedBuiltInElements: {
9700
+ writable: true,
9701
+ configurable: false,
9702
+ enumerable: true,
9703
+ value: false
9704
+ }
9705
+ }));
9706
+
9707
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
9708
+ let FORBID_TAGS = null;
9709
+
9710
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
9711
+ let FORBID_ATTR = null;
9712
+
9713
+ /* Decide if ARIA attributes are okay */
9714
+ let ALLOW_ARIA_ATTR = true;
9715
+
9716
+ /* Decide if custom data attributes are okay */
9717
+ let ALLOW_DATA_ATTR = true;
9718
+
9719
+ /* Decide if unknown protocols are okay */
9720
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
9721
+
9722
+ /* Decide if self-closing tags in attributes are allowed.
9723
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
9724
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
9725
+
9726
+ /* Output should be safe for common template engines.
9727
+ * This means, DOMPurify removes data attributes, mustaches and ERB
9728
+ */
9729
+ let SAFE_FOR_TEMPLATES = false;
9730
+
9731
+ /* Output should be safe even for XML used within HTML and alike.
9732
+ * This means, DOMPurify removes comments when containing risky content.
9733
+ */
9734
+ let SAFE_FOR_XML = true;
9735
+
9736
+ /* Decide if document with <html>... should be returned */
9737
+ let WHOLE_DOCUMENT = false;
9738
+
9739
+ /* Track whether config is already set on this instance of DOMPurify. */
9740
+ let SET_CONFIG = false;
9741
+
9742
+ /* Decide if all elements (e.g. style, script) must be children of
9743
+ * document.body. By default, browsers might move them to document.head */
9744
+ let FORCE_BODY = false;
9745
+
9746
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
9747
+ * string (or a TrustedHTML object if Trusted Types are supported).
9748
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
9749
+ */
9750
+ let RETURN_DOM = false;
9751
+
9752
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
9753
+ * string (or a TrustedHTML object if Trusted Types are supported) */
9754
+ let RETURN_DOM_FRAGMENT = false;
9755
+
9756
+ /* Try to return a Trusted Type object instead of a string, return a string in
9757
+ * case Trusted Types are not supported */
9758
+ let RETURN_TRUSTED_TYPE = false;
9759
+
9760
+ /* Output should be free from DOM clobbering attacks?
9761
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
9762
+ */
9763
+ let SANITIZE_DOM = true;
9764
+
9765
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
9766
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
9767
+ *
9768
+ * HTML/DOM spec rules that enable DOM Clobbering:
9769
+ * - Named Access on Window (§7.3.3)
9770
+ * - DOM Tree Accessors (§3.1.5)
9771
+ * - Form Element Parent-Child Relations (§4.10.3)
9772
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
9773
+ * - HTMLCollection (§4.2.10.2)
9774
+ *
9775
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
9776
+ * with a constant string, i.e., `user-content-`
9777
+ */
9778
+ let SANITIZE_NAMED_PROPS = false;
9779
+ const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
9780
+
9781
+ /* Keep element content when removing element? */
9782
+ let KEEP_CONTENT = true;
9783
+
9784
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
9785
+ * of importing it into a new Document and returning a sanitized copy */
9786
+ let IN_PLACE = false;
9787
+
9788
+ /* Allow usage of profiles like html, svg and mathMl */
9789
+ let USE_PROFILES = {};
9790
+
9791
+ /* Tags to ignore content of when KEEP_CONTENT is true */
9792
+ let FORBID_CONTENTS = null;
9793
+ 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']);
9794
+
9795
+ /* Tags that are safe for data: URIs */
9796
+ let DATA_URI_TAGS = null;
9797
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
9798
+
9799
+ /* Attributes safe for values like "javascript:" */
9800
+ let URI_SAFE_ATTRIBUTES = null;
9801
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
9802
+ const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
9803
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
9804
+ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
9805
+ /* Document namespace */
9806
+ let NAMESPACE = HTML_NAMESPACE;
9807
+ let IS_EMPTY_INPUT = false;
9808
+
9809
+ /* Allowed XHTML+XML namespaces */
9810
+ let ALLOWED_NAMESPACES = null;
9811
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
9812
+
9813
+ /* Parsing of strict XHTML documents */
9814
+ let PARSER_MEDIA_TYPE = null;
9815
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
9816
+ const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
9817
+ let transformCaseFunc = null;
9818
+
9819
+ /* Keep a reference to config to pass to hooks */
9820
+ let CONFIG = null;
9821
+
9822
+ /* Ideally, do not touch anything below this line */
9823
+ /* ______________________________________________ */
9824
+
9825
+ const formElement = document.createElement('form');
9826
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
9827
+ return testValue instanceof RegExp || testValue instanceof Function;
9828
+ };
9829
+
9830
+ /**
9831
+ * _parseConfig
9832
+ *
9833
+ * @param {Object} cfg optional config literal
9834
+ */
9835
+ // eslint-disable-next-line complexity
9836
+ const _parseConfig = function _parseConfig() {
9837
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
9838
+ if (CONFIG && CONFIG === cfg) {
9839
+ return;
9840
+ }
9841
+
9842
+ /* Shield configuration object from tampering */
9843
+ if (!cfg || typeof cfg !== 'object') {
9844
+ cfg = {};
9845
+ }
9846
+
9847
+ /* Shield configuration object from prototype pollution */
9848
+ cfg = clone(cfg);
9849
+ PARSER_MEDIA_TYPE =
9850
+ // eslint-disable-next-line unicorn/prefer-includes
9851
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
9852
+
9853
+ // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
9854
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
9855
+
9856
+ /* Set configuration parameters */
9857
+ ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
9858
+ ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
9859
+ ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
9860
+ URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES),
9861
+ // eslint-disable-line indent
9862
+ cfg.ADD_URI_SAFE_ATTR,
9863
+ // eslint-disable-line indent
9864
+ transformCaseFunc // eslint-disable-line indent
9865
+ ) // eslint-disable-line indent
9866
+ : DEFAULT_URI_SAFE_ATTRIBUTES;
9867
+ DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS),
9868
+ // eslint-disable-line indent
9869
+ cfg.ADD_DATA_URI_TAGS,
9870
+ // eslint-disable-line indent
9871
+ transformCaseFunc // eslint-disable-line indent
9872
+ ) // eslint-disable-line indent
9873
+ : DEFAULT_DATA_URI_TAGS;
9874
+ FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
9875
+ FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
9876
+ FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
9877
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
9878
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
9879
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
9880
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
9881
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
9882
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
9883
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
9884
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
9885
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
9886
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
9887
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
9888
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
9889
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
9890
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
9891
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
9892
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
9893
+ IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
9894
+ NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
9895
+ CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
9896
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
9897
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
9898
+ }
9899
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
9900
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
9901
+ }
9902
+ if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
9903
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
9904
+ }
9905
+ if (SAFE_FOR_TEMPLATES) {
9906
+ ALLOW_DATA_ATTR = false;
9907
+ }
9908
+ if (RETURN_DOM_FRAGMENT) {
9909
+ RETURN_DOM = true;
9910
+ }
9911
+
9912
+ /* Parse profile info */
9913
+ if (USE_PROFILES) {
9914
+ ALLOWED_TAGS = addToSet({}, text);
9915
+ ALLOWED_ATTR = [];
9916
+ if (USE_PROFILES.html === true) {
9917
+ addToSet(ALLOWED_TAGS, html$1);
9918
+ addToSet(ALLOWED_ATTR, html);
9919
+ }
9920
+ if (USE_PROFILES.svg === true) {
9921
+ addToSet(ALLOWED_TAGS, svg$1);
9922
+ addToSet(ALLOWED_ATTR, svg);
9923
+ addToSet(ALLOWED_ATTR, xml);
9924
+ }
9925
+ if (USE_PROFILES.svgFilters === true) {
9926
+ addToSet(ALLOWED_TAGS, svgFilters);
9927
+ addToSet(ALLOWED_ATTR, svg);
9928
+ addToSet(ALLOWED_ATTR, xml);
9929
+ }
9930
+ if (USE_PROFILES.mathMl === true) {
9931
+ addToSet(ALLOWED_TAGS, mathMl$1);
9932
+ addToSet(ALLOWED_ATTR, mathMl);
9933
+ addToSet(ALLOWED_ATTR, xml);
9934
+ }
9935
+ }
9936
+
9937
+ /* Merge configuration parameters */
9938
+ if (cfg.ADD_TAGS) {
9939
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
9940
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
9941
+ }
9942
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
9943
+ }
9944
+ if (cfg.ADD_ATTR) {
9945
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
9946
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
9947
+ }
9948
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
9949
+ }
9950
+ if (cfg.ADD_URI_SAFE_ATTR) {
9951
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
9952
+ }
9953
+ if (cfg.FORBID_CONTENTS) {
9954
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
9955
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
9956
+ }
9957
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
9958
+ }
9959
+
9960
+ /* Add #text in case KEEP_CONTENT is set to true */
9961
+ if (KEEP_CONTENT) {
9962
+ ALLOWED_TAGS['#text'] = true;
9963
+ }
9964
+
9965
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
9966
+ if (WHOLE_DOCUMENT) {
9967
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
9968
+ }
9969
+
9970
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
9971
+ if (ALLOWED_TAGS.table) {
9972
+ addToSet(ALLOWED_TAGS, ['tbody']);
9973
+ delete FORBID_TAGS.tbody;
9974
+ }
9975
+ if (cfg.TRUSTED_TYPES_POLICY) {
9976
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
9977
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
9978
+ }
9979
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
9980
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
9981
+ }
9982
+
9983
+ // Overwrite existing TrustedTypes policy.
9984
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
9985
+
9986
+ // Sign local variables required by `sanitize`.
9987
+ emptyHTML = trustedTypesPolicy.createHTML('');
9988
+ } else {
9989
+ // Uninitialized policy, attempt to initialize the internal dompurify policy.
9990
+ if (trustedTypesPolicy === undefined) {
9991
+ trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
9992
+ }
9993
+
9994
+ // If creating the internal policy succeeded sign internal variables.
9995
+ if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
9996
+ emptyHTML = trustedTypesPolicy.createHTML('');
9997
+ }
9998
+ }
9999
+
10000
+ // Prevent further manipulation of configuration.
10001
+ // Not available in IE8, Safari 5, etc.
10002
+ if (freeze) {
10003
+ freeze(cfg);
10004
+ }
10005
+ CONFIG = cfg;
10006
+ };
10007
+ const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
10008
+ const HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'annotation-xml']);
10009
+
10010
+ // Certain elements are allowed in both SVG and HTML
10011
+ // namespace. We need to specify them explicitly
10012
+ // so that they don't get erroneously deleted from
10013
+ // HTML namespace.
10014
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
10015
+
10016
+ /* Keep track of all possible SVG and MathML tags
10017
+ * so that we can perform the namespace checks
10018
+ * correctly. */
10019
+ const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
10020
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
10021
+
10022
+ /**
10023
+ * @param {Element} element a DOM element whose namespace is being checked
10024
+ * @returns {boolean} Return false if the element has a
10025
+ * namespace that a spec-compliant parser would never
10026
+ * return. Return true otherwise.
10027
+ */
10028
+ const _checkValidNamespace = function _checkValidNamespace(element) {
10029
+ let parent = getParentNode(element);
10030
+
10031
+ // In JSDOM, if we're inside shadow DOM, then parentNode
10032
+ // can be null. We just simulate parent in this case.
10033
+ if (!parent || !parent.tagName) {
10034
+ parent = {
10035
+ namespaceURI: NAMESPACE,
10036
+ tagName: 'template'
10037
+ };
10038
+ }
10039
+ const tagName = stringToLowerCase(element.tagName);
10040
+ const parentTagName = stringToLowerCase(parent.tagName);
10041
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
10042
+ return false;
10043
+ }
10044
+ if (element.namespaceURI === SVG_NAMESPACE) {
10045
+ // The only way to switch from HTML namespace to SVG
10046
+ // is via <svg>. If it happens via any other tag, then
10047
+ // it should be killed.
10048
+ if (parent.namespaceURI === HTML_NAMESPACE) {
10049
+ return tagName === 'svg';
10050
+ }
10051
+
10052
+ // The only way to switch from MathML to SVG is via`
10053
+ // svg if parent is either <annotation-xml> or MathML
10054
+ // text integration points.
10055
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
10056
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
10057
+ }
10058
+
10059
+ // We only allow elements that are defined in SVG
10060
+ // spec. All others are disallowed in SVG namespace.
10061
+ return Boolean(ALL_SVG_TAGS[tagName]);
10062
+ }
10063
+ if (element.namespaceURI === MATHML_NAMESPACE) {
10064
+ // The only way to switch from HTML namespace to MathML
10065
+ // is via <math>. If it happens via any other tag, then
10066
+ // it should be killed.
10067
+ if (parent.namespaceURI === HTML_NAMESPACE) {
10068
+ return tagName === 'math';
10069
+ }
10070
+
10071
+ // The only way to switch from SVG to MathML is via
10072
+ // <math> and HTML integration points
10073
+ if (parent.namespaceURI === SVG_NAMESPACE) {
10074
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
10075
+ }
10076
+
10077
+ // We only allow elements that are defined in MathML
10078
+ // spec. All others are disallowed in MathML namespace.
10079
+ return Boolean(ALL_MATHML_TAGS[tagName]);
10080
+ }
10081
+ if (element.namespaceURI === HTML_NAMESPACE) {
10082
+ // The only way to switch from SVG to HTML is via
10083
+ // HTML integration points, and from MathML to HTML
10084
+ // is via MathML text integration points
10085
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
10086
+ return false;
10087
+ }
10088
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
10089
+ return false;
10090
+ }
10091
+
10092
+ // We disallow tags that are specific for MathML
10093
+ // or SVG and should never appear in HTML namespace
10094
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
10095
+ }
10096
+
10097
+ // For XHTML and XML documents that support custom namespaces
10098
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
10099
+ return true;
10100
+ }
10101
+
10102
+ // The code should never reach this place (this means
10103
+ // that the element somehow got namespace that is not
10104
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
10105
+ // Return false just in case.
10106
+ return false;
10107
+ };
10108
+
10109
+ /**
10110
+ * _forceRemove
10111
+ *
10112
+ * @param {Node} node a DOM node
10113
+ */
10114
+ const _forceRemove = function _forceRemove(node) {
10115
+ arrayPush(DOMPurify.removed, {
10116
+ element: node
10117
+ });
10118
+ try {
10119
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
10120
+ getParentNode(node).removeChild(node);
10121
+ } catch (_) {
10122
+ remove(node);
10123
+ }
10124
+ };
10125
+
10126
+ /**
10127
+ * _removeAttribute
10128
+ *
10129
+ * @param {String} name an Attribute name
10130
+ * @param {Node} node a DOM node
10131
+ */
10132
+ const _removeAttribute = function _removeAttribute(name, node) {
10133
+ try {
10134
+ arrayPush(DOMPurify.removed, {
10135
+ attribute: node.getAttributeNode(name),
10136
+ from: node
10137
+ });
10138
+ } catch (_) {
10139
+ arrayPush(DOMPurify.removed, {
10140
+ attribute: null,
10141
+ from: node
10142
+ });
10143
+ }
10144
+ node.removeAttribute(name);
10145
+
10146
+ // We void attribute values for unremovable "is"" attributes
10147
+ if (name === 'is' && !ALLOWED_ATTR[name]) {
10148
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
10149
+ try {
10150
+ _forceRemove(node);
10151
+ } catch (_) {}
10152
+ } else {
10153
+ try {
10154
+ node.setAttribute(name, '');
10155
+ } catch (_) {}
10156
+ }
10157
+ }
10158
+ };
10159
+
10160
+ /**
10161
+ * _initDocument
10162
+ *
10163
+ * @param {String} dirty a string of dirty markup
10164
+ * @return {Document} a DOM, filled with the dirty markup
10165
+ */
10166
+ const _initDocument = function _initDocument(dirty) {
10167
+ /* Create a HTML document */
10168
+ let doc = null;
10169
+ let leadingWhitespace = null;
10170
+ if (FORCE_BODY) {
10171
+ dirty = '<remove></remove>' + dirty;
10172
+ } else {
10173
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
10174
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
10175
+ leadingWhitespace = matches && matches[0];
10176
+ }
10177
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
10178
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
10179
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
10180
+ }
10181
+ const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
10182
+ /*
10183
+ * Use the DOMParser API by default, fallback later if needs be
10184
+ * DOMParser not work for svg when has multiple root element.
10185
+ */
10186
+ if (NAMESPACE === HTML_NAMESPACE) {
10187
+ try {
10188
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
10189
+ } catch (_) {}
10190
+ }
10191
+
10192
+ /* Use createHTMLDocument in case DOMParser is not available */
10193
+ if (!doc || !doc.documentElement) {
10194
+ doc = implementation.createDocument(NAMESPACE, 'template', null);
10195
+ try {
10196
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
10197
+ } catch (_) {
10198
+ // Syntax error if dirtyPayload is invalid xml
10199
+ }
10200
+ }
10201
+ const body = doc.body || doc.documentElement;
10202
+ if (dirty && leadingWhitespace) {
10203
+ body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
10204
+ }
10205
+
10206
+ /* Work on whole document or just its body */
10207
+ if (NAMESPACE === HTML_NAMESPACE) {
10208
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
10209
+ }
10210
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
10211
+ };
10212
+
10213
+ /**
10214
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
10215
+ *
10216
+ * @param {Node} root The root element or node to start traversing on.
10217
+ * @return {NodeIterator} The created NodeIterator
10218
+ */
10219
+ const _createNodeIterator = function _createNodeIterator(root) {
10220
+ return createNodeIterator.call(root.ownerDocument || root, root,
10221
+ // eslint-disable-next-line no-bitwise
10222
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
10223
+ };
10224
+
10225
+ /**
10226
+ * _isClobbered
10227
+ *
10228
+ * @param {Node} elm element to check for clobbering attacks
10229
+ * @return {Boolean} true if clobbered, false if safe
10230
+ */
10231
+ const _isClobbered = function _isClobbered(elm) {
10232
+ 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');
10233
+ };
10234
+
10235
+ /**
10236
+ * Checks whether the given object is a DOM node.
10237
+ *
10238
+ * @param {Node} object object to check whether it's a DOM node
10239
+ * @return {Boolean} true is object is a DOM node
10240
+ */
10241
+ const _isNode = function _isNode(object) {
10242
+ return typeof Node === 'function' && object instanceof Node;
10243
+ };
10244
+
10245
+ /**
10246
+ * _executeHook
10247
+ * Execute user configurable hooks
10248
+ *
10249
+ * @param {String} entryPoint Name of the hook's entry point
10250
+ * @param {Node} currentNode node to work on with the hook
10251
+ * @param {Object} data additional hook parameters
10252
+ */
10253
+ const _executeHook = function _executeHook(entryPoint, currentNode, data) {
10254
+ if (!hooks[entryPoint]) {
10255
+ return;
10256
+ }
10257
+ arrayForEach(hooks[entryPoint], hook => {
10258
+ hook.call(DOMPurify, currentNode, data, CONFIG);
10259
+ });
10260
+ };
10261
+
10262
+ /**
10263
+ * _sanitizeElements
10264
+ *
10265
+ * @protect nodeName
10266
+ * @protect textContent
10267
+ * @protect removeChild
10268
+ *
10269
+ * @param {Node} currentNode to check for permission to exist
10270
+ * @return {Boolean} true if node was killed, false if left alive
10271
+ */
10272
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
10273
+ let content = null;
10274
+
10275
+ /* Execute a hook if present */
10276
+ _executeHook('beforeSanitizeElements', currentNode, null);
10277
+
10278
+ /* Check if element is clobbered or can clobber */
10279
+ if (_isClobbered(currentNode)) {
10280
+ _forceRemove(currentNode);
10281
+ return true;
10282
+ }
10283
+
10284
+ /* Now let's check the element's type and name */
10285
+ const tagName = transformCaseFunc(currentNode.nodeName);
10286
+
10287
+ /* Execute a hook if present */
10288
+ _executeHook('uponSanitizeElement', currentNode, {
10289
+ tagName,
10290
+ allowedTags: ALLOWED_TAGS
10291
+ });
10292
+
10293
+ /* Detect mXSS attempts abusing namespace confusion */
10294
+ if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
10295
+ _forceRemove(currentNode);
10296
+ return true;
10297
+ }
10298
+
10299
+ /* Remove any occurrence of processing instructions */
10300
+ if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
10301
+ _forceRemove(currentNode);
10302
+ return true;
10303
+ }
10304
+
10305
+ /* Remove any kind of possibly harmful comments */
10306
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
10307
+ _forceRemove(currentNode);
10308
+ return true;
10309
+ }
10310
+
10311
+ /* Remove element if anything forbids its presence */
10312
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
10313
+ /* Check if we have a custom element to handle */
10314
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
10315
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
10316
+ return false;
10317
+ }
10318
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
10319
+ return false;
10320
+ }
10321
+ }
10322
+
10323
+ /* Keep content except for bad-listed elements */
10324
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
10325
+ const parentNode = getParentNode(currentNode) || currentNode.parentNode;
10326
+ const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
10327
+ if (childNodes && parentNode) {
10328
+ const childCount = childNodes.length;
10329
+ for (let i = childCount - 1; i >= 0; --i) {
10330
+ const childClone = cloneNode(childNodes[i], true);
10331
+ childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
10332
+ parentNode.insertBefore(childClone, getNextSibling(currentNode));
10333
+ }
10334
+ }
10335
+ }
10336
+ _forceRemove(currentNode);
10337
+ return true;
10338
+ }
10339
+
10340
+ /* Check whether element has a valid namespace */
10341
+ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
10342
+ _forceRemove(currentNode);
10343
+ return true;
10344
+ }
10345
+
10346
+ /* Make sure that older browsers don't get fallback-tag mXSS */
10347
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
10348
+ _forceRemove(currentNode);
10349
+ return true;
10350
+ }
10351
+
10352
+ /* Sanitize element content to be template-safe */
10353
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
10354
+ /* Get the element's text content */
10355
+ content = currentNode.textContent;
10356
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
10357
+ content = stringReplace(content, expr, ' ');
10358
+ });
10359
+ if (currentNode.textContent !== content) {
10360
+ arrayPush(DOMPurify.removed, {
10361
+ element: currentNode.cloneNode()
10362
+ });
10363
+ currentNode.textContent = content;
10364
+ }
10365
+ }
10366
+
10367
+ /* Execute a hook if present */
10368
+ _executeHook('afterSanitizeElements', currentNode, null);
10369
+ return false;
10370
+ };
10371
+
10372
+ /**
10373
+ * _isValidAttribute
10374
+ *
10375
+ * @param {string} lcTag Lowercase tag name of containing element.
10376
+ * @param {string} lcName Lowercase attribute name.
10377
+ * @param {string} value Attribute value.
10378
+ * @return {Boolean} Returns true if `value` is valid, otherwise false.
10379
+ */
10380
+ // eslint-disable-next-line complexity
10381
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
10382
+ /* Make sure attribute cannot clobber */
10383
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
10384
+ return false;
10385
+ }
10386
+
10387
+ /* Allow valid data-* attributes: At least one character after "-"
10388
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
10389
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
10390
+ We don't need to check the value; it's always URI safe. */
10391
+ 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]) {
10392
+ if (
10393
+ // First condition does a very basic check if a) it's basically a valid custom element tagname AND
10394
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
10395
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
10396
+ _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)) ||
10397
+ // Alternative, second condition checks if it's an `is`-attribute, AND
10398
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
10399
+ 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 {
10400
+ return false;
10401
+ }
10402
+ /* Check value is safe. First, is attr inert? If so, is safe */
10403
+ } 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) {
10404
+ return false;
10405
+ } else ;
10406
+ return true;
10407
+ };
10408
+
10409
+ /**
10410
+ * _isBasicCustomElement
10411
+ * checks if at least one dash is included in tagName, and it's not the first char
10412
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
10413
+ *
10414
+ * @param {string} tagName name of the tag of the node to sanitize
10415
+ * @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
10416
+ */
10417
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
10418
+ return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
10419
+ };
10420
+
10421
+ /**
10422
+ * _sanitizeAttributes
10423
+ *
10424
+ * @protect attributes
10425
+ * @protect nodeName
10426
+ * @protect removeAttribute
10427
+ * @protect setAttribute
10428
+ *
10429
+ * @param {Node} currentNode to sanitize
10430
+ */
10431
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
10432
+ /* Execute a hook if present */
10433
+ _executeHook('beforeSanitizeAttributes', currentNode, null);
10434
+ const {
10435
+ attributes
10436
+ } = currentNode;
10437
+
10438
+ /* Check if we have attributes; if not we might have a text node */
10439
+ if (!attributes) {
10440
+ return;
10441
+ }
10442
+ const hookEvent = {
10443
+ attrName: '',
10444
+ attrValue: '',
10445
+ keepAttr: true,
10446
+ allowedAttributes: ALLOWED_ATTR
10447
+ };
10448
+ let l = attributes.length;
10449
+
10450
+ /* Go backwards over all attributes; safely remove bad ones */
10451
+ while (l--) {
10452
+ const attr = attributes[l];
10453
+ const {
10454
+ name,
10455
+ namespaceURI,
10456
+ value: attrValue
10457
+ } = attr;
10458
+ const lcName = transformCaseFunc(name);
10459
+ let value = name === 'value' ? attrValue : stringTrim(attrValue);
10460
+
10461
+ /* Execute a hook if present */
10462
+ hookEvent.attrName = lcName;
10463
+ hookEvent.attrValue = value;
10464
+ hookEvent.keepAttr = true;
10465
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
10466
+ _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
10467
+ value = hookEvent.attrValue;
10468
+
10469
+ /* Work around a security issue with comments inside attributes */
10470
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
10471
+ _removeAttribute(name, currentNode);
10472
+ continue;
10473
+ }
10474
+
10475
+ /* Did the hooks approve of the attribute? */
10476
+ if (hookEvent.forceKeepAttr) {
10477
+ continue;
10478
+ }
10479
+
10480
+ /* Remove attribute */
10481
+ _removeAttribute(name, currentNode);
10482
+
10483
+ /* Did the hooks approve of the attribute? */
10484
+ if (!hookEvent.keepAttr) {
10485
+ continue;
10486
+ }
10487
+
10488
+ /* Work around a security issue in jQuery 3.0 */
10489
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
10490
+ _removeAttribute(name, currentNode);
10491
+ continue;
10492
+ }
10493
+
10494
+ /* Sanitize attribute content to be template-safe */
10495
+ if (SAFE_FOR_TEMPLATES) {
10496
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
10497
+ value = stringReplace(value, expr, ' ');
10498
+ });
10499
+ }
10500
+
10501
+ /* Is `value` valid for this attribute? */
10502
+ const lcTag = transformCaseFunc(currentNode.nodeName);
10503
+ if (!_isValidAttribute(lcTag, lcName, value)) {
10504
+ continue;
10505
+ }
10506
+
10507
+ /* Full DOM Clobbering protection via namespace isolation,
10508
+ * Prefix id and name attributes with `user-content-`
10509
+ */
10510
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
10511
+ // Remove the attribute with this value
10512
+ _removeAttribute(name, currentNode);
10513
+
10514
+ // Prefix the value and later re-create the attribute with the sanitized value
10515
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
10516
+ }
10517
+
10518
+ /* Handle attributes that require Trusted Types */
10519
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
10520
+ if (namespaceURI) ; else {
10521
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
10522
+ case 'TrustedHTML':
10523
+ {
10524
+ value = trustedTypesPolicy.createHTML(value);
10525
+ break;
10526
+ }
10527
+ case 'TrustedScriptURL':
10528
+ {
10529
+ value = trustedTypesPolicy.createScriptURL(value);
10530
+ break;
10531
+ }
10532
+ }
10533
+ }
10534
+ }
10535
+
10536
+ /* Handle invalid data-* attribute set by try-catching it */
10537
+ try {
10538
+ if (namespaceURI) {
10539
+ currentNode.setAttributeNS(namespaceURI, name, value);
10540
+ } else {
10541
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
10542
+ currentNode.setAttribute(name, value);
10543
+ }
10544
+ if (_isClobbered(currentNode)) {
10545
+ _forceRemove(currentNode);
10546
+ } else {
10547
+ arrayPop(DOMPurify.removed);
10548
+ }
10549
+ } catch (_) {}
10550
+ }
10551
+
10552
+ /* Execute a hook if present */
10553
+ _executeHook('afterSanitizeAttributes', currentNode, null);
10554
+ };
10555
+
10556
+ /**
10557
+ * _sanitizeShadowDOM
10558
+ *
10559
+ * @param {DocumentFragment} fragment to iterate over recursively
10560
+ */
10561
+ const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
10562
+ let shadowNode = null;
10563
+ const shadowIterator = _createNodeIterator(fragment);
10564
+
10565
+ /* Execute a hook if present */
10566
+ _executeHook('beforeSanitizeShadowDOM', fragment, null);
10567
+ while (shadowNode = shadowIterator.nextNode()) {
10568
+ /* Execute a hook if present */
10569
+ _executeHook('uponSanitizeShadowNode', shadowNode, null);
10570
+
10571
+ /* Sanitize tags and elements */
10572
+ if (_sanitizeElements(shadowNode)) {
10573
+ continue;
10574
+ }
10575
+
10576
+ /* Deep shadow DOM detected */
10577
+ if (shadowNode.content instanceof DocumentFragment) {
10578
+ _sanitizeShadowDOM(shadowNode.content);
10579
+ }
10580
+
10581
+ /* Check attributes, sanitize if necessary */
10582
+ _sanitizeAttributes(shadowNode);
10583
+ }
10584
+
10585
+ /* Execute a hook if present */
10586
+ _executeHook('afterSanitizeShadowDOM', fragment, null);
10587
+ };
10588
+
10589
+ /**
10590
+ * Sanitize
10591
+ * Public method providing core sanitation functionality
10592
+ *
10593
+ * @param {String|Node} dirty string or DOM node
10594
+ * @param {Object} cfg object
10595
+ */
10596
+ // eslint-disable-next-line complexity
10597
+ DOMPurify.sanitize = function (dirty) {
10598
+ let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10599
+ let body = null;
10600
+ let importedNode = null;
10601
+ let currentNode = null;
10602
+ let returnNode = null;
10603
+ /* Make sure we have a string to sanitize.
10604
+ DO NOT return early, as this will return the wrong type if
10605
+ the user has requested a DOM object rather than a string */
10606
+ IS_EMPTY_INPUT = !dirty;
10607
+ if (IS_EMPTY_INPUT) {
10608
+ dirty = '<!-->';
10609
+ }
10610
+
10611
+ /* Stringify, in case dirty is an object */
10612
+ if (typeof dirty !== 'string' && !_isNode(dirty)) {
10613
+ if (typeof dirty.toString === 'function') {
10614
+ dirty = dirty.toString();
10615
+ if (typeof dirty !== 'string') {
10616
+ throw typeErrorCreate('dirty is not a string, aborting');
10617
+ }
10618
+ } else {
10619
+ throw typeErrorCreate('toString is not a function');
10620
+ }
10621
+ }
10622
+
10623
+ /* Return dirty HTML if DOMPurify cannot run */
10624
+ if (!DOMPurify.isSupported) {
10625
+ return dirty;
10626
+ }
10627
+
10628
+ /* Assign config vars */
10629
+ if (!SET_CONFIG) {
10630
+ _parseConfig(cfg);
10631
+ }
10632
+
10633
+ /* Clean up removed elements */
10634
+ DOMPurify.removed = [];
10635
+
10636
+ /* Check if dirty is correctly typed for IN_PLACE */
10637
+ if (typeof dirty === 'string') {
10638
+ IN_PLACE = false;
10639
+ }
10640
+ if (IN_PLACE) {
10641
+ /* Do some early pre-sanitization to avoid unsafe root nodes */
10642
+ if (dirty.nodeName) {
10643
+ const tagName = transformCaseFunc(dirty.nodeName);
10644
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
10645
+ throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
10646
+ }
10647
+ }
10648
+ } else if (dirty instanceof Node) {
10649
+ /* If dirty is a DOM element, append to an empty document to avoid
10650
+ elements being stripped by the parser */
10651
+ body = _initDocument('<!---->');
10652
+ importedNode = body.ownerDocument.importNode(dirty, true);
10653
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
10654
+ /* Node is already a body, use as is */
10655
+ body = importedNode;
10656
+ } else if (importedNode.nodeName === 'HTML') {
10657
+ body = importedNode;
10658
+ } else {
10659
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
10660
+ body.appendChild(importedNode);
10661
+ }
10662
+ } else {
10663
+ /* Exit directly if we have nothing to do */
10664
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
10665
+ // eslint-disable-next-line unicorn/prefer-includes
10666
+ dirty.indexOf('<') === -1) {
10667
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
10668
+ }
10669
+
10670
+ /* Initialize the document to work on */
10671
+ body = _initDocument(dirty);
10672
+
10673
+ /* Check we have a DOM node from the data */
10674
+ if (!body) {
10675
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
10676
+ }
10677
+ }
10678
+
10679
+ /* Remove first element node (ours) if FORCE_BODY is set */
10680
+ if (body && FORCE_BODY) {
10681
+ _forceRemove(body.firstChild);
10682
+ }
10683
+
10684
+ /* Get node iterator */
10685
+ const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
10686
+
10687
+ /* Now start iterating over the created document */
10688
+ while (currentNode = nodeIterator.nextNode()) {
10689
+ /* Sanitize tags and elements */
10690
+ if (_sanitizeElements(currentNode)) {
10691
+ continue;
10692
+ }
10693
+
10694
+ /* Shadow DOM detected, sanitize it */
10695
+ if (currentNode.content instanceof DocumentFragment) {
10696
+ _sanitizeShadowDOM(currentNode.content);
10697
+ }
10698
+
10699
+ /* Check attributes, sanitize if necessary */
10700
+ _sanitizeAttributes(currentNode);
10701
+ }
10702
+
10703
+ /* If we sanitized `dirty` in-place, return it. */
10704
+ if (IN_PLACE) {
10705
+ return dirty;
10706
+ }
10707
+
10708
+ /* Return sanitized string or DOM */
10709
+ if (RETURN_DOM) {
10710
+ if (RETURN_DOM_FRAGMENT) {
10711
+ returnNode = createDocumentFragment.call(body.ownerDocument);
10712
+ while (body.firstChild) {
10713
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
10714
+ returnNode.appendChild(body.firstChild);
10715
+ }
10716
+ } else {
10717
+ returnNode = body;
10718
+ }
10719
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
10720
+ /*
10721
+ AdoptNode() is not used because internal state is not reset
10722
+ (e.g. the past names map of a HTMLFormElement), this is safe
10723
+ in theory but we would rather not risk another attack vector.
10724
+ The state that is cloned by importNode() is explicitly defined
10725
+ by the specs.
10726
+ */
10727
+ returnNode = importNode.call(originalDocument, returnNode, true);
10728
+ }
10729
+ return returnNode;
10730
+ }
10731
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
10732
+
10733
+ /* Serialize doctype if allowed */
10734
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
10735
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
10736
+ }
10737
+
10738
+ /* Sanitize final string template-safe */
10739
+ if (SAFE_FOR_TEMPLATES) {
10740
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
10741
+ serializedHTML = stringReplace(serializedHTML, expr, ' ');
10742
+ });
10743
+ }
10744
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
10745
+ };
10746
+
10747
+ /**
10748
+ * Public method to set the configuration once
10749
+ * setConfig
10750
+ *
10751
+ * @param {Object} cfg configuration object
10752
+ */
10753
+ DOMPurify.setConfig = function () {
10754
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10755
+ _parseConfig(cfg);
10756
+ SET_CONFIG = true;
10757
+ };
10758
+
10759
+ /**
10760
+ * Public method to remove the configuration
10761
+ * clearConfig
10762
+ *
10763
+ */
10764
+ DOMPurify.clearConfig = function () {
10765
+ CONFIG = null;
10766
+ SET_CONFIG = false;
10767
+ };
10768
+
10769
+ /**
10770
+ * Public method to check if an attribute value is valid.
10771
+ * Uses last set config, if any. Otherwise, uses config defaults.
10772
+ * isValidAttribute
10773
+ *
10774
+ * @param {String} tag Tag name of containing element.
10775
+ * @param {String} attr Attribute name.
10776
+ * @param {String} value Attribute value.
10777
+ * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
10778
+ */
10779
+ DOMPurify.isValidAttribute = function (tag, attr, value) {
10780
+ /* Initialize shared config vars if necessary. */
10781
+ if (!CONFIG) {
10782
+ _parseConfig({});
10783
+ }
10784
+ const lcTag = transformCaseFunc(tag);
10785
+ const lcName = transformCaseFunc(attr);
10786
+ return _isValidAttribute(lcTag, lcName, value);
10787
+ };
10788
+
10789
+ /**
10790
+ * AddHook
10791
+ * Public method to add DOMPurify hooks
10792
+ *
10793
+ * @param {String} entryPoint entry point for the hook to add
10794
+ * @param {Function} hookFunction function to execute
10795
+ */
10796
+ DOMPurify.addHook = function (entryPoint, hookFunction) {
10797
+ if (typeof hookFunction !== 'function') {
10798
+ return;
10799
+ }
10800
+ hooks[entryPoint] = hooks[entryPoint] || [];
10801
+ arrayPush(hooks[entryPoint], hookFunction);
10802
+ };
10803
+
10804
+ /**
10805
+ * RemoveHook
10806
+ * Public method to remove a DOMPurify hook at a given entryPoint
10807
+ * (pops it from the stack of hooks if more are present)
10808
+ *
10809
+ * @param {String} entryPoint entry point for the hook to remove
10810
+ * @return {Function} removed(popped) hook
10811
+ */
10812
+ DOMPurify.removeHook = function (entryPoint) {
10813
+ if (hooks[entryPoint]) {
10814
+ return arrayPop(hooks[entryPoint]);
10815
+ }
10816
+ };
10817
+
10818
+ /**
10819
+ * RemoveHooks
10820
+ * Public method to remove all DOMPurify hooks at a given entryPoint
10821
+ *
10822
+ * @param {String} entryPoint entry point for the hooks to remove
10823
+ */
10824
+ DOMPurify.removeHooks = function (entryPoint) {
10825
+ if (hooks[entryPoint]) {
10826
+ hooks[entryPoint] = [];
10827
+ }
10828
+ };
10829
+
10830
+ /**
10831
+ * RemoveAllHooks
10832
+ * Public method to remove all DOMPurify hooks
10833
+ */
10834
+ DOMPurify.removeAllHooks = function () {
10835
+ hooks = {};
10836
+ };
10837
+ return DOMPurify;
10838
+ }
10839
+ var purify = createDOMPurify();
10840
+
10841
+ return purify;
10842
+
10843
+ }));
10844
+
10845
+ } (purify));
10846
+
10847
+ var purifyExports = purify.exports;
10848
+
8503
10849
  exports.MarkdownIt = MarkdownIt;
10850
+ exports.markdownItAttrs = markdownItAttrs$1;
10851
+ exports.purifyExports = purifyExports;
8504
10852
  exports.sub_plugin = sub_plugin;
8505
10853
  exports.sup_plugin = sup_plugin;