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