@bobfrankston/rmfmail 1.2.276 → 1.2.278

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 (198) hide show
  1. package/.commitmsg +26 -23
  2. package/bin/build-tinymce.js +27 -0
  3. package/client/app.bundle.js +108 -0
  4. package/client/app.bundle.js.map +4 -4
  5. package/client/app.js +65 -0
  6. package/client/app.js.map +1 -1
  7. package/client/app.ts +59 -0
  8. package/client/compose/compose.bundle.js +90 -2
  9. package/client/compose/compose.bundle.js.map +4 -4
  10. package/client/compose/compose.js +26 -1
  11. package/client/compose/compose.js.map +1 -1
  12. package/client/compose/compose.ts +22 -1
  13. package/client/compose/editor.js +12 -1
  14. package/client/compose/editor.js.map +1 -1
  15. package/client/compose/editor.ts +17 -2
  16. package/client/index.html +1 -0
  17. package/client/lib/rmf-tiny.js +3 -0
  18. package/client/lib/tinymce/CHANGELOG.md +47 -0
  19. package/client/lib/tinymce/composer.json +1 -1
  20. package/client/lib/tinymce/icons/default/icons.js +13 -0
  21. package/client/lib/tinymce/icons/default/icons.min.js +1 -1
  22. package/client/lib/tinymce/langs/ar-SA.js +440 -0
  23. package/client/lib/tinymce/langs/ar.js +441 -0
  24. package/client/lib/tinymce/langs/az.js +440 -0
  25. package/client/lib/tinymce/langs/be.js +440 -0
  26. package/client/lib/tinymce/langs/bg-BG.js +440 -0
  27. package/client/lib/tinymce/langs/bn-BD.js +440 -0
  28. package/client/lib/tinymce/langs/bs.js +440 -0
  29. package/client/lib/tinymce/langs/ca.js +440 -0
  30. package/client/lib/tinymce/langs/cs.js +440 -0
  31. package/client/lib/tinymce/langs/cy.js +440 -0
  32. package/client/lib/tinymce/langs/da.js +440 -0
  33. package/client/lib/tinymce/langs/de.js +440 -0
  34. package/client/lib/tinymce/langs/el.js +440 -0
  35. package/client/lib/tinymce/langs/eo.js +440 -0
  36. package/client/lib/tinymce/langs/es-MX.js +440 -0
  37. package/client/lib/tinymce/langs/es.js +440 -0
  38. package/client/lib/tinymce/langs/et.js +440 -0
  39. package/client/lib/tinymce/langs/eu.js +440 -0
  40. package/client/lib/tinymce/langs/fa.js +441 -0
  41. package/client/lib/tinymce/langs/fi.js +440 -0
  42. package/client/lib/tinymce/langs/fr-FR.js +440 -0
  43. package/client/lib/tinymce/langs/gl.js +440 -0
  44. package/client/lib/tinymce/langs/he-IL.js +440 -0
  45. package/client/lib/tinymce/langs/hr.js +440 -0
  46. package/client/lib/tinymce/langs/hu-HU.js +440 -0
  47. package/client/lib/tinymce/langs/hy.js +440 -0
  48. package/client/lib/tinymce/langs/id.js +440 -0
  49. package/client/lib/tinymce/langs/index.json +63 -0
  50. package/client/lib/tinymce/langs/is-IS.js +440 -0
  51. package/client/lib/tinymce/langs/it.js +440 -0
  52. package/client/lib/tinymce/langs/ja.js +440 -0
  53. package/client/lib/tinymce/langs/ka-GE.js +440 -0
  54. package/client/lib/tinymce/langs/kab.js +440 -0
  55. package/client/lib/tinymce/langs/kk.js +440 -0
  56. package/client/lib/tinymce/langs/ko-KR.js +440 -0
  57. package/client/lib/tinymce/langs/lt.js +440 -0
  58. package/client/lib/tinymce/langs/lv.js +440 -0
  59. package/client/lib/tinymce/langs/nb-NO.js +440 -0
  60. package/client/lib/tinymce/langs/ne.js +440 -0
  61. package/client/lib/tinymce/langs/nl-BE.js +440 -0
  62. package/client/lib/tinymce/langs/nl.js +440 -0
  63. package/client/lib/tinymce/langs/oc.js +440 -0
  64. package/client/lib/tinymce/langs/pl.js +440 -0
  65. package/client/lib/tinymce/langs/pt-BR.js +440 -0
  66. package/client/lib/tinymce/langs/pt-PT.js +440 -0
  67. package/client/lib/tinymce/langs/ro.js +440 -0
  68. package/client/lib/tinymce/langs/ru.js +440 -0
  69. package/client/lib/tinymce/langs/sk.js +440 -0
  70. package/client/lib/tinymce/langs/sl-SI.js +440 -0
  71. package/client/lib/tinymce/langs/sr.js +440 -0
  72. package/client/lib/tinymce/langs/sv-SE.js +440 -0
  73. package/client/lib/tinymce/langs/ta.js +440 -0
  74. package/client/lib/tinymce/langs/tg.js +440 -0
  75. package/client/lib/tinymce/langs/th-TH.js +440 -0
  76. package/client/lib/tinymce/langs/tr.js +440 -0
  77. package/client/lib/tinymce/langs/ug.js +440 -0
  78. package/client/lib/tinymce/langs/uk.js +440 -0
  79. package/client/lib/tinymce/langs/vi.js +440 -0
  80. package/client/lib/tinymce/langs/zh-CN.js +440 -0
  81. package/client/lib/tinymce/langs/zh-HK.js +440 -0
  82. package/client/lib/tinymce/langs/zh-MO.js +440 -0
  83. package/client/lib/tinymce/langs/zh-TW.js +440 -0
  84. package/client/lib/tinymce/models/dom/model.js +1 -1
  85. package/client/lib/tinymce/package.json +1 -1
  86. package/client/lib/tinymce/plugins/accordion/plugin.js +1 -1
  87. package/client/lib/tinymce/plugins/advlist/plugin.js +1 -1
  88. package/client/lib/tinymce/plugins/anchor/plugin.js +1 -1
  89. package/client/lib/tinymce/plugins/autolink/plugin.js +1 -1
  90. package/client/lib/tinymce/plugins/autolink/plugin.min.js +1 -1
  91. package/client/lib/tinymce/plugins/autoresize/plugin.js +1 -1
  92. package/client/lib/tinymce/plugins/autosave/plugin.js +1 -1
  93. package/client/lib/tinymce/plugins/autosave/plugin.min.js +1 -1
  94. package/client/lib/tinymce/plugins/charmap/plugin.js +1 -1
  95. package/client/lib/tinymce/plugins/code/plugin.js +1 -1
  96. package/client/lib/tinymce/plugins/codesample/plugin.js +2 -2
  97. package/client/lib/tinymce/plugins/codesample/plugin.min.js +2 -2
  98. package/client/lib/tinymce/plugins/directionality/plugin.js +1 -1
  99. package/client/lib/tinymce/plugins/emoticons/plugin.js +5 -11
  100. package/client/lib/tinymce/plugins/emoticons/plugin.min.js +1 -1
  101. package/client/lib/tinymce/plugins/fullscreen/plugin.js +1 -1
  102. package/client/lib/tinymce/plugins/help/plugin.js +1 -1
  103. package/client/lib/tinymce/plugins/help/plugin.min.js +1 -1
  104. package/client/lib/tinymce/plugins/image/plugin.js +15 -28
  105. package/client/lib/tinymce/plugins/image/plugin.min.js +1 -1
  106. package/client/lib/tinymce/plugins/importcss/plugin.js +1 -1
  107. package/client/lib/tinymce/plugins/insertdatetime/plugin.js +1 -1
  108. package/client/lib/tinymce/plugins/link/plugin.js +3 -2
  109. package/client/lib/tinymce/plugins/link/plugin.min.js +1 -1
  110. package/client/lib/tinymce/plugins/lists/plugin.js +1 -1
  111. package/client/lib/tinymce/plugins/media/plugin.js +1 -1
  112. package/client/lib/tinymce/plugins/nonbreaking/plugin.js +1 -1
  113. package/client/lib/tinymce/plugins/pagebreak/plugin.js +1 -1
  114. package/client/lib/tinymce/plugins/preview/plugin.js +12 -2
  115. package/client/lib/tinymce/plugins/preview/plugin.min.js +1 -1
  116. package/client/lib/tinymce/plugins/quickbars/plugin.js +1 -1
  117. package/client/lib/tinymce/plugins/save/plugin.js +1 -1
  118. package/client/lib/tinymce/plugins/searchreplace/plugin.js +1 -1
  119. package/client/lib/tinymce/plugins/table/plugin.js +5 -3
  120. package/client/lib/tinymce/plugins/table/plugin.min.js +1 -1
  121. package/client/lib/tinymce/plugins/visualblocks/plugin.js +1 -1
  122. package/client/lib/tinymce/plugins/visualchars/plugin.js +1 -1
  123. package/client/lib/tinymce/plugins/wordcount/plugin.js +1 -1
  124. package/client/lib/tinymce/skins/content/dark/content.css +3 -0
  125. package/client/lib/tinymce/skins/content/dark/content.js +1 -1
  126. package/client/lib/tinymce/skins/content/dark/content.min.css +1 -1
  127. package/client/lib/tinymce/skins/ui/oxide/content.css +53 -42
  128. package/client/lib/tinymce/skins/ui/oxide/content.inline.css +53 -42
  129. package/client/lib/tinymce/skins/ui/oxide/content.inline.js +1 -1
  130. package/client/lib/tinymce/skins/ui/oxide/content.inline.min.css +1 -1
  131. package/client/lib/tinymce/skins/ui/oxide/content.inline.min.ts +2 -2
  132. package/client/lib/tinymce/skins/ui/oxide/content.inline.ts +2 -2
  133. package/client/lib/tinymce/skins/ui/oxide/content.js +1 -1
  134. package/client/lib/tinymce/skins/ui/oxide/content.min.css +1 -1
  135. package/client/lib/tinymce/skins/ui/oxide/content.min.ts +2 -2
  136. package/client/lib/tinymce/skins/ui/oxide/content.ts +2 -2
  137. package/client/lib/tinymce/skins/ui/oxide/skin.css +94 -22
  138. package/client/lib/tinymce/skins/ui/oxide/skin.js +1 -1
  139. package/client/lib/tinymce/skins/ui/oxide/skin.min.css +1 -1
  140. package/client/lib/tinymce/skins/ui/oxide/skin.min.ts +8 -3
  141. package/client/lib/tinymce/skins/ui/oxide/skin.ts +8 -3
  142. package/client/lib/tinymce/skins/ui/oxide-dark/content.css +53 -42
  143. package/client/lib/tinymce/skins/ui/oxide-dark/content.inline.css +53 -42
  144. package/client/lib/tinymce/skins/ui/oxide-dark/content.inline.js +1 -1
  145. package/client/lib/tinymce/skins/ui/oxide-dark/content.inline.min.css +1 -1
  146. package/client/lib/tinymce/skins/ui/oxide-dark/content.inline.min.ts +2 -2
  147. package/client/lib/tinymce/skins/ui/oxide-dark/content.inline.ts +2 -2
  148. package/client/lib/tinymce/skins/ui/oxide-dark/content.js +1 -1
  149. package/client/lib/tinymce/skins/ui/oxide-dark/content.min.css +1 -1
  150. package/client/lib/tinymce/skins/ui/oxide-dark/content.min.ts +2 -2
  151. package/client/lib/tinymce/skins/ui/oxide-dark/content.ts +2 -2
  152. package/client/lib/tinymce/skins/ui/oxide-dark/skin.css +94 -22
  153. package/client/lib/tinymce/skins/ui/oxide-dark/skin.js +1 -1
  154. package/client/lib/tinymce/skins/ui/oxide-dark/skin.min.css +1 -1
  155. package/client/lib/tinymce/skins/ui/oxide-dark/skin.min.ts +8 -3
  156. package/client/lib/tinymce/skins/ui/oxide-dark/skin.ts +8 -3
  157. package/client/lib/tinymce/skins/ui/tinymce-5/content.css +53 -42
  158. package/client/lib/tinymce/skins/ui/tinymce-5/content.inline.css +53 -42
  159. package/client/lib/tinymce/skins/ui/tinymce-5/content.inline.js +1 -1
  160. package/client/lib/tinymce/skins/ui/tinymce-5/content.inline.min.css +1 -1
  161. package/client/lib/tinymce/skins/ui/tinymce-5/content.inline.min.ts +2 -2
  162. package/client/lib/tinymce/skins/ui/tinymce-5/content.inline.ts +2 -2
  163. package/client/lib/tinymce/skins/ui/tinymce-5/content.js +1 -1
  164. package/client/lib/tinymce/skins/ui/tinymce-5/content.min.css +1 -1
  165. package/client/lib/tinymce/skins/ui/tinymce-5/content.min.ts +2 -2
  166. package/client/lib/tinymce/skins/ui/tinymce-5/content.ts +2 -2
  167. package/client/lib/tinymce/skins/ui/tinymce-5/skin.css +94 -22
  168. package/client/lib/tinymce/skins/ui/tinymce-5/skin.js +1 -1
  169. package/client/lib/tinymce/skins/ui/tinymce-5/skin.min.css +1 -1
  170. package/client/lib/tinymce/skins/ui/tinymce-5/skin.min.ts +8 -3
  171. package/client/lib/tinymce/skins/ui/tinymce-5/skin.ts +8 -3
  172. package/client/lib/tinymce/skins/ui/tinymce-5-dark/content.css +53 -42
  173. package/client/lib/tinymce/skins/ui/tinymce-5-dark/content.inline.css +53 -42
  174. package/client/lib/tinymce/skins/ui/tinymce-5-dark/content.inline.js +1 -1
  175. package/client/lib/tinymce/skins/ui/tinymce-5-dark/content.inline.min.css +1 -1
  176. package/client/lib/tinymce/skins/ui/tinymce-5-dark/content.inline.min.ts +2 -2
  177. package/client/lib/tinymce/skins/ui/tinymce-5-dark/content.inline.ts +2 -2
  178. package/client/lib/tinymce/skins/ui/tinymce-5-dark/content.js +1 -1
  179. package/client/lib/tinymce/skins/ui/tinymce-5-dark/content.min.css +1 -1
  180. package/client/lib/tinymce/skins/ui/tinymce-5-dark/content.min.ts +2 -2
  181. package/client/lib/tinymce/skins/ui/tinymce-5-dark/content.ts +2 -2
  182. package/client/lib/tinymce/skins/ui/tinymce-5-dark/skin.css +94 -22
  183. package/client/lib/tinymce/skins/ui/tinymce-5-dark/skin.js +1 -1
  184. package/client/lib/tinymce/skins/ui/tinymce-5-dark/skin.min.css +1 -1
  185. package/client/lib/tinymce/skins/ui/tinymce-5-dark/skin.min.ts +8 -3
  186. package/client/lib/tinymce/skins/ui/tinymce-5-dark/skin.ts +8 -3
  187. package/client/lib/tinymce/themes/silver/theme.js +1602 -579
  188. package/client/lib/tinymce/themes/silver/theme.min.js +3 -3
  189. package/client/lib/tinymce/tinymce.js +1410 -294
  190. package/client/lib/tinymce/tinymce.min.js +5 -5
  191. package/client/lib/tinymce-langs.js +96 -0
  192. package/client/lib/tinymce-langs.js.map +1 -0
  193. package/client/lib/tinymce-langs.ts +99 -0
  194. package/docs/editor.md +29 -3
  195. package/docs/preferences.md +2 -1
  196. package/npmchanges.md +63 -0
  197. package/package.json +11 -8
  198. /package/packages/mailx-imap/{node_modules.npmglobalize-stash-59216 → node_modules.npmglobalize-stash-65048}/.package-lock.json +0 -0
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TinyMCE version 8.6.0 (2026-06-03)
2
+ * TinyMCE version 8.8.2 (2026-07-27)
3
3
  */
4
4
 
5
5
  (function () {
@@ -573,14 +573,16 @@
573
573
  }
574
574
  return Optional.none();
575
575
  };
576
- const findLastIndex = (arr, pred) => {
576
+ const findLastByPredicate = (arr, pred) => {
577
577
  for (let i = arr.length - 1; i >= 0; i--) {
578
578
  if (pred(arr[i], i)) {
579
- return Optional.some(i);
579
+ return Optional.some({ v: arr[i], i });
580
580
  }
581
581
  }
582
582
  return Optional.none();
583
583
  };
584
+ const findLast = (arr, pred) => findLastByPredicate(arr, pred).map((r) => r.v);
585
+ const findLastIndex = (arr, pred) => findLastByPredicate(arr, pred).map((r) => r.i);
584
586
  const flatten$1 = (xs) => {
585
587
  // Note, this is possible because push supports multiple arguments:
586
588
  // http://jsperf.com/concat-push/6
@@ -2198,14 +2200,14 @@
2198
2200
  const siblings = (element) => {
2199
2201
  // TODO: Refactor out children so we can just not add self instead of filtering afterwards
2200
2202
  const filterSelf = (elements) => filter$5(elements, (x) => !eq(element, x));
2201
- return parent(element).map(children$1).map(filterSelf).getOr([]);
2203
+ return parent(element).map(children$2).map(filterSelf).getOr([]);
2202
2204
  };
2203
2205
  const prevSibling = (element) => Optional.from(element.dom.previousSibling).map(SugarElement.fromDom);
2204
2206
  const nextSibling = (element) => Optional.from(element.dom.nextSibling).map(SugarElement.fromDom);
2205
2207
  // This one needs to be reversed, so they're still in DOM order
2206
2208
  const prevSiblings = (element) => reverse(toArray(element, prevSibling));
2207
2209
  const nextSiblings = (element) => toArray(element, nextSibling);
2208
- const children$1 = (element) => map$3(element.dom.childNodes, SugarElement.fromDom);
2210
+ const children$2 = (element) => map$3(element.dom.childNodes, SugarElement.fromDom);
2209
2211
  const child$1 = (element, index) => {
2210
2212
  const cs = element.dom.childNodes;
2211
2213
  return Optional.from(cs[index]).map(SugarElement.fromDom);
@@ -2442,7 +2444,7 @@
2442
2444
  // than removing every child node manually.
2443
2445
  // The following is (probably) safe for performance as 99.9% of the time the trick works and
2444
2446
  // Traverse.children will return an empty array.
2445
- each$e(children$1(element), (rogue) => {
2447
+ each$e(children$2(element), (rogue) => {
2446
2448
  remove$8(rogue);
2447
2449
  });
2448
2450
  };
@@ -2453,7 +2455,7 @@
2453
2455
  }
2454
2456
  };
2455
2457
  const unwrap = (wrapper) => {
2456
- const children = children$1(wrapper);
2458
+ const children = children$2(wrapper);
2457
2459
  if (children.length > 0) {
2458
2460
  after$3(wrapper, children);
2459
2461
  }
@@ -2476,7 +2478,7 @@
2476
2478
  const mutate = (original, tag) => {
2477
2479
  const nu = shallowAs(original, tag);
2478
2480
  after$4(original, nu);
2479
- const children = children$1(original);
2481
+ const children = children$2(original);
2480
2482
  append(nu, children);
2481
2483
  remove$8(original);
2482
2484
  return nu;
@@ -2486,7 +2488,7 @@
2486
2488
  const doc = scope || document;
2487
2489
  const div = doc.createElement('div');
2488
2490
  div.innerHTML = html;
2489
- return children$1(SugarElement.fromDom(div));
2491
+ return children$2(SugarElement.fromDom(div));
2490
2492
  };
2491
2493
  const fromDom$1 = (nodes) => map$3(nodes, SugarElement.fromDom);
2492
2494
 
@@ -2526,6 +2528,14 @@
2526
2528
  const doc = dom.ownerDocument;
2527
2529
  return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost));
2528
2530
  };
2531
+ const body = () => getBody(SugarElement.fromDom(document));
2532
+ const getBody = (doc) => {
2533
+ const b = doc.dom.body;
2534
+ if (b === null || b === undefined) {
2535
+ throw new Error('Body is not available yet');
2536
+ }
2537
+ return SugarElement.fromDom(b);
2538
+ };
2529
2539
 
2530
2540
  const internalSet = (dom, property, value) => {
2531
2541
  // This is going to hurt. Apologies.
@@ -2999,11 +3009,11 @@
2999
3009
  };
3000
3010
 
3001
3011
  const ancestors$1 = (scope, predicate, isRoot) => filter$5(parents$1(scope, isRoot), predicate);
3002
- const children = (scope, predicate) => filter$5(children$1(scope), predicate);
3012
+ const children$1 = (scope, predicate) => filter$5(children$2(scope), predicate);
3003
3013
  const descendants$1 = (scope, predicate) => {
3004
3014
  let result = [];
3005
3015
  // Recurse.toArray() might help here
3006
- each$e(children$1(scope), (x) => {
3016
+ each$e(children$2(scope), (x) => {
3007
3017
  if (predicate(x)) {
3008
3018
  result = result.concat([x]);
3009
3019
  }
@@ -3021,6 +3031,10 @@
3021
3031
  // It may surprise you to learn this is exactly what JQuery does
3022
3032
  // TODO: Avoid all this wrapping and unwrapping
3023
3033
  ancestors$1(scope, (e) => is$2(e, selector), isRoot);
3034
+ const children = (scope, selector) =>
3035
+ // It may surprise you to learn this is exactly what JQuery does
3036
+ // TODO: Avoid all the wrapping and unwrapping
3037
+ children$1(scope, (e) => is$2(e, selector));
3024
3038
  const descendants = (scope, selector) => all(selector, scope);
3025
3039
 
3026
3040
  const ancestor$3 = (scope, predicate, isRoot) => ancestor$5(scope, predicate, isRoot).isSome();
@@ -3205,6 +3219,20 @@
3205
3219
  };
3206
3220
  const getAtPoint = (win, x, y) => fromPoint$1(win, x, y);
3207
3221
 
3222
+ const getImageSize = (url) => new Promise((resolve, reject) => {
3223
+ const img = document.createElement('img');
3224
+ img.addEventListener('load', () => {
3225
+ resolve({
3226
+ width: img.naturalWidth,
3227
+ height: img.naturalHeight
3228
+ });
3229
+ });
3230
+ img.addEventListener('error', () => {
3231
+ reject(`Failed to get image dimensions for: ${url}`);
3232
+ });
3233
+ img.src = url;
3234
+ });
3235
+
3208
3236
  const get$2 = (_win) => {
3209
3237
  const win = _win === undefined ? window : _win;
3210
3238
  if (detect$1().browser.isFirefox()) {
@@ -3660,7 +3688,7 @@
3660
3688
  const isRoot = (el) => eq(el, rootNode);
3661
3689
  each$e(fromDom$1(transparentBlocks), (transparentBlock) => {
3662
3690
  ancestor$5(transparentBlock, isBlock, isRoot).each((parentBlock) => {
3663
- const invalidChildren = children(transparentBlock, (el) => isBlock(el) && !schema.isValidChild(name(parentBlock), name(el)));
3691
+ const invalidChildren = children$1(transparentBlock, (el) => isBlock(el) && !schema.isValidChild(name(parentBlock), name(el)));
3664
3692
  if (invalidChildren.length > 0) {
3665
3693
  const stateScope = parentElement(parentBlock);
3666
3694
  each$e(invalidChildren, (child) => {
@@ -3711,7 +3739,7 @@
3711
3739
  // this tries to compensate for that by detecting if that offsets are incorrect and then remove the height
3712
3740
  const getTableCaptionDeltaY = (elm) => {
3713
3741
  if (browser$2.isFirefox() && name(elm) === 'table') {
3714
- return firstElement(children$1(elm)).filter((elm) => {
3742
+ return firstElement(children$2(elm)).filter((elm) => {
3715
3743
  return name(elm) === 'caption';
3716
3744
  }).bind((caption) => {
3717
3745
  return firstElement(nextSiblings(caption)).map((body) => {
@@ -5594,12 +5622,16 @@
5594
5622
  let matches;
5595
5623
  while ((matches = styleRegExp.exec(css))) {
5596
5624
  styleRegExp.lastIndex = matches.index + matches[0].length;
5597
- let name = matches[1].replace(trimRightRegExp, '').toLowerCase();
5625
+ let name = matches[1].replace(trimRightRegExp, '');
5598
5626
  let value = matches[2].replace(trimRightRegExp, '');
5599
5627
  if (name && value) {
5600
5628
  // Decode escaped sequences like \65 -> e
5601
5629
  name = decodeHexSequences(name);
5602
5630
  value = decodeHexSequences(value);
5631
+ // Custom properties (--*) keep user case; standard names normalize to lowercase
5632
+ if (!name.startsWith('--')) {
5633
+ name = name.toLowerCase();
5634
+ }
5603
5635
  // Skip properties with double quotes and sequences like \" \' in their names
5604
5636
  // See 'mXSS Attacks: Attacking well-secured Web-Applications by using innerHTML Mutations'
5605
5637
  // https://cure53.de/fp170.pdf
@@ -5614,9 +5646,6 @@
5614
5646
  if (name === 'font-weight' && value === '700') {
5615
5647
  value = 'bold';
5616
5648
  }
5617
- else if (name === 'color' || name === 'background-color') { // Lowercase colors like RED
5618
- value = value.toLowerCase();
5619
- }
5620
5649
  // Convert RGB colors to HEX
5621
5650
  if (getColorFormat(value) === 'rgb') {
5622
5651
  fromString(value).each((rgba) => {
@@ -6591,7 +6620,7 @@
6591
6620
  const $node = SugarElement.fromDom(n);
6592
6621
  if (keepChildren) {
6593
6622
  // Unwrap but don't keep any empty text nodes
6594
- each$e(children$1($node), (child) => {
6623
+ each$e(children$2($node), (child) => {
6595
6624
  if (isText$c(child) && child.dom.length === 0) {
6596
6625
  remove$8(child);
6597
6626
  }
@@ -12124,6 +12153,13 @@
12124
12153
  const selector = isEmpty$5(formatNoneditableSelector) ? baseDataSelector : `${baseDataSelector},${formatNoneditableSelector}`;
12125
12154
  return is$2(SugarElement.fromDom(node), selector);
12126
12155
  };
12156
+ const hasEditableDescendants = (dom, node) => dom.select('[contenteditable="true"]', node).length > 0;
12157
+ const getEditableDescendants = (dom, parent) => foldl(from(parent.childNodes), (editableDescendants, child) => [
12158
+ ...editableDescendants,
12159
+ ...(isElement$7(child) && dom.getContentEditable(child) === 'true'
12160
+ ? [child]
12161
+ : getEditableDescendants(dom, child))
12162
+ ], []);
12127
12163
  // A noneditable element is wrappable if it:
12128
12164
  // - is valid target (has data-mce-cef-wrappable attribute or matches selector from option)
12129
12165
  // - has no editable descendants - removing formats in the editable region can result in the wrapped noneditable being split which is undesirable
@@ -12132,7 +12168,7 @@
12132
12168
  return (isElementNode$1(node) &&
12133
12169
  dom.getContentEditable(node) === 'false' &&
12134
12170
  isWrapNoneditableTarget(editor, node) &&
12135
- dom.select('[contenteditable="true"]', node).length === 0);
12171
+ !hasEditableDescendants(dom, node));
12136
12172
  };
12137
12173
  /**
12138
12174
  * Replaces variables in the value. The variable format is %var.
@@ -12736,7 +12772,7 @@
12736
12772
  switch (ctx) {
12737
12773
  case "invalid-child" /* ChildContext.InvalidChild */: {
12738
12774
  finishWrapper();
12739
- const children = children$1(elem);
12775
+ const children = children$2(elem);
12740
12776
  processElements(children);
12741
12777
  finishWrapper();
12742
12778
  break;
@@ -12890,6 +12926,113 @@
12890
12926
  };
12891
12927
  };
12892
12928
 
12929
+ const announcerContainerId = generate('tiny-aria-announcer');
12930
+ const POLITE_MESSAGE_TTL_MS = 600000; // 10 minutes
12931
+ const CREATE_DELAY_MS = 100; // Delay before creating announcer regions to avoid interfering with screen readers initial announcements.
12932
+ const politeTimestampAttr = 'data-mce-announced-at';
12933
+ const OFFSCREEN_STYLES = {
12934
+ position: 'absolute',
12935
+ left: '-9999px',
12936
+ width: '1px',
12937
+ height: '1px',
12938
+ overflow: 'hidden'
12939
+ };
12940
+ const createRegion = (live) => {
12941
+ const region = SugarElement.fromTag('div');
12942
+ setAll$1(region, {
12943
+ 'aria-live': live,
12944
+ 'aria-atomic': 'false',
12945
+ 'aria-relevant': 'additions'
12946
+ });
12947
+ return region;
12948
+ };
12949
+ const isConnected = (element) => element.dom.isConnected;
12950
+ const createNewState = () => {
12951
+ const container = SugarElement.fromTag('div');
12952
+ const politeRegion = createRegion('polite');
12953
+ const assertiveRegion = createRegion('assertive');
12954
+ set$5(container, 'id', announcerContainerId);
12955
+ setAll(container, OFFSCREEN_STYLES);
12956
+ append$1(container, politeRegion);
12957
+ append$1(container, assertiveRegion);
12958
+ append$1(body(), container);
12959
+ return { container, politeRegion, assertiveRegion };
12960
+ };
12961
+ const cleanupExpiredMessages = (polite, now) => {
12962
+ each$e(children(polite, `div[${politeTimestampAttr}]`), (messageDiv) => {
12963
+ getOpt(messageDiv, politeTimestampAttr)
12964
+ .bind((value) => toInt(value))
12965
+ .filter((announcedAt) => now - announcedAt > POLITE_MESSAGE_TTL_MS)
12966
+ .each(() => remove$8(messageDiv));
12967
+ });
12968
+ };
12969
+ const createAnnouncer = () => {
12970
+ const state = value$1();
12971
+ const mountRegions = async () => {
12972
+ const createNewPendingState = async () => {
12973
+ const promise = new Promise((resolve) => {
12974
+ const newState = createNewState();
12975
+ setTimeout(() => resolve(newState), CREATE_DELAY_MS);
12976
+ });
12977
+ state.set(promise);
12978
+ return promise;
12979
+ };
12980
+ return state.get().fold(createNewPendingState, async (existingPromise) => {
12981
+ const { container } = await existingPromise;
12982
+ if (isConnected(container)) {
12983
+ return existingPromise;
12984
+ }
12985
+ else {
12986
+ // A concurrent caller may have already replaced the stale state while we awaited.
12987
+ // The block after the await runs atomically, so reuse that state if present and
12988
+ // only create a fresh one when the state is still the stale promise we observed.
12989
+ return state.get().filter((current) => current !== existingPromise).getOrThunk(createNewPendingState);
12990
+ }
12991
+ });
12992
+ };
12993
+ const addMessage = (region, message) => {
12994
+ const now = Date.now();
12995
+ cleanupExpiredMessages(region, now);
12996
+ const messageDiv = SugarElement.fromTag('div');
12997
+ set$5(messageDiv, politeTimestampAttr, String(now));
12998
+ append$1(messageDiv, SugarElement.fromText(message));
12999
+ append$1(region, messageDiv);
13000
+ };
13001
+ const polite = async (message) => {
13002
+ const { politeRegion } = await mountRegions();
13003
+ addMessage(politeRegion, message);
13004
+ };
13005
+ const assertive = async (message) => {
13006
+ const { assertiveRegion } = await mountRegions();
13007
+ addMessage(assertiveRegion, message);
13008
+ };
13009
+ return { polite, assertive };
13010
+ };
13011
+
13012
+ const announcer = createAnnouncer();
13013
+ /**
13014
+ * Announces a message to screen readers via an aria-live region, without shifting focus.
13015
+ *
13016
+ * @method announce
13017
+ * @param {String} message The message to announce to screen readers.
13018
+ * @param {Object} options Optional settings.
13019
+ * @param {Boolean} options.assertive If true, uses aria-live="assertive" instead of polite.
13020
+ * @example
13021
+ * tinymce.dom.AriaAnnouncer.announce('Bold on');
13022
+ * tinymce.dom.AriaAnnouncer.announce('Error occurred', { assertive: true });
13023
+ */
13024
+ const announce = (message, options) => {
13025
+ if (options?.assertive === true) {
13026
+ announcer.assertive(message).catch(noop);
13027
+ }
13028
+ else {
13029
+ announcer.polite(message).catch(noop);
13030
+ }
13031
+ };
13032
+ const AriaAnnouncer = {
13033
+ announce
13034
+ };
13035
+
12893
13036
  /**
12894
13037
  * Constructs a new BookmarkManager instance for a specific selection instance.
12895
13038
  *
@@ -12954,7 +13097,7 @@
12954
13097
  };
12955
13098
 
12956
13099
  const clamp$1 = (offset, element) => {
12957
- const max = isText$c(element) ? get$5(element).length : children$1(element).length + 1;
13100
+ const max = isText$c(element) ? get$5(element).length : children$2(element).length + 1;
12958
13101
  if (offset > max) {
12959
13102
  return max;
12960
13103
  }
@@ -14226,7 +14369,7 @@
14226
14369
  editor.dispatch('AfterScrollIntoView', data);
14227
14370
  };
14228
14371
  const descend = (element, offset) => {
14229
- const children = children$1(element);
14372
+ const children = children$2(element);
14230
14373
  if (children.length === 0 || excludeFromDescend(element)) {
14231
14374
  return { element, offset };
14232
14375
  }
@@ -14246,7 +14389,7 @@
14246
14389
  return { element: last, offset: get$5(last).length };
14247
14390
  }
14248
14391
  else {
14249
- return { element: last, offset: children$1(last).length };
14392
+ return { element: last, offset: children$2(last).length };
14250
14393
  }
14251
14394
  }
14252
14395
  }
@@ -15750,7 +15893,7 @@
15750
15893
  const br = SugarElement.fromHtml('<br data-mce-bogus="1">');
15751
15894
  // Remove all bogus elements except caret
15752
15895
  if (preserveEmptyCaret) {
15753
- each$e(children$1(elm), (node) => {
15896
+ each$e(children$2(elm), (node) => {
15754
15897
  if (!isEmptyCaretFormatElement(node)) {
15755
15898
  remove$8(node);
15756
15899
  }
@@ -15922,7 +16065,7 @@
15922
16065
  // Clean up any additional leftover nodes. If the last block wasn't a direct child, then we also need to clean up siblings
15923
16066
  if (!eq(root, lastBlock)) {
15924
16067
  const additionalCleanupNodes = is$4(parent(lastBlock), root) ? [] : siblings(lastBlock);
15925
- each$e(additionalCleanupNodes.concat(children$1(root)), (node) => {
16068
+ each$e(additionalCleanupNodes.concat(children$2(root)), (node) => {
15926
16069
  if (!eq(node, lastBlock) && !contains(node, lastBlock) && isEmpty$4(editor.schema, node)) {
15927
16070
  remove$8(node);
15928
16071
  }
@@ -16633,14 +16776,23 @@
16633
16776
  }
16634
16777
  return undefined;
16635
16778
  };
16779
+ const containsFormatDeep = (editor, root, name, vars, similar) => isNonNullable(matchNode$1(editor, root, name, vars, similar)) ||
16780
+ exists(from(root.childNodes), (child) => containsFormatDeep(editor, child, name, vars, similar));
16781
+ const matchEditableDescendants = (editor, node, name, vars, similar) => {
16782
+ const dom = editor.dom;
16783
+ if (!isElement$7(node) || dom.getContentEditable(node) !== 'false' || isWrappableNoneditable(editor, node)) {
16784
+ return false;
16785
+ }
16786
+ return exists(getEditableDescendants(dom, node), (descendant) => containsFormatDeep(editor, descendant, name, vars, similar));
16787
+ };
16636
16788
  const match$2 = (editor, name, vars, node, similar) => {
16637
16789
  // Check specified node
16638
16790
  if (node) {
16639
- return matchParents(editor, node, name, vars, similar);
16791
+ return matchParents(editor, node, name, vars, similar) || matchEditableDescendants(editor, node, name, vars, similar);
16640
16792
  }
16641
16793
  // Check selected node
16642
16794
  node = editor.selection.getNode();
16643
- if (matchParents(editor, node, name, vars, similar)) {
16795
+ if (matchParents(editor, node, name, vars, similar) || matchEditableDescendants(editor, node, name, vars, similar)) {
16644
16796
  return true;
16645
16797
  }
16646
16798
  // Check start node if it's different
@@ -17045,6 +17197,18 @@
17045
17197
  return block;
17046
17198
  }
17047
17199
  });
17200
+ // Resolve list items from the
17201
+ // selected cells directly instead, matching how SelectionUtils.runOnRanges resolves fake selections.
17202
+ const getCellSelectionListItems = (editor) => {
17203
+ const fakeSelectionNodes = getCellsFromEditor(editor);
17204
+ if (fakeSelectionNodes.length > 0) {
17205
+ const listItems = bind$3(fakeSelectionNodes, (cell) => descendants(cell, 'li'));
17206
+ return Optional.some(map$3(listItems, (item) => item.dom));
17207
+ }
17208
+ else {
17209
+ return Optional.none();
17210
+ }
17211
+ };
17048
17212
  const getFullySelectedBlocks = (selection) => {
17049
17213
  if (selection.isCollapsed()) {
17050
17214
  return [];
@@ -17061,8 +17225,15 @@
17061
17225
  return first.concat(middle).concat(last);
17062
17226
  }
17063
17227
  };
17064
- const getFullySelectedListItems = (selection) => filter$5(getFullySelectedBlocks(selection), isEditableListItem(selection.dom));
17065
- const getPartiallySelectedListItems = (selection) => filter$5(getAndOnlyNormalizeFirstBlockIf(selection, (el) => !isListItem$3(el)), isEditableListItem(selection.dom));
17228
+ const getFullySelectedListItems = (editor) => {
17229
+ const items = getCellSelectionListItems(editor).getOrThunk(() => getFullySelectedBlocks(editor.selection));
17230
+ return filter$5(items, isEditableListItem(editor.selection.dom));
17231
+ };
17232
+ const getPartiallySelectedListItems = (editor) => {
17233
+ const items = getCellSelectionListItems(editor)
17234
+ .getOrThunk(() => getAndOnlyNormalizeFirstBlockIf(editor.selection, (el) => !isListItem$3(el)));
17235
+ return filter$5(items, isEditableListItem(editor.selection.dom));
17236
+ };
17066
17237
 
17067
17238
  const each$8 = Tools.each;
17068
17239
  const isElementNode = (node) => isElement$7(node) && !isBookmarkNode$1(node) && !isCaretNode(node) && !isBogus$1(node);
@@ -17304,14 +17475,14 @@
17304
17475
  };
17305
17476
  const removeListStyleFormats = (editor, name, vars) => {
17306
17477
  if (name === 'removeformat') {
17307
- each$e(getPartiallySelectedListItems(editor.selection), (li) => {
17478
+ each$e(getPartiallySelectedListItems(editor), (li) => {
17308
17479
  each$e(listItemStyles, (name) => editor.dom.setStyle(li, name, ''));
17309
17480
  removeEmptyStyleAttributeIfNeeded(editor.dom, li);
17310
17481
  });
17311
17482
  }
17312
17483
  else {
17313
17484
  getExpandedListItemFormat(editor.formatter, name).each((liFmt) => {
17314
- each$e(getPartiallySelectedListItems(editor.selection), (li) => removeStyles$1(editor.dom, li, liFmt, vars, null));
17485
+ each$e(getPartiallySelectedListItems(editor), (li) => removeStyles$1(editor.dom, li, liFmt, vars, null));
17315
17486
  });
17316
17487
  }
17317
17488
  };
@@ -17695,14 +17866,14 @@
17695
17866
  });
17696
17867
  };
17697
17868
  const wrapChildrenInInnerWrapper = (target, wrapper, hasFormat, removeFormatFromElement) => {
17698
- each$e(children$1(target), (child) => {
17869
+ each$e(children$2(target), (child) => {
17699
17870
  if (isElement$8(child) && hasFormat(child)) {
17700
17871
  if (removeFormatFromElement(child).isNone()) {
17701
17872
  unwrap(child);
17702
17873
  }
17703
17874
  }
17704
17875
  });
17705
- each$e(children$1(target), (child) => append$1(wrapper, child));
17876
+ each$e(children$2(target), (child) => append$1(wrapper, child));
17706
17877
  prepend(target, wrapper);
17707
17878
  };
17708
17879
  const wrapInOuterWrappers = (target, wrappers) => {
@@ -18492,7 +18663,7 @@
18492
18663
  }
18493
18664
  };
18494
18665
 
18495
- /*! @license DOMPurify 3.4.5 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.5/LICENSE */
18666
+ /*! @license DOMPurify 3.4.12 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.12/LICENSE */
18496
18667
 
18497
18668
  function _arrayLikeToArray(r, a) {
18498
18669
  (null == a || a > r.length) && (a = r.length);
@@ -18805,7 +18976,7 @@
18805
18976
  const text = freeze(['#text']);
18806
18977
 
18807
18978
  const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'command', 'commandfor', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', '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', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns']);
18808
- const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', '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', 'exponent', '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', 'intercept', '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', 'mask-type', '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', 'slope', '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', 'tablevalues', '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']);
18979
+ const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', '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', 'dominant-baseline', 'dur', 'edgemode', 'elevation', 'end', 'exponent', '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', 'intercept', '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', 'mask-type', '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', 'slope', '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', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-orientation', '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']);
18809
18980
  const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnalign', 'columnlines', 'columnspacing', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lquote', 'lspace', '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']);
18810
18981
  const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
18811
18982
 
@@ -18821,16 +18992,31 @@
18821
18992
  );
18822
18993
  const DOCTYPE_NAME = seal(/^html$/i);
18823
18994
  const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
18995
+ // Markup-significant character probes used by _sanitizeElements.
18996
+ // Shared module-level instances are safe despite the sticky /g flags:
18997
+ // unapply() resets lastIndex for RegExp receivers before every call.
18998
+ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
18999
+ const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
19000
+ const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
19001
+ const SELF_CLOSING_TAG = seal(/\/>/i);
18824
19002
 
18825
- /* eslint-disable @typescript-eslint/indent */
18826
19003
  // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
18827
19004
  const NODE_TYPE = {
18828
19005
  element: 1,
19006
+ attribute: 2,
18829
19007
  text: 3,
19008
+ cdataSection: 4,
19009
+ entityReference: 5,
19010
+ // Deprecated
19011
+ entityNode: 6,
18830
19012
  // Deprecated
18831
- progressingInstruction: 7,
19013
+ processingInstruction: 7,
18832
19014
  comment: 8,
18833
- document: 9};
19015
+ document: 9,
19016
+ documentType: 10,
19017
+ documentFragment: 11,
19018
+ notation: 12 // Deprecated
19019
+ };
18834
19020
  const getGlobal = function getGlobal() {
18835
19021
  return typeof window === 'undefined' ? null : window;
18836
19022
  };
@@ -18885,10 +19071,25 @@
18885
19071
  uponSanitizeShadowNode: []
18886
19072
  };
18887
19073
  };
19074
+ /**
19075
+ * Resolve a set-valued configuration option: a fresh set built from
19076
+ * cfg[key] when it is an own array property (seeded with a clone of
19077
+ * options.base when given, case-normalized via options.transform),
19078
+ * the fallback set otherwise.
19079
+ *
19080
+ * @param cfg the cloned, prototype-free configuration object
19081
+ * @param key the configuration property to read
19082
+ * @param fallback the set to use when the option is absent or not an array
19083
+ * @param options transform and optional base set to merge into
19084
+ * @returns the resolved set
19085
+ */
19086
+ const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
19087
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
19088
+ };
18888
19089
  function createDOMPurify() {
18889
19090
  let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
18890
19091
  const DOMPurify = root => createDOMPurify(root);
18891
- DOMPurify.version = '3.4.5';
19092
+ DOMPurify.version = '3.4.12';
18892
19093
  DOMPurify.removed = [];
18893
19094
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
18894
19095
  // Not running in a browser, provide a factory function
@@ -18899,15 +19100,15 @@
18899
19100
  let document = window.document;
18900
19101
  const originalDocument = document;
18901
19102
  const currentScript = originalDocument.currentScript;
18902
- const DocumentFragment = window.DocumentFragment,
18903
- HTMLTemplateElement = window.HTMLTemplateElement,
19103
+ window.DocumentFragment;
19104
+ const HTMLTemplateElement = window.HTMLTemplateElement,
18904
19105
  Node = window.Node,
18905
19106
  Element = window.Element,
18906
19107
  NodeFilter = window.NodeFilter,
18907
- _window$NamedNodeMap = window.NamedNodeMap,
18908
- NamedNodeMap = _window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap,
18909
- HTMLFormElement = window.HTMLFormElement,
18910
- DOMParser = window.DOMParser,
19108
+ _window$NamedNodeMap = window.NamedNodeMap;
19109
+ _window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap;
19110
+ window.HTMLFormElement;
19111
+ const DOMParser = window.DOMParser,
18911
19112
  trustedTypes = window.trustedTypes;
18912
19113
  const ElementPrototype = Element.prototype;
18913
19114
  const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
@@ -18915,7 +19116,10 @@
18915
19116
  const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
18916
19117
  const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
18917
19118
  const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
19119
+ const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
19120
+ const getAttributes = lookupGetter(ElementPrototype, 'attributes');
18918
19121
  const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
19122
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
18919
19123
  // As per issue #47, the web-components registry is inherited by a
18920
19124
  // new document created via createHTMLDocument. As per the spec
18921
19125
  // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
@@ -18930,6 +19134,54 @@
18930
19134
  }
18931
19135
  let trustedTypesPolicy;
18932
19136
  let emptyHTML = '';
19137
+ // The instance's own internal Trusted Types policy. Unlike a caller-supplied
19138
+ // `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
19139
+ // on duplicate policy names — and is the only policy allowed to persist
19140
+ // across configurations and survive `clearConfig()`.
19141
+ let defaultTrustedTypesPolicy;
19142
+ let defaultTrustedTypesPolicyResolved = false;
19143
+ // Tracks whether we are already inside a call to the configured Trusted Types
19144
+ // policy (`createHTML` or `createScriptURL`). If a supplied policy callback
19145
+ // itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
19146
+ // re-enter the policy and recurse until the stack overflows. We detect that
19147
+ // re-entry and throw a clear, actionable error instead. The guard is shared
19148
+ // across both callbacks, because either one re-entering `sanitize` triggers
19149
+ // the same unbounded recursion.
19150
+ let IN_TRUSTED_TYPES_POLICY = 0;
19151
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
19152
+ if (IN_TRUSTED_TYPES_POLICY > 0) {
19153
+ throw typeErrorCreate('A configured TRUSTED_TYPES_POLICY callback (createHTML or ' + 'createScriptURL) must not call DOMPurify.sanitize, as that causes ' + 'infinite recursion. Do not pass a policy whose callbacks wrap ' + 'DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted ' + 'Types" section of the README.');
19154
+ }
19155
+ };
19156
+ const _createTrustedHTML = function _createTrustedHTML(html) {
19157
+ _assertNotInTrustedTypesPolicy();
19158
+ IN_TRUSTED_TYPES_POLICY++;
19159
+ try {
19160
+ return trustedTypesPolicy.createHTML(html);
19161
+ } finally {
19162
+ IN_TRUSTED_TYPES_POLICY--;
19163
+ }
19164
+ };
19165
+ const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
19166
+ _assertNotInTrustedTypesPolicy();
19167
+ IN_TRUSTED_TYPES_POLICY++;
19168
+ try {
19169
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
19170
+ } finally {
19171
+ IN_TRUSTED_TYPES_POLICY--;
19172
+ }
19173
+ };
19174
+ // Lazily resolve (and cache) the instance's internal default policy.
19175
+ // Resolution is attempted at most once: a successful `createPolicy` cannot be
19176
+ // repeated (Trusted Types throws on duplicate names), and a failed or
19177
+ // unsupported attempt must not be retried on every parse.
19178
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
19179
+ if (!defaultTrustedTypesPolicyResolved) {
19180
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
19181
+ defaultTrustedTypesPolicyResolved = true;
19182
+ }
19183
+ return defaultTrustedTypesPolicy;
19184
+ };
18933
19185
  const _document = document,
18934
19186
  implementation = _document.implementation,
18935
19187
  createNodeIterator = _document.createNodeIterator,
@@ -19026,6 +19278,13 @@
19026
19278
  let WHOLE_DOCUMENT = false;
19027
19279
  /* Track whether config is already set on this instance of DOMPurify. */
19028
19280
  let SET_CONFIG = false;
19281
+ /* Pristine allowlist bindings captured at setConfig() time. On the
19282
+ * persistent-config path sanitize() restores the sets from these before
19283
+ * the per-walk hook clone-guard, so a hook's in-call widening cannot
19284
+ * carry across calls. Null until setConfig() is called; reset by
19285
+ * clearConfig(). */
19286
+ let SET_CONFIG_ALLOWED_TAGS = null;
19287
+ let SET_CONFIG_ALLOWED_ATTR = null;
19029
19288
  /* Decide if all elements (e.g. style, script) must be children of
19030
19289
  * document.body. By default, browsers might move them to document.head */
19031
19290
  let FORCE_BODY = false;
@@ -19068,7 +19327,17 @@
19068
19327
  let USE_PROFILES = {};
19069
19328
  /* Tags to ignore content of when KEEP_CONTENT is true */
19070
19329
  let FORBID_CONTENTS = null;
19071
- 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']);
19330
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
19331
+ // <selectedcontent> mirrors the selected <option>'s subtree, cloned by
19332
+ // the UA (customizable <select>) — including any on* handlers — and the
19333
+ // engine re-mirrors synchronously whenever a removal changes which
19334
+ // option/selectedcontent is current, even inside DOMPurify's inert
19335
+ // DOMParser document. Hoisting its children on removal re-inserts a fresh
19336
+ // mirror target ahead of the walk, which the engine refills, looping
19337
+ // forever (DoS) and amplifying output. Dropping its content on removal
19338
+ // (rather than hoisting) breaks that cascade; the content is a duplicate
19339
+ // of the option, which is sanitized on its own. See campaign-3 F1/F6.
19340
+ 'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
19072
19341
  /* Tags that are safe for data: URIs */
19073
19342
  let DATA_URI_TAGS = null;
19074
19343
  const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
@@ -19084,8 +19353,10 @@
19084
19353
  /* Allowed XHTML+XML namespaces */
19085
19354
  let ALLOWED_NAMESPACES = null;
19086
19355
  const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
19087
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
19088
- let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
19356
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
19357
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
19358
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
19359
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
19089
19360
  // Certain elements are allowed in both SVG and HTML
19090
19361
  // namespace. We need to specify them explicitly
19091
19362
  // so that they don't get erroneously deleted from
@@ -19127,14 +19398,32 @@
19127
19398
  // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
19128
19399
  transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
19129
19400
  /* Set configuration parameters */
19130
- ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') && arrayIsArray(cfg.ALLOWED_TAGS) ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
19131
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') && arrayIsArray(cfg.ALLOWED_ATTR) ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
19132
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') && arrayIsArray(cfg.ALLOWED_NAMESPACES) ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
19133
- URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR) ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
19134
- DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') && arrayIsArray(cfg.ADD_DATA_URI_TAGS) ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
19135
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS) ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
19136
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') && arrayIsArray(cfg.FORBID_TAGS) ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
19137
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') && arrayIsArray(cfg.FORBID_ATTR) ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
19401
+ ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
19402
+ transform: transformCaseFunc
19403
+ });
19404
+ ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
19405
+ transform: transformCaseFunc
19406
+ });
19407
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
19408
+ transform: stringToString
19409
+ });
19410
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
19411
+ transform: transformCaseFunc,
19412
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
19413
+ });
19414
+ DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
19415
+ transform: transformCaseFunc,
19416
+ base: DEFAULT_DATA_URI_TAGS
19417
+ });
19418
+ FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
19419
+ transform: transformCaseFunc
19420
+ });
19421
+ FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
19422
+ transform: transformCaseFunc
19423
+ });
19424
+ FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
19425
+ transform: transformCaseFunc
19426
+ });
19138
19427
  USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
19139
19428
  ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
19140
19429
  ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
@@ -19153,8 +19442,8 @@
19153
19442
  IN_PLACE = cfg.IN_PLACE || false; // Default false
19154
19443
  IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
19155
19444
  NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
19156
- MATHML_TEXT_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'MATHML_TEXT_INTEGRATION_POINTS') && cfg.MATHML_TEXT_INTEGRATION_POINTS && typeof cfg.MATHML_TEXT_INTEGRATION_POINTS === 'object' ? clone(cfg.MATHML_TEXT_INTEGRATION_POINTS) : addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']); // Default built-in map
19157
- HTML_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'HTML_INTEGRATION_POINTS') && cfg.HTML_INTEGRATION_POINTS && typeof cfg.HTML_INTEGRATION_POINTS === 'object' ? clone(cfg.HTML_INTEGRATION_POINTS) : addToSet({}, ['annotation-xml']); // Default built-in map
19445
+ MATHML_TEXT_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'MATHML_TEXT_INTEGRATION_POINTS') && cfg.MATHML_TEXT_INTEGRATION_POINTS && typeof cfg.MATHML_TEXT_INTEGRATION_POINTS === 'object' ? clone(cfg.MATHML_TEXT_INTEGRATION_POINTS) : addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS); // Default built-in map
19446
+ HTML_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'HTML_INTEGRATION_POINTS') && cfg.HTML_INTEGRATION_POINTS && typeof cfg.HTML_INTEGRATION_POINTS === 'object' ? clone(cfg.HTML_INTEGRATION_POINTS) : addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS); // Default built-in map
19158
19447
  const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create$7(null);
19159
19448
  CUSTOM_ELEMENT_HANDLING = create$7(null);
19160
19449
  if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
@@ -19166,6 +19455,7 @@
19166
19455
  if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
19167
19456
  CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
19168
19457
  }
19458
+ seal(CUSTOM_ELEMENT_HANDLING);
19169
19459
  if (SAFE_FOR_TEMPLATES) {
19170
19460
  ALLOW_DATA_ATTR = false;
19171
19461
  }
@@ -19249,6 +19539,13 @@
19249
19539
  addToSet(ALLOWED_TAGS, ['tbody']);
19250
19540
  delete FORBID_TAGS.tbody;
19251
19541
  }
19542
+ // Re-derive the active Trusted Types policy from this configuration on
19543
+ // every parse. The active policy must never be sticky closure state that
19544
+ // outlives the config that set it: a caller-supplied policy left in place
19545
+ // after `clearConfig()` — or after a later call that supplied none, or
19546
+ // `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
19547
+ // `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
19548
+ // See GHSA-vxr8-fq34-vvx9.
19252
19549
  if (cfg.TRUSTED_TYPES_POLICY) {
19253
19550
  if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
19254
19551
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
@@ -19256,18 +19553,45 @@
19256
19553
  if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
19257
19554
  throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
19258
19555
  }
19259
- // Overwrite existing TrustedTypes policy.
19556
+ // A caller-supplied policy applies to this configuration only.
19557
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
19260
19558
  trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
19261
- // Sign local variables required by `sanitize`.
19262
- emptyHTML = trustedTypesPolicy.createHTML('');
19559
+ // Sign local variables required by `sanitize`. If the supplied policy's
19560
+ // `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
19561
+ // throws via the re-entrancy guard. Restore the previous policy first so
19562
+ // the instance is not left in a poisoned state. See #1422.
19563
+ try {
19564
+ emptyHTML = _createTrustedHTML('');
19565
+ } catch (error) {
19566
+ trustedTypesPolicy = previousTrustedTypesPolicy;
19567
+ throw error;
19568
+ }
19569
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
19570
+ // Explicit opt-out for this call: perform no Trusted Types signing and
19571
+ // create nothing (so a strict `trusted-types` CSP that disallows a
19572
+ // `dompurify` policy can still call `sanitize` from inside its own
19573
+ // policy — see #1422). Resetting to `undefined` rather than a sticky
19574
+ // `null` also drops any previously retained caller policy, so it cannot
19575
+ // resurface on a later call, while still allowing the next config-less
19576
+ // call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
19577
+ trustedTypesPolicy = undefined;
19578
+ emptyHTML = '';
19263
19579
  } else {
19264
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
19580
+ // No policy supplied: keep the currently active policy if one is set — a
19581
+ // previously supplied policy is intentionally sticky across config-less
19582
+ // calls — otherwise fall back to the instance's own internal policy,
19583
+ // created at most once. (A policy supplied for a *single* call still
19584
+ // lingers by design; what must not linger is a policy whose configuration
19585
+ // has been torn down via `clearConfig()`, which restores the default.)
19265
19586
  if (trustedTypesPolicy === undefined) {
19266
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
19587
+ trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
19267
19588
  }
19268
- // If creating the internal policy succeeded sign internal variables.
19269
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
19270
- emptyHTML = trustedTypesPolicy.createHTML('');
19589
+ // Sign internal variables only when a policy is active. A falsy policy
19590
+ // (Trusted Types unsupported, creation failed, or an explicit opt-out)
19591
+ // leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
19592
+ // a non-policy and throw. See #1422.
19593
+ if (trustedTypesPolicy && typeof emptyHTML === 'string') {
19594
+ emptyHTML = _createTrustedHTML('');
19271
19595
  }
19272
19596
  }
19273
19597
  // Prevent further manipulation of configuration.
@@ -19282,6 +19606,77 @@
19282
19606
  * correctly. */
19283
19607
  const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
19284
19608
  const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
19609
+ /**
19610
+ * Namespace rules for an element in the SVG namespace.
19611
+ *
19612
+ * @param tagName the element's lowercase tag name
19613
+ * @param parent the (possibly simulated) parent node
19614
+ * @param parentTagName the parent's lowercase tag name
19615
+ * @returns true if a spec-compliant parser could produce this element
19616
+ */
19617
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
19618
+ // The only way to switch from HTML namespace to SVG
19619
+ // is via <svg>. If it happens via any other tag, then
19620
+ // it should be killed.
19621
+ if (parent.namespaceURI === HTML_NAMESPACE) {
19622
+ return tagName === 'svg';
19623
+ }
19624
+ // The only way to switch from MathML to SVG is via <svg>
19625
+ // if the parent is either <annotation-xml> or a MathML
19626
+ // text integration point.
19627
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
19628
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
19629
+ }
19630
+ // We only allow elements that are defined in SVG
19631
+ // spec. All others are disallowed in SVG namespace.
19632
+ return Boolean(ALL_SVG_TAGS[tagName]);
19633
+ };
19634
+ /**
19635
+ * Namespace rules for an element in the MathML namespace.
19636
+ *
19637
+ * @param tagName the element's lowercase tag name
19638
+ * @param parent the (possibly simulated) parent node
19639
+ * @param parentTagName the parent's lowercase tag name
19640
+ * @returns true if a spec-compliant parser could produce this element
19641
+ */
19642
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
19643
+ // The only way to switch from HTML namespace to MathML
19644
+ // is via <math>. If it happens via any other tag, then
19645
+ // it should be killed.
19646
+ if (parent.namespaceURI === HTML_NAMESPACE) {
19647
+ return tagName === 'math';
19648
+ }
19649
+ // The only way to switch from SVG to MathML is via
19650
+ // <math> and HTML integration points
19651
+ if (parent.namespaceURI === SVG_NAMESPACE) {
19652
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
19653
+ }
19654
+ // We only allow elements that are defined in MathML
19655
+ // spec. All others are disallowed in MathML namespace.
19656
+ return Boolean(ALL_MATHML_TAGS[tagName]);
19657
+ };
19658
+ /**
19659
+ * Namespace rules for an element in the HTML namespace.
19660
+ *
19661
+ * @param tagName the element's lowercase tag name
19662
+ * @param parent the (possibly simulated) parent node
19663
+ * @param parentTagName the parent's lowercase tag name
19664
+ * @returns true if a spec-compliant parser could produce this element
19665
+ */
19666
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
19667
+ // The only way to switch from SVG to HTML is via
19668
+ // HTML integration points, and from MathML to HTML
19669
+ // is via MathML text integration points
19670
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
19671
+ return false;
19672
+ }
19673
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
19674
+ return false;
19675
+ }
19676
+ // We disallow tags that are specific for MathML
19677
+ // or SVG and should never appear in HTML namespace
19678
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
19679
+ };
19285
19680
  /**
19286
19681
  * @param element a DOM element whose namespace is being checked
19287
19682
  * @returns Return false if the element has a
@@ -19304,51 +19699,13 @@
19304
19699
  return false;
19305
19700
  }
19306
19701
  if (element.namespaceURI === SVG_NAMESPACE) {
19307
- // The only way to switch from HTML namespace to SVG
19308
- // is via <svg>. If it happens via any other tag, then
19309
- // it should be killed.
19310
- if (parent.namespaceURI === HTML_NAMESPACE) {
19311
- return tagName === 'svg';
19312
- }
19313
- // The only way to switch from MathML to SVG is via`
19314
- // svg if parent is either <annotation-xml> or MathML
19315
- // text integration points.
19316
- if (parent.namespaceURI === MATHML_NAMESPACE) {
19317
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
19318
- }
19319
- // We only allow elements that are defined in SVG
19320
- // spec. All others are disallowed in SVG namespace.
19321
- return Boolean(ALL_SVG_TAGS[tagName]);
19702
+ return _checkSvgNamespace(tagName, parent, parentTagName);
19322
19703
  }
19323
19704
  if (element.namespaceURI === MATHML_NAMESPACE) {
19324
- // The only way to switch from HTML namespace to MathML
19325
- // is via <math>. If it happens via any other tag, then
19326
- // it should be killed.
19327
- if (parent.namespaceURI === HTML_NAMESPACE) {
19328
- return tagName === 'math';
19329
- }
19330
- // The only way to switch from SVG to MathML is via
19331
- // <math> and HTML integration points
19332
- if (parent.namespaceURI === SVG_NAMESPACE) {
19333
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
19334
- }
19335
- // We only allow elements that are defined in MathML
19336
- // spec. All others are disallowed in MathML namespace.
19337
- return Boolean(ALL_MATHML_TAGS[tagName]);
19705
+ return _checkMathMlNamespace(tagName, parent, parentTagName);
19338
19706
  }
19339
19707
  if (element.namespaceURI === HTML_NAMESPACE) {
19340
- // The only way to switch from SVG to HTML is via
19341
- // HTML integration points, and from MathML to HTML
19342
- // is via MathML text integration points
19343
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
19344
- return false;
19345
- }
19346
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
19347
- return false;
19348
- }
19349
- // We disallow tags that are specific for MathML
19350
- // or SVG and should never appear in HTML namespace
19351
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
19708
+ return _checkHtmlNamespace(tagName, parent, parentTagName);
19352
19709
  }
19353
19710
  // For XHTML and XML documents that support custom namespaces
19354
19711
  if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
@@ -19373,7 +19730,81 @@
19373
19730
  // eslint-disable-next-line unicorn/prefer-dom-node-remove
19374
19731
  getParentNode(node).removeChild(node);
19375
19732
  } catch (_) {
19733
+ /* The normal detach failed — this is reached for a parentless node
19734
+ (getParentNode() is null, so .removeChild throws). Element.prototype
19735
+ .remove() is itself a spec no-op on a parentless node, so a recorded
19736
+ "removal" would otherwise hand the caller back an intact,
19737
+ payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
19738
+ the style-with-element-child rule decided to kill). Fail closed by
19739
+ throwing — exactly as a clobbered root does at the IN_PLACE entry —
19740
+ rather than trying to "neutralize" the node via its own methods.
19741
+ Neutralizing would mean calling getAttributeNames()/removeAttribute()
19742
+ on the node, both of which a <form> root can clobber via a named child
19743
+ (and _isClobbered does not even probe getAttributeNames), so the
19744
+ neutralize step could itself be silently defeated, leaving the payload
19745
+ intact. A throw touches only the cached, clobber-safe remove() and
19746
+ getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
19747
+ to every root-kill reason. REPORT-3.
19748
+ This lives inside the catch, so it never fires for a normally-removed
19749
+ in-tree node: those have a parent, removeChild() succeeds, and the
19750
+ catch is not entered. Only a kept (parentless) root reaches here. */
19376
19751
  remove(node);
19752
+ if (!getParentNode(node)) {
19753
+ throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
19754
+ }
19755
+ }
19756
+ };
19757
+ /**
19758
+ * _neutralizeRoot
19759
+ *
19760
+ * Fail-closed teardown of an in-place root after the sanitize walk aborts
19761
+ * (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
19762
+ * custom element's reaction detaches a node so `_forceRemove`'s deliberate
19763
+ * parentless guard throws, or any other re-entrant engine mutation — would
19764
+ * otherwise leave the caller's *live* tree half-sanitized, with everything
19765
+ * after the abort point still carrying its handlers. There is no safe way
19766
+ * to resume the walk (the tree mutated under us), so we strip the root bare:
19767
+ * remove every child and every attribute, then let the caller's catch see
19768
+ * the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
19769
+ * getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
19770
+ *
19771
+ * @param root the in-place root to empty
19772
+ */
19773
+ const _neutralizeRoot = function _neutralizeRoot(root) {
19774
+ /* Strip every disallowed attribute (on* handlers included) off the whole
19775
+ subtree BEFORE detaching anything. Detaching first would hand back
19776
+ handler-bearing originals (e.g. an already-loading `<img onerror>`)
19777
+ whose queued resource event still fires in page scope after we throw.
19778
+ Clobber-safe reads; a doomed clobbered node's own attributes are
19779
+ irrelevant while its non-clobbered descendants are reached and scrubbed. */
19780
+ _neutralizeSubtree(root);
19781
+ const childNodes = getChildNodes(root);
19782
+ if (childNodes) {
19783
+ const snapshot = [];
19784
+ arrayForEach(childNodes, child => {
19785
+ arrayPush(snapshot, child);
19786
+ });
19787
+ arrayForEach(snapshot, child => {
19788
+ try {
19789
+ remove(child);
19790
+ } catch (_) {
19791
+ /* Best-effort teardown; a still-attached child is handled below */
19792
+ }
19793
+ });
19794
+ }
19795
+ const attributes = getAttributes(root);
19796
+ if (attributes) {
19797
+ for (let i = attributes.length - 1; i >= 0; --i) {
19798
+ const attribute = attributes[i];
19799
+ const name = attribute && attribute.name;
19800
+ if (typeof name === 'string') {
19801
+ try {
19802
+ root.removeAttribute(name);
19803
+ } catch (_) {
19804
+ /* Clobbered removeAttribute — ignore (fail-closed best effort) */
19805
+ }
19806
+ }
19807
+ }
19377
19808
  }
19378
19809
  };
19379
19810
  /**
@@ -19408,6 +19839,148 @@
19408
19839
  }
19409
19840
  }
19410
19841
  };
19842
+ /**
19843
+ * _stripDisallowedAttributes
19844
+ *
19845
+ * Removes every attribute the active configuration does not allow from a
19846
+ * single element, using the same allowlist as the main attribute pass (so
19847
+ * `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
19848
+ * neutralise nodes that are being discarded from an in-place tree.
19849
+ *
19850
+ * @param element the element to strip
19851
+ */
19852
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
19853
+ const attributes = getAttributes(element);
19854
+ if (!attributes) {
19855
+ return;
19856
+ }
19857
+ for (let i = attributes.length - 1; i >= 0; --i) {
19858
+ const attribute = attributes[i];
19859
+ const name = attribute && attribute.name;
19860
+ if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
19861
+ continue;
19862
+ }
19863
+ try {
19864
+ element.removeAttribute(name);
19865
+ } catch (_) {
19866
+ /* Clobbered removeAttribute on a doomed node — ignore */
19867
+ }
19868
+ }
19869
+ };
19870
+ /**
19871
+ * _neutralizeSubtree
19872
+ *
19873
+ * Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
19874
+ * move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
19875
+ * namespace, comment, processing-instruction and KEEP_CONTENT:false removals
19876
+ * all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
19877
+ * those dropped nodes are detached from the caller's LIVE tree but a
19878
+ * handler-bearing original among them (an `<img onerror>`/`<video>` that was
19879
+ * loading) keeps its queued resource event, which fires in page scope after
19880
+ * sanitize returns. This walks a removed subtree and strips every attribute
19881
+ * the active configuration does not allow — so `on*` handlers are cancelled
19882
+ * through the SAME allowlist that governs kept nodes, not a separate `/^on/`
19883
+ * blocklist. Run synchronously before sanitize returns, i.e. before any
19884
+ * queued event can fire. Hook-free by design: these nodes leave the output,
19885
+ * so firing attribute hooks for them would be surprising. Clobber-safe reads;
19886
+ * a doomed clobbered node may shadow `removeAttribute` (its own attributes are
19887
+ * irrelevant — it is discarded — while its non-clobbered descendants, e.g.
19888
+ * the `<img>`, are reached and scrubbed).
19889
+ *
19890
+ * @param root the root of a removed subtree to neutralise
19891
+ */
19892
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
19893
+ const stack = [root];
19894
+ while (stack.length > 0) {
19895
+ const node = stack.pop();
19896
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
19897
+ if (nodeType === NODE_TYPE.element) {
19898
+ _stripDisallowedAttributes(node);
19899
+ }
19900
+ const childNodes = getChildNodes(node);
19901
+ if (childNodes) {
19902
+ for (let i = childNodes.length - 1; i >= 0; --i) {
19903
+ stack.push(childNodes[i]);
19904
+ }
19905
+ }
19906
+ }
19907
+ };
19908
+ /**
19909
+ * _neutralizePatchLinkage
19910
+ *
19911
+ * IN_PLACE entry pre-pass (declarative-partial-updates / streaming
19912
+ * hardening, https://github.com/WICG/declarative-partial-updates).
19913
+ *
19914
+ * The main walk strips patch linkage (`for`/`patchsrc`) and removes range
19915
+ * markers (PIs / markup comments) node-by-node, in document order, AS it
19916
+ * reaches each node. On a live in-place root that leaves a window: from the
19917
+ * moment the root is connected until the walk arrives at a given node, that
19918
+ * node's linkage is live. A patch applied on connection/stream can fire as
19919
+ * a microtask during the walk and inject or teleport an unsanitized DOM
19920
+ * range into a region the iterator has already passed and will not revisit,
19921
+ * so the post-return "tree is sanitized" contract is violated. Sweep the
19922
+ * whole tree once up front and sever every linkage before the walk begins,
19923
+ * closing that window.
19924
+ *
19925
+ * This CANNOT undo a patch that already fired before sanitize ran — that is
19926
+ * the irreducible "do not IN_PLACE a live-connected attacker tree" caveat —
19927
+ * but it closes everything from sanitize-start onward. Gated on SAFE_FOR_XML
19928
+ * to group with the rest of the declarative-partial-updates handling and
19929
+ * stay overridable, consistent with the codebase.
19930
+ *
19931
+ * Clobber-safe traversal (cached childNodes getter); per-node try/catch so a
19932
+ * clobbered root cannot defeat the sweep of its non-clobbered descendants.
19933
+ *
19934
+ * NOTE (pending real-Chrome confirmation, see test/declarative-patch-probe
19935
+ * .html Q1): this mirrors the existing policy of keeping `for` on
19936
+ * <label>/<output>. If the shipping feature can drive a patch through a
19937
+ * surviving `for`-on-label/output + `id` pair, this pre-pass and the
19938
+ * attribute check at _isBasicCustomElement's caller must additionally drop
19939
+ * that pair on the IN_PLACE path. Left as-is until the taxonomy is verified.
19940
+ *
19941
+ * @param root the in-place root to sweep
19942
+ */
19943
+ const _neutralizePatchLinkage = function _neutralizePatchLinkage(root) {
19944
+ if (!SAFE_FOR_XML) {
19945
+ return;
19946
+ }
19947
+ const stack = [root];
19948
+ while (stack.length > 0) {
19949
+ const node = stack.pop();
19950
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
19951
+ /* Remove range markers (the target side of a patch linkage): every
19952
+ processing instruction, and any markup-bearing comment. */
19953
+ if (nodeType === NODE_TYPE.processingInstruction || nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, node.data)) {
19954
+ try {
19955
+ remove(node);
19956
+ } catch (_) {
19957
+ /* Best-effort */
19958
+ }
19959
+ continue;
19960
+ }
19961
+ /* Strip patch-source attributes (the source side) off elements. */
19962
+ if (nodeType === NODE_TYPE.element) {
19963
+ const element = node;
19964
+ const lcTag = transformCaseFunc(getNodeName ? getNodeName(node) : node.nodeName);
19965
+ try {
19966
+ if (element.hasAttribute && element.hasAttribute('patchsrc')) {
19967
+ element.removeAttribute('patchsrc');
19968
+ }
19969
+ if (element.hasAttribute && element.hasAttribute('for') && lcTag !== 'label' && lcTag !== 'output') {
19970
+ element.removeAttribute('for');
19971
+ }
19972
+ } catch (_) {
19973
+ /* Clobbered removeAttribute/hasAttribute on a doomed node — ignore */
19974
+ }
19975
+ }
19976
+ const childNodes = getChildNodes(node);
19977
+ if (childNodes) {
19978
+ for (let i = childNodes.length - 1; i >= 0; --i) {
19979
+ stack.push(childNodes[i]);
19980
+ }
19981
+ }
19982
+ }
19983
+ };
19411
19984
  /**
19412
19985
  * _initDocument
19413
19986
  *
@@ -19429,7 +20002,7 @@
19429
20002
  // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
19430
20003
  dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
19431
20004
  }
19432
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
20005
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
19433
20006
  /*
19434
20007
  * Use the DOMParser API by default, fallback later if needs be
19435
20008
  * DOMParser not work for svg when has multiple root element.
@@ -19469,6 +20042,20 @@
19469
20042
  // eslint-disable-next-line no-bitwise
19470
20043
  NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
19471
20044
  };
20045
+ /**
20046
+ * Replace template expression syntax (mustache, ERB, template
20047
+ * literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
20048
+ * sites. Order matters: mustache, then ERB, then template literal.
20049
+ *
20050
+ * @param value the string to scrub
20051
+ * @returns the scrubbed string
20052
+ */
20053
+ const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
20054
+ value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
20055
+ value = stringReplace(value, ERB_EXPR$1, ' ');
20056
+ value = stringReplace(value, TMPLIT_EXPR$1, ' ');
20057
+ return value;
20058
+ };
19472
20059
  /**
19473
20060
  * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
19474
20061
  * character data of an element subtree. Used as the final safety net for
@@ -19488,29 +20075,100 @@
19488
20075
  *
19489
20076
  * @param node The root element whose character data should be scrubbed.
19490
20077
  */
19491
- const _scrubTemplateExpressions = function _scrubTemplateExpressions(node) {
20078
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
20079
+ var _node$querySelectorAl;
19492
20080
  node.normalize();
19493
20081
  const walker = createNodeIterator.call(node.ownerDocument || node, node,
19494
20082
  // eslint-disable-next-line no-bitwise
19495
20083
  NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
19496
20084
  let currentNode = walker.nextNode();
19497
20085
  while (currentNode) {
19498
- let data = currentNode.data;
19499
- arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
19500
- data = stringReplace(data, expr, ' ');
19501
- });
19502
- currentNode.data = data;
20086
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
19503
20087
  currentNode = walker.nextNode();
19504
20088
  }
20089
+ // NodeIterator does not descend into <template>.content per the DOM spec,
20090
+ // so we must explicitly recurse into each template's content fragment,
20091
+ // mirroring the approach used by _sanitizeShadowDOM.
20092
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
20093
+ if (templates) {
20094
+ arrayForEach(templates, tmpl => {
20095
+ if (_isDocumentFragment(tmpl.content)) {
20096
+ _scrubTemplateExpressions2(tmpl.content);
20097
+ }
20098
+ });
20099
+ }
19505
20100
  };
19506
20101
  /**
19507
20102
  * _isClobbered
19508
20103
  *
20104
+ * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
20105
+ * interface with [LegacyOverrideBuiltIns]; a descendant element with a
20106
+ * `name` attribute matching a prototype property shadows that property
20107
+ * on direct reads. We use this check at the IN_PLACE entry-point and
20108
+ * during attribute sanitization to refuse clobbered forms.
20109
+ *
19509
20110
  * @param element element to check for clobbering attacks
19510
20111
  * @return true if clobbered, false if safe
19511
20112
  */
19512
20113
  const _isClobbered = function _isClobbered(element) {
19513
- return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');
20114
+ // Realm-independent tag-name probe. If we can't determine the tag
20115
+ // name at all, we can't reason about clobbering — return false
20116
+ // (the caller's other defences still apply).
20117
+ const realTagName = getNodeName ? getNodeName(element) : null;
20118
+ if (typeof realTagName !== 'string') {
20119
+ return false;
20120
+ }
20121
+ if (transformCaseFunc(realTagName) !== 'form') {
20122
+ return false;
20123
+ }
20124
+ return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
20125
+ // Realm-safe NamedNodeMap detection: equality against the cached
20126
+ // prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
20127
+ // makes the direct read diverge from the cached read; a clean form
20128
+ // (same-realm OR foreign-realm) has both reads pointing at the same
20129
+ // canonical NamedNodeMap.
20130
+ element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
20131
+ // NodeType clobbering probe. Cached Node.prototype.nodeType getter
20132
+ // returns the integer 1 for any Element regardless of realm; direct
20133
+ // read on a clobbered form (e.g. <input name="nodeType">) returns
20134
+ // the named child element. Cheap addition — nodeType is read from
20135
+ // an internal slot, no serialization cost — and removes a residual
20136
+ // clobbering surface used by several mXSS / PI / comment branches
20137
+ // in _sanitizeElements that compare currentNode.nodeType directly.
20138
+ element.nodeType !== getNodeType(element) ||
20139
+ // HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
20140
+ // "childNodes" shadows the prototype getter. Direct reads of
20141
+ // form.childNodes from a clobbered form return the named child
20142
+ // instead of the real NodeList, so any walk that reads it directly
20143
+ // skips the form's real children. Compare the direct read to the
20144
+ // cached Node.prototype getter — when the form's named-property
20145
+ // getter intercepts the read, the two values differ and we flag
20146
+ // the form. This catches every clobbering child type (input,
20147
+ // select, etc.) regardless of whether the named child happens to
20148
+ // carry a numeric .length, which a typeof-based probe would miss
20149
+ // (e.g. HTMLSelectElement.length is a defined unsigned-long).
20150
+ element.childNodes !== getChildNodes(element);
20151
+ };
20152
+ /**
20153
+ * Checks whether the given value is a DocumentFragment from any realm.
20154
+ *
20155
+ * The realm-independent replacement reads `nodeType` through the cached
20156
+ * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
20157
+ * constant (11). nodeType is a numeric value resolved from the node's
20158
+ * internal slot, identical across realms for the same kind of node.
20159
+ *
20160
+ * @param value object to check
20161
+ * @return true if value is a DocumentFragment-shaped node from any realm
20162
+ */
20163
+ const _isDocumentFragment = function _isDocumentFragment(value) {
20164
+ if (!getNodeType || typeof value !== 'object' || value === null) {
20165
+ return false;
20166
+ }
20167
+ try {
20168
+ return getNodeType(value) === NODE_TYPE.documentFragment;
20169
+ } catch (_) {
20170
+ return false;
20171
+ }
19514
20172
  };
19515
20173
  /**
19516
20174
  * Checks whether the given object is a DOM node, including nodes that
@@ -19520,12 +20178,6 @@
19520
20178
  * sanitize() to silently stringify them and reset IN_PLACE to false,
19521
20179
  * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
19522
20180
  *
19523
- * Implementation: call the cached `nodeType` getter from Node.prototype
19524
- * directly on the value. This bypasses any clobbered instance property
19525
- * (e.g. a child element named "nodeType") and works across realms
19526
- * because the WebIDL `nodeType` getter reads an internal slot that
19527
- * every real Node has, regardless of which window minted it.
19528
- *
19529
20181
  * @param value object to check whether it's a DOM node
19530
20182
  * @return true if value is a DOM node from any realm
19531
20183
  */
@@ -19540,10 +20192,110 @@
19540
20192
  }
19541
20193
  };
19542
20194
  function _executeHooks(hooks, currentNode, data) {
20195
+ if (hooks.length === 0) {
20196
+ return;
20197
+ }
19543
20198
  arrayForEach(hooks, hook => {
19544
20199
  hook.call(DOMPurify, currentNode, data, CONFIG);
19545
20200
  });
19546
20201
  }
20202
+ /**
20203
+ * Structural-threat checks that condemn a node regardless of the
20204
+ * allowlists: mXSS via namespace confusion, risky CSS construction,
20205
+ * processing instructions, markup-bearing comments. Pure predicate;
20206
+ * the caller removes. Check order is load-bearing.
20207
+ *
20208
+ * @param currentNode the node to inspect
20209
+ * @param tagName the node's transformCaseFunc'd tag name
20210
+ * @return true if the node must be removed
20211
+ */
20212
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
20213
+ /* Detect mXSS attempts abusing namespace confusion */
20214
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
20215
+ return true;
20216
+ }
20217
+ /* Remove risky CSS construction leading to mXSS */
20218
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
20219
+ return true;
20220
+ }
20221
+ /* Remove any occurrence of processing instructions */
20222
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
20223
+ return true;
20224
+ }
20225
+ /* Remove any kind of possibly harmful comments */
20226
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
20227
+ return true;
20228
+ }
20229
+ return false;
20230
+ };
20231
+ /**
20232
+ * Handle a node whose tag is forbidden or not allowlisted: keep
20233
+ * allowed custom elements (false return exits _sanitizeElements
20234
+ * early - the namespace and fallback-tag removal checks are
20235
+ * intentionally skipped for kept custom elements), else hoist
20236
+ * content per KEEP_CONTENT and remove.
20237
+ *
20238
+ * A kept custom element is the ONLY case in which this function
20239
+ * returns false, so the caller uses that return value to run the
20240
+ * afterSanitizeElements hook on the kept element and keep the
20241
+ * element-hook lifecycle consistent with normal allowlisted
20242
+ * elements (GHSA-c2j3-45gr-mqc4).
20243
+ *
20244
+ * @param currentNode the disallowed node
20245
+ * @param tagName the node's transformCaseFunc'd tag name
20246
+ * @return true if the node was removed, false if kept
20247
+ */
20248
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
20249
+ /* Check if we have a custom element to handle */
20250
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
20251
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
20252
+ return false;
20253
+ }
20254
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
20255
+ return false;
20256
+ }
20257
+ }
20258
+ /* Keep content except for bad-listed elements.
20259
+ Use the cached prototype getters exclusively — the previous code
20260
+ had `|| currentNode.parentNode` / `|| currentNode.childNodes`
20261
+ fallbacks, but the cached getters always return the canonical
20262
+ value (or null for a real parent-less node), so the fallback
20263
+ path was dead in safe cases and a clobbering surface in unsafe
20264
+ ones. Falsy cached results stay falsy; the `if (childNodes &&
20265
+ parentNode)` check already gates correctly. */
20266
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
20267
+ const parentNode = getParentNode(currentNode);
20268
+ const childNodes = getChildNodes(currentNode);
20269
+ if (childNodes && parentNode) {
20270
+ const childCount = childNodes.length;
20271
+ /* In-place: hoist the *original* children so the iterator visits
20272
+ and sanitises them through the same allowlist pass as every other
20273
+ node. The caller built the tree in the live document, so the
20274
+ originals carry already-queued resource events (`<img onerror>`,
20275
+ `<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
20276
+ those originals detached but still armed, firing in page scope
20277
+ while the returned tree looked clean. Moving is safe in-place: the
20278
+ root is pre-validated as an allowed tag and so is never the node
20279
+ being removed, which keeps `parentNode` inside the iterator root
20280
+ and the relocated child inside the serialised tree.
20281
+ Otherwise (string / DOM-copy paths): clone. The iterator is rooted
20282
+ at — and the result serialised from — `body`, so a restrictive
20283
+ ALLOWED_TAGS that removes `body` itself must leave its content in
20284
+ place, which only cloning does; and those paths parse into an
20285
+ inert document, so their discarded originals never had a queued
20286
+ event to neutralise.
20287
+ `childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
20288
+ valid whether we move (drops the trailing entry) or clone (leaves
20289
+ the list intact). */
20290
+ for (let i = childCount - 1; i >= 0; --i) {
20291
+ const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
20292
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
20293
+ }
20294
+ }
20295
+ }
20296
+ _forceRemove(currentNode);
20297
+ return true;
20298
+ };
19547
20299
  /**
19548
20300
  * _sanitizeElements
19549
20301
  *
@@ -19553,85 +20305,89 @@
19553
20305
  * @param currentNode to check for permission to exist
19554
20306
  * @return true if node was killed, false if left alive
19555
20307
  */
19556
- const _sanitizeElements = function _sanitizeElements(currentNode) {
19557
- let content = null;
20308
+ // eslint-disable-next-line complexity
20309
+ const _sanitizeElements = function _sanitizeElements(currentNode, root) {
19558
20310
  /* Execute a hook if present */
19559
20311
  _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
20312
+ /* A hook may have detached the node — treat it as removed (see the
20313
+ detached-node comment after the uponSanitizeElement hook below). */
20314
+ if (currentNode !== root && getParentNode(currentNode) === null) {
20315
+ return true;
20316
+ }
19560
20317
  /* Check if element is clobbered or can clobber */
19561
20318
  if (_isClobbered(currentNode)) {
19562
20319
  _forceRemove(currentNode);
19563
20320
  return true;
19564
20321
  }
19565
20322
  /* Now let's check the element's type and name */
19566
- const tagName = transformCaseFunc(currentNode.nodeName);
20323
+ const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
19567
20324
  /* Execute a hook if present */
19568
20325
  _executeHooks(hooks.uponSanitizeElement, currentNode, {
19569
20326
  tagName,
19570
20327
  allowedTags: ALLOWED_TAGS
19571
20328
  });
19572
- /* Detect mXSS attempts abusing namespace confusion */
19573
- if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
19574
- _forceRemove(currentNode);
19575
- return true;
19576
- }
19577
- /* Remove risky CSS construction leading to mXSS */
19578
- if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
19579
- _forceRemove(currentNode);
20329
+ /* A hook may have detached the node from the tree — a long-standing
20330
+ user pattern (issue #469; draw.io-style foreignObject filtering).
20331
+ Per the cached, unclobberable parentNode getter the node is
20332
+ genuinely out of the tree, so it can reach neither the serialized
20333
+ output nor an IN_PLACE live tree; treat it as removed and stop
20334
+ processing it. Without this guard, the unsafe-node / namespace
20335
+ checks below would call _forceRemove on a parentless node and hit
20336
+ the REPORT-3 fail-closed throw — which exists for nodes DOMPurify
20337
+ wants gone but *cannot* detach (clobbered / parentless roots), the
20338
+ opposite of a node that is already safely gone. The walk root is
20339
+ exempt: a detached IN_PLACE root is legitimate input and must still
20340
+ be fully sanitized, and a kill-decision on it must keep hitting the
20341
+ REPORT-3 throw. Nodes detached by hooks are the hook's
20342
+ responsibility: they are not recorded in DOMPurify.removed and are
20343
+ not neutralized by the post-walk IN_PLACE pass. */
20344
+ if (currentNode !== root && getParentNode(currentNode) === null) {
19580
20345
  return true;
19581
20346
  }
19582
- /* Remove any occurrence of processing instructions */
19583
- if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
19584
- _forceRemove(currentNode);
19585
- return true;
19586
- }
19587
- /* Remove any kind of possibly harmful comments */
19588
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
20347
+ /* Remove mXSS vectors, processing instructions and risky comments */
20348
+ if (_isUnsafeNode(currentNode, tagName)) {
19589
20349
  _forceRemove(currentNode);
19590
20350
  return true;
19591
20351
  }
19592
20352
  /* Remove element if anything forbids its presence */
19593
20353
  if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
19594
- /* Check if we have a custom element to handle */
19595
- if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
19596
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
19597
- return false;
19598
- }
19599
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
19600
- return false;
19601
- }
19602
- }
19603
- /* Keep content except for bad-listed elements */
19604
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
19605
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
19606
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
19607
- if (childNodes && parentNode) {
19608
- const childCount = childNodes.length;
19609
- for (let i = childCount - 1; i >= 0; --i) {
19610
- const childClone = cloneNode(childNodes[i], true);
19611
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
19612
- }
19613
- }
20354
+ const removed = _sanitizeDisallowedNode(currentNode, tagName);
20355
+ /* A false return means the node is a custom element kept via
20356
+ CUSTOM_ELEMENT_HANDLING - the only keep path through
20357
+ _sanitizeDisallowedNode. Run afterSanitizeElements on it so the
20358
+ element-hook lifecycle matches normal allowlisted elements: a
20359
+ security policy applied in this hook (e.g. stripping an attribute
20360
+ from every surviving element) must not silently skip kept custom
20361
+ elements (GHSA-c2j3-45gr-mqc4). This mirrors the normal-element
20362
+ tail below - the hook runs, then the walker's subsequent
20363
+ _sanitizeAttributes pass sanitizes the element's attributes. The
20364
+ deliberately skipped namespace and fallback-tag removal checks stay
20365
+ skipped; they are removal decisions, not the hook contract. */
20366
+ if (removed === false) {
20367
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
19614
20368
  }
19615
- _forceRemove(currentNode);
19616
- return true;
19617
- }
19618
- /* Check whether element has a valid namespace */
19619
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
20369
+ return removed;
20370
+ }
20371
+ /* Check whether element has a valid namespace.
20372
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
20373
+ nodeType getter rather than `instanceof Element`, which is realm-
20374
+ bound and short-circuits to false for any node minted in a different
20375
+ realm — letting a foreign-realm element with a forbidden namespace
20376
+ slip past the namespace check entirely. */
20377
+ const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
20378
+ if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
19620
20379
  _forceRemove(currentNode);
19621
20380
  return true;
19622
20381
  }
19623
20382
  /* Make sure that older browsers don't get fallback-tag mXSS */
19624
- if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
20383
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
19625
20384
  _forceRemove(currentNode);
19626
20385
  return true;
19627
20386
  }
19628
20387
  /* Sanitize element content to be template-safe */
19629
20388
  if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
19630
20389
  /* Get the element's text content */
19631
- content = currentNode.textContent;
19632
- arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
19633
- content = stringReplace(content, expr, ' ');
19634
- });
20390
+ const content = _stripTemplateExpressions(currentNode.textContent);
19635
20391
  if (currentNode.textContent !== content) {
19636
20392
  arrayPush(DOMPurify.removed, {
19637
20393
  element: currentNode.cloneNode()
@@ -19657,6 +20413,33 @@
19657
20413
  if (FORBID_ATTR[lcName]) {
19658
20414
  return false;
19659
20415
  }
20416
+ /* Reject declarative-partial-updates patch-linkage attributes
20417
+ (https://github.com/WICG/declarative-partial-updates).
20418
+ Empirical note (Chrome 150, verified — see
20419
+ test/declarative-patch-probe-v3.html): expansion is NOT applied after
20420
+ sanitization. For the string path it fires during sanitize()'s own
20421
+ parse, so the walk sees and sanitizes the fully materialized expanded
20422
+ tree — teleports into MathML/SVG integration points included; a
20423
+ weaponized `<template for>`->`<img onerror>` comes back with the handler
20424
+ stripped. For the IN_PLACE path it fires on connection, before the walk.
20425
+ Either way DOMPurify is NOT blind to the patch.
20426
+ This removal is therefore defense-in-depth rather than the sole barrier:
20427
+ it prevents live linkage from surviving into the OUTPUT and re-expanding
20428
+ in the caller's context, and keeps behaviour deterministic if a future
20429
+ engine defers expansion. `for` is legitimate only on <label>/<output>;
20430
+ anywhere else (notably <template for>) it links the element to a patch
20431
+ target and teleports or removes an arbitrary DOM range by id/marker name.
20432
+ `patchsrc` fetches remote markup and is treated as a script-loading
20433
+ mechanism (CSP). Gated on SAFE_FOR_XML so the removal groups with the
20434
+ other structural-threat checks and stays overridable, consistent with
20435
+ the rest of the codebase. PI range markers are already removed by
20436
+ _isUnsafeNode. */
20437
+ if (SAFE_FOR_XML && lcName === 'patchsrc') {
20438
+ return false;
20439
+ }
20440
+ if (SAFE_FOR_XML && lcName === 'for' && lcTag !== 'label' && lcTag !== 'output') {
20441
+ return false;
20442
+ }
19660
20443
  /* Make sure attribute cannot clobber */
19661
20444
  if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
19662
20445
  return false;
@@ -19666,7 +20449,7 @@
19666
20449
  (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
19667
20450
  XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
19668
20451
  We don't need to check the value; it's always URI safe. */
19669
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted || FORBID_ATTR[lcName]) {
20452
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
19670
20453
  if (
19671
20454
  // First condition does a very basic check if a) it's basically a valid custom element tagname AND
19672
20455
  // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
@@ -19698,6 +20481,63 @@
19698
20481
  const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
19699
20482
  return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
19700
20483
  };
20484
+ /**
20485
+ * Wrap an attribute value in the matching Trusted Types object when
20486
+ * the active policy requires it. Namespaced attributes pass through
20487
+ * unchanged (no TT support yet, see
20488
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
20489
+ *
20490
+ * @param lcTag lowercase tag name of the containing element
20491
+ * @param lcName lowercase attribute name
20492
+ * @param namespaceURI the attribute's namespace, if any
20493
+ * @param value the attribute value to wrap
20494
+ * @return the value, wrapped when Trusted Types demand it
20495
+ */
20496
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
20497
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
20498
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
20499
+ case 'TrustedHTML':
20500
+ {
20501
+ return _createTrustedHTML(value);
20502
+ }
20503
+ case 'TrustedScriptURL':
20504
+ {
20505
+ return _createTrustedScriptURL(value);
20506
+ }
20507
+ }
20508
+ }
20509
+ return value;
20510
+ };
20511
+ /**
20512
+ * Write a modified attribute value back onto the element. On
20513
+ * success, re-probe for clobbering introduced by the new value and
20514
+ * remove the element when found; otherwise pop the removal entry
20515
+ * recorded by the earlier _removeAttribute (long-standing pairing
20516
+ * with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
20517
+ * failure, remove the attribute instead.
20518
+ *
20519
+ * @param currentNode the element carrying the attribute
20520
+ * @param name the attribute name as present on the element
20521
+ * @param namespaceURI the attribute's namespace, if any
20522
+ * @param value the new attribute value
20523
+ */
20524
+ const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
20525
+ try {
20526
+ if (namespaceURI) {
20527
+ currentNode.setAttributeNS(namespaceURI, name, value);
20528
+ } else {
20529
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
20530
+ currentNode.setAttribute(name, value);
20531
+ }
20532
+ if (_isClobbered(currentNode)) {
20533
+ _forceRemove(currentNode);
20534
+ } else {
20535
+ arrayPop(DOMPurify.removed);
20536
+ }
20537
+ } catch (_) {
20538
+ _removeAttribute(name, currentNode);
20539
+ }
20540
+ };
19701
20541
  /**
19702
20542
  * _sanitizeAttributes
19703
20543
  *
@@ -19724,6 +20564,7 @@
19724
20564
  forceKeepAttr: undefined
19725
20565
  };
19726
20566
  let l = attributes.length;
20567
+ const lcTag = transformCaseFunc(currentNode.nodeName);
19727
20568
  /* Go backwards over all attributes; safely remove bad ones */
19728
20569
  while (l--) {
19729
20570
  const attr = attributes[l];
@@ -19761,7 +20602,7 @@
19761
20602
  _removeAttribute(name, currentNode);
19762
20603
  continue;
19763
20604
  }
19764
- /* Did the hooks approve of the attribute? */
20605
+ /* Did the hooks force-keep the attribute? */
19765
20606
  if (hookEvent.forceKeepAttr) {
19766
20607
  continue;
19767
20608
  }
@@ -19771,56 +20612,24 @@
19771
20612
  continue;
19772
20613
  }
19773
20614
  /* Work around a security issue in jQuery 3.0 */
19774
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
20615
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
19775
20616
  _removeAttribute(name, currentNode);
19776
20617
  continue;
19777
20618
  }
19778
20619
  /* Sanitize attribute content to be template-safe */
19779
20620
  if (SAFE_FOR_TEMPLATES) {
19780
- arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
19781
- value = stringReplace(value, expr, ' ');
19782
- });
20621
+ value = _stripTemplateExpressions(value);
19783
20622
  }
19784
20623
  /* Is `value` valid for this attribute? */
19785
- const lcTag = transformCaseFunc(currentNode.nodeName);
19786
20624
  if (!_isValidAttribute(lcTag, lcName, value)) {
19787
20625
  _removeAttribute(name, currentNode);
19788
20626
  continue;
19789
20627
  }
19790
20628
  /* Handle attributes that require Trusted Types */
19791
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
19792
- if (namespaceURI) ; else {
19793
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
19794
- case 'TrustedHTML':
19795
- {
19796
- value = trustedTypesPolicy.createHTML(value);
19797
- break;
19798
- }
19799
- case 'TrustedScriptURL':
19800
- {
19801
- value = trustedTypesPolicy.createScriptURL(value);
19802
- break;
19803
- }
19804
- }
19805
- }
19806
- }
20629
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
19807
20630
  /* Handle invalid data-* attribute set by try-catching it */
19808
20631
  if (value !== initValue) {
19809
- try {
19810
- if (namespaceURI) {
19811
- currentNode.setAttributeNS(namespaceURI, name, value);
19812
- } else {
19813
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
19814
- currentNode.setAttribute(name, value);
19815
- }
19816
- if (_isClobbered(currentNode)) {
19817
- _forceRemove(currentNode);
19818
- } else {
19819
- arrayPop(DOMPurify.removed);
19820
- }
19821
- } catch (_) {
19822
- _removeAttribute(name, currentNode);
19823
- }
20632
+ _setAttributeValue(currentNode, name, namespaceURI, value);
19824
20633
  }
19825
20634
  }
19826
20635
  /* Execute a hook if present */
@@ -19840,13 +20649,34 @@
19840
20649
  /* Execute a hook if present */
19841
20650
  _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
19842
20651
  /* Sanitize tags and elements */
19843
- _sanitizeElements(shadowNode);
20652
+ _sanitizeElements(shadowNode, fragment);
19844
20653
  /* Check attributes next */
19845
20654
  _sanitizeAttributes(shadowNode);
19846
- /* Deep shadow DOM detected */
19847
- if (shadowNode.content instanceof DocumentFragment) {
20655
+ /* Deep shadow DOM detected.
20656
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
20657
+ DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
20658
+ recurse into <template>.content from foreign realms too. */
20659
+ if (_isDocumentFragment(shadowNode.content)) {
19848
20660
  _sanitizeShadowDOM2(shadowNode.content);
19849
20661
  }
20662
+ /* An element iterated here may itself host an attached
20663
+ shadow root. The default NodeIterator does not enter shadow
20664
+ trees, so a shadow root nested inside template.content was
20665
+ previously reached by no walk at all (the pre-pass at
20666
+ _sanitizeAttachedShadowRoots descends via childNodes, which
20667
+ doesn't enter template.content; the template-content recursion
20668
+ above iterates the content but never inspected shadowRoot).
20669
+ Walk it explicitly. The nodeType guard avoids reading
20670
+ shadowRoot off text / comment / CDATA / PI nodes that the
20671
+ iterator also surfaces. */
20672
+ const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
20673
+ if (shadowNodeType === NODE_TYPE.element) {
20674
+ const innerSr = getShadowRoot(shadowNode);
20675
+ if (_isDocumentFragment(innerSr)) {
20676
+ _sanitizeAttachedShadowRoots(innerSr);
20677
+ _sanitizeShadowDOM2(innerSr);
20678
+ }
20679
+ }
19850
20680
  }
19851
20681
  /* Execute a hook if present */
19852
20682
  _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
@@ -19870,28 +20700,83 @@
19870
20700
  *
19871
20701
  * @param root the subtree root to walk for attached shadow roots
19872
20702
  */
19873
- const _sanitizeAttachedShadowRoots2 = function _sanitizeAttachedShadowRoots(root) {
19874
- if (root.nodeType === NODE_TYPE.element && root.shadowRoot instanceof DocumentFragment) {
19875
- const sr = root.shadowRoot;
19876
- // Recurse first so that nested shadow roots are reached even if
19877
- // _sanitizeShadowDOM removes hosts at this level.
19878
- _sanitizeAttachedShadowRoots2(sr);
19879
- _sanitizeShadowDOM2(sr);
19880
- }
19881
- // Snapshot children before recursing. Sanitization of one subtree
19882
- // (e.g. via an uponSanitizeShadowNode hook) may detach siblings,
19883
- // and naive nextSibling traversal would silently skip the rest of
19884
- // the list once a node is detached.
19885
- const childNodes = root.childNodes;
19886
- if (!childNodes) {
19887
- return;
19888
- }
19889
- const snapshot = [];
19890
- arrayForEach(childNodes, child => {
19891
- arrayPush(snapshot, child);
19892
- });
19893
- for (const child of snapshot) {
19894
- _sanitizeAttachedShadowRoots2(child);
20703
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
20704
+ /* Iterative (explicit stack) rather than per-child recursion. DOM APIs
20705
+ impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
20706
+ built straight into the DOM the IN_PLACE surface) deeper than the JS
20707
+ call-stack budget would otherwise overflow native recursion here and
20708
+ throw at the IN_PLACE entry pre-pass, before a single node is
20709
+ sanitized, leaving the caller's live tree untouched (fail-open). See
20710
+ campaign-3 F4. A heap stack keeps depth off the call stack.
20711
+ Each work item is either a node to descend into, or a deferred
20712
+ `_sanitizeShadowDOM` for an already-walked shadow root. The deferred
20713
+ form preserves the original post-order discipline: a shadow root's
20714
+ nested shadow roots are discovered before the outer shadow is
20715
+ sanitized (which may remove hosts). Pushes are in reverse of the
20716
+ desired processing order (LIFO): template content, then children, then
20717
+ the shadow-sanitize, then the shadow walk — so the order matches the
20718
+ previous recursion exactly. */
20719
+ const stack = [{
20720
+ node: root,
20721
+ shadow: null
20722
+ }];
20723
+ while (stack.length > 0) {
20724
+ const item = stack.pop();
20725
+ /* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
20726
+ if (item.shadow) {
20727
+ _sanitizeShadowDOM2(item.shadow);
20728
+ continue;
20729
+ }
20730
+ const node = item.node;
20731
+ const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
20732
+ const isElement = nodeType === NODE_TYPE.element;
20733
+ /* (pushed last → processed first) Children, snapshotted in reverse so
20734
+ the first child is processed first. Snapshotting matters because a
20735
+ hook may detach siblings mid-walk. */
20736
+ const childNodes = getChildNodes(node);
20737
+ if (childNodes) {
20738
+ for (let i = childNodes.length - 1; i >= 0; --i) {
20739
+ stack.push({
20740
+ node: childNodes[i],
20741
+ shadow: null
20742
+ });
20743
+ }
20744
+ }
20745
+ /* (pushed before children → processed after them, matching the old
20746
+ "template content last" order) When the node is a <template>,
20747
+ descend into its content. */
20748
+ if (isElement) {
20749
+ const rootName = getNodeName ? getNodeName(node) : null;
20750
+ if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
20751
+ const content = node.content;
20752
+ if (_isDocumentFragment(content)) {
20753
+ stack.push({
20754
+ node: content,
20755
+ shadow: null
20756
+ });
20757
+ }
20758
+ }
20759
+ }
20760
+ /* Shadow root (processed first): walk its subtree, then sanitise it.
20761
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
20762
+ rather than `instanceof DocumentFragment`, which is realm-bound and
20763
+ silently skipped foreign-realm shadow roots (e.g.
20764
+ iframe.contentDocument attachShadow). */
20765
+ if (isElement) {
20766
+ const sr = getShadowRoot(node);
20767
+ if (_isDocumentFragment(sr)) {
20768
+ /* Push the deferred sanitise first so it pops after the shadow
20769
+ walk we push next, i.e. nested shadow roots are discovered
20770
+ before this one is sanitised. */
20771
+ stack.push({
20772
+ node: null,
20773
+ shadow: sr
20774
+ }, {
20775
+ node: sr,
20776
+ shadow: null
20777
+ });
20778
+ }
20779
+ }
19895
20780
  }
19896
20781
  };
19897
20782
  // eslint-disable-next-line complexity
@@ -19920,27 +20805,89 @@
19920
20805
  return dirty;
19921
20806
  }
19922
20807
  /* Assign config vars */
19923
- if (!SET_CONFIG) {
20808
+ if (SET_CONFIG) {
20809
+ /* Persistent setConfig() path: _parseConfig is skipped, so the sets are
20810
+ * not re-derived per call. Restore them from the pristine bindings
20811
+ * captured at setConfig() time so a previous call's hook clone (mutated
20812
+ * below) does not carry over. */
20813
+ ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
20814
+ ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
20815
+ } else {
19924
20816
  _parseConfig(cfg);
19925
20817
  }
20818
+ /* Clone the hook-mutable allowlists before the walk whenever an
20819
+ * uponSanitize* hook is registered. The hook event exposes ALLOWED_TAGS
20820
+ * and ALLOWED_ATTR by reference (as allowedTags / allowedAttributes), so
20821
+ * a hook that widens them would otherwise mutate the shared set
20822
+ * permanently: across later calls and across every element. Cloning per
20823
+ * walk keeps documented in-call widening working while scoping it to the
20824
+ * call. A single guard for both config paths - the per-call path rebinds
20825
+ * the sets in _parseConfig each call, the persistent path restores them
20826
+ * from the captured bindings just above - so the two cannot diverge. */
20827
+ if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) {
20828
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
20829
+ }
20830
+ if (hooks.uponSanitizeAttribute.length > 0) {
20831
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
20832
+ }
19926
20833
  /* Clean up removed elements */
19927
20834
  DOMPurify.removed = [];
19928
- /* Check if dirty is correctly typed for IN_PLACE */
19929
- if (typeof dirty === 'string') {
19930
- IN_PLACE = false;
19931
- }
19932
- if (IN_PLACE) {
19933
- /* Do some early pre-sanitization to avoid unsafe root nodes */
19934
- const nn = dirty.nodeName;
20835
+ /* Resolve IN_PLACE for this call without mutating persistent config.
20836
+ Writing the IN_PLACE closure variable here leaks under setConfig(),
20837
+ where _parseConfig is skipped on later calls: a single string call would
20838
+ disable in-place mode for every subsequent node call, returning a
20839
+ sanitized copy while leaving the caller's node — which in-place callers
20840
+ keep using and whose return value they ignore unsanitized. REPORT-2. */
20841
+ const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
20842
+ if (inPlace) {
20843
+ /* Declarative-partial-updates / streaming pre-pass: sever every patch
20844
+ linkage across the live tree BEFORE the walk, so no patch can fire
20845
+ mid-walk and inject into an already-processed region. Runs first, so
20846
+ it also covers the forbidden/clobbered roots that throw below. */
20847
+ _neutralizePatchLinkage(dirty);
20848
+ /* Do some early pre-sanitization to avoid unsafe root nodes.
20849
+ Read nodeName through the cached prototype getter — a clobbering
20850
+ child named "nodeName" on the form root would otherwise shadow
20851
+ the property and let this check skip the root-allowlist
20852
+ validation entirely. */
20853
+ const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
19935
20854
  if (typeof nn === 'string') {
19936
20855
  const tagName = transformCaseFunc(nn);
19937
20856
  if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
20857
+ /* Fail closed on a live root: neutralize handlers/children before
20858
+ throwing, exactly as the mid-walk abort path does. */
20859
+ _neutralizeRoot(dirty);
19938
20860
  throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
19939
20861
  }
19940
20862
  }
20863
+ /* Pre-flight the root through _isClobbered. The iterator-driven
20864
+ removal path can not detach a parent-less root: _forceRemove
20865
+ falls through to Element.prototype.remove(), which per spec
20866
+ is a no-op on a node with no parent. A clobbered root would
20867
+ then survive the main loop with its attributes uninspected,
20868
+ because _sanitizeAttributes early-returns on _isClobbered. The
20869
+ result would be an attacker-controlled form, complete with any
20870
+ event-handler attributes the caller passed in, handed back to
20871
+ the application unsanitized. Refuse to sanitize such a root
20872
+ the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
20873
+ if (_isClobbered(dirty)) {
20874
+ /* Fail closed on a live clobbered root before throwing.
20875
+ _neutralizeRoot's reads are clobber-safe (cached getters); the
20876
+ form's non-clobbered descendants, e.g. an armed <img>, are scrubbed. */
20877
+ _neutralizeRoot(dirty);
20878
+ throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
20879
+ }
19941
20880
  /* Sanitize attached shadow roots before the main iterator runs.
19942
- The iterator does not descend into shadow trees. */
19943
- _sanitizeAttachedShadowRoots2(dirty);
20881
+ The iterator does not descend into shadow trees. Same fail-closed
20882
+ barrier as the main walk (campaign-3 F2): a custom-element reaction
20883
+ inside a shadow root could abort this pre-pass before the walk runs,
20884
+ which would otherwise leave the entire live tree unsanitized. */
20885
+ try {
20886
+ _sanitizeAttachedShadowRoots(dirty);
20887
+ } catch (error) {
20888
+ _neutralizeRoot(dirty);
20889
+ throw error;
20890
+ }
19944
20891
  } else if (_isNode(dirty)) {
19945
20892
  /* If dirty is a DOM element, append to an empty document to avoid
19946
20893
  elements being stripped by the parser */
@@ -19957,14 +20904,16 @@
19957
20904
  }
19958
20905
  /* Clonable shadow roots are deep-cloned by importNode(); sanitize
19959
20906
  them before the main iterator runs, since the iterator does not
19960
- descend into shadow trees. */
19961
- _sanitizeAttachedShadowRoots2(importedNode);
20907
+ descend into shadow trees. The walk routes every read through a
20908
+ cached prototype getter so clobbering descendants on a form root
20909
+ cannot hide a shadow host from this pass. */
20910
+ _sanitizeAttachedShadowRoots(importedNode);
19962
20911
  } else {
19963
20912
  /* Exit directly if we have nothing to do */
19964
20913
  if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
19965
20914
  // eslint-disable-next-line unicorn/prefer-includes
19966
20915
  dirty.indexOf('<') === -1) {
19967
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
20916
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
19968
20917
  }
19969
20918
  /* Initialize the document to work on */
19970
20919
  body = _initDocument(dirty);
@@ -19978,29 +20927,68 @@
19978
20927
  _forceRemove(body.firstChild);
19979
20928
  }
19980
20929
  /* Get node iterator */
19981
- const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
19982
- /* Now start iterating over the created document */
19983
- while (currentNode = nodeIterator.nextNode()) {
19984
- /* Sanitize tags and elements */
19985
- _sanitizeElements(currentNode);
19986
- /* Check attributes next */
19987
- _sanitizeAttributes(currentNode);
19988
- /* Shadow DOM detected, sanitize it */
19989
- if (currentNode.content instanceof DocumentFragment) {
19990
- _sanitizeShadowDOM2(currentNode.content);
20930
+ const walkRoot = inPlace ? dirty : body;
20931
+ const nodeIterator = _createNodeIterator(walkRoot);
20932
+ /* Now start iterating over the created document.
20933
+ The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
20934
+ engine/custom-element mutation can detach a node mid-walk so
20935
+ `_forceRemove`'s parentless guard throws, aborting the loop. Without the
20936
+ barrier the caller's in-place tree would be left half-sanitized with the
20937
+ unvisited tail still armed. On any throw we fail closed — strip the
20938
+ in-place root bare then rethrow so the existing throw contract is
20939
+ preserved. (String/DOM-copy paths never return the partial body, so the
20940
+ propagating throw is already fail-closed there.) */
20941
+ try {
20942
+ while (currentNode = nodeIterator.nextNode()) {
20943
+ /* Sanitize tags and elements */
20944
+ _sanitizeElements(currentNode, walkRoot);
20945
+ /* Check attributes next */
20946
+ _sanitizeAttributes(currentNode);
20947
+ /* Shadow DOM detected, sanitize it.
20948
+ Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
20949
+ instead of instanceof, so foreign-realm <template>.content is
20950
+ walked correctly. */
20951
+ if (_isDocumentFragment(currentNode.content)) {
20952
+ _sanitizeShadowDOM2(currentNode.content);
20953
+ }
19991
20954
  }
20955
+ } catch (error) {
20956
+ if (inPlace) {
20957
+ _neutralizeRoot(dirty);
20958
+ /* Nodes _forceRemove'd earlier in the aborted walk are already
20959
+ detached from the root, so _neutralizeRoot's subtree pass does not
20960
+ reach them. Defuse them too, mirroring the success-path loop below. */
20961
+ arrayForEach(DOMPurify.removed, entry => {
20962
+ if (entry.element) {
20963
+ _neutralizeSubtree(entry.element);
20964
+ }
20965
+ });
20966
+ }
20967
+ throw error;
19992
20968
  }
19993
20969
  /* If we sanitized `dirty` in-place, return it. */
19994
- if (IN_PLACE) {
20970
+ if (inPlace) {
20971
+ /* Fail-closed completion of the audit-5 F1 fix: every node removed from
20972
+ the caller's live tree is detached but may still hold a queued
20973
+ resource-event handler that fires in page scope after we return. The
20974
+ move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
20975
+ non-allow-listed attributes off every other removed subtree (clobber,
20976
+ mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
20977
+ cancelled before any event can fire. Runs synchronously, pre-return. */
20978
+ arrayForEach(DOMPurify.removed, entry => {
20979
+ if (entry.element) {
20980
+ _neutralizeSubtree(entry.element);
20981
+ }
20982
+ });
19995
20983
  if (SAFE_FOR_TEMPLATES) {
19996
- _scrubTemplateExpressions(dirty);
20984
+ _scrubTemplateExpressions2(dirty);
19997
20985
  }
19998
20986
  return dirty;
19999
20987
  }
20000
20988
  /* Return sanitized string or DOM */
20001
20989
  if (RETURN_DOM) {
20002
20990
  if (SAFE_FOR_TEMPLATES) {
20003
- _scrubTemplateExpressions(body);
20991
+ _scrubTemplateExpressions2(body);
20004
20992
  }
20005
20993
  if (RETURN_DOM_FRAGMENT) {
20006
20994
  returnNode = createDocumentFragment.call(body.ownerDocument);
@@ -20030,20 +21018,28 @@
20030
21018
  }
20031
21019
  /* Sanitize final string template-safe */
20032
21020
  if (SAFE_FOR_TEMPLATES) {
20033
- arrayForEach([MUSTACHE_EXPR$1, ERB_EXPR$1, TMPLIT_EXPR$1], expr => {
20034
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
20035
- });
21021
+ serializedHTML = _stripTemplateExpressions(serializedHTML);
20036
21022
  }
20037
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
21023
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
20038
21024
  };
20039
21025
  DOMPurify.setConfig = function () {
20040
21026
  let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20041
21027
  _parseConfig(cfg);
20042
21028
  SET_CONFIG = true;
21029
+ SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
21030
+ SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
20043
21031
  };
20044
21032
  DOMPurify.clearConfig = function () {
20045
21033
  CONFIG = null;
20046
21034
  SET_CONFIG = false;
21035
+ SET_CONFIG_ALLOWED_TAGS = null;
21036
+ SET_CONFIG_ALLOWED_ATTR = null;
21037
+ // Drop any caller-supplied Trusted Types policy so it cannot poison later
21038
+ // `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
21039
+ // never recreated — Trusted Types throws on duplicate names) is restored by
21040
+ // the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
21041
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
21042
+ emptyHTML = '';
20047
21043
  };
20048
21044
  DOMPurify.isValidAttribute = function (tag, attr, value) {
20049
21045
  /* Initialize shared config vars if necessary. */
@@ -20058,9 +21054,19 @@
20058
21054
  if (typeof hookFunction !== 'function') {
20059
21055
  return;
20060
21056
  }
21057
+ /* Reject unknown entry points. Without this, a non-hook key (e.g.
21058
+ * '__proto__') indexes off the prototype chain rather than a real
21059
+ * hook array, and arrayPush then writes to Object.prototype. Guard
21060
+ * with an own-property check against the known hook names. */
21061
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
21062
+ return;
21063
+ }
20061
21064
  arrayPush(hooks[entryPoint], hookFunction);
20062
21065
  };
20063
21066
  DOMPurify.removeHook = function (entryPoint, hookFunction) {
21067
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
21068
+ return undefined;
21069
+ }
20064
21070
  if (hookFunction !== undefined) {
20065
21071
  const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
20066
21072
  return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
@@ -20068,6 +21074,9 @@
20068
21074
  return arrayPop(hooks[entryPoint]);
20069
21075
  };
20070
21076
  DOMPurify.removeHooks = function (entryPoint) {
21077
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
21078
+ return;
21079
+ }
20071
21080
  hooks[entryPoint] = [];
20072
21081
  };
20073
21082
  DOMPurify.removeAllHooks = function () {
@@ -22068,7 +23077,7 @@
22068
23077
  append(SugarElement.fromDom(pre1), [
22069
23078
  SugarElement.fromTag('br', doc),
22070
23079
  SugarElement.fromTag('br', doc),
22071
- ...children$1(sPre2)
23080
+ ...children$2(sPre2)
22072
23081
  ]);
22073
23082
  };
22074
23083
  if (!rng.collapsed) {
@@ -22215,10 +23224,12 @@
22215
23224
  const wrapName = format.inline || format.block;
22216
23225
  const wrapElm = createWrapElement(wrapName);
22217
23226
  const isMatchingWrappingBlock = (node) => isWrappingBlockFormat(format) && matchNode$1(ed, node, name, vars);
23227
+ const canRenameChildBlocks = (node) => forall(node.childNodes, (child) => !isTextBlock$2(ed.schema, child) || isValid(ed, wrapName, child.nodeName.toLowerCase()));
22218
23228
  const canRenameBlock = (node, parentName, isEditableDescendant) => {
22219
23229
  const isValidBlockFormatForNode = isNonWrappingBlockFormat(format) &&
22220
23230
  isTextBlock$2(ed.schema, node) &&
22221
- isValid(ed, parentName, wrapName);
23231
+ isValid(ed, parentName, wrapName) &&
23232
+ canRenameChildBlocks(node);
22222
23233
  return isEditableDescendant && isValidBlockFormatForNode;
22223
23234
  };
22224
23235
  const canWrapNode = (node, parentName, isEditableDescendant, isWrappableNoneditableElm) => {
@@ -22369,12 +23380,38 @@
22369
23380
  }
22370
23381
  });
22371
23382
  };
22372
- // TODO: TINY-9142: Remove this to make nested noneditable formatting work
22373
23383
  const targetNode = isNode(node) ? node : selection.getNode();
22374
23384
  if (dom.getContentEditable(targetNode) === 'false' && !isWrappableNoneditable(ed, targetNode)) {
22375
23385
  // node variable is used by other functions above in the same scope so need to set it here
22376
23386
  node = targetNode;
22377
23387
  applyNodeStyle(formatList, node);
23388
+ if (hasEditableDescendants(dom, node)) {
23389
+ each$e(getEditableDescendants(dom, node), (island) => {
23390
+ const rng = dom.createRng();
23391
+ rng.selectNodeContents(island);
23392
+ applyRngStyle(dom, rng, true);
23393
+ });
23394
+ return;
23395
+ }
23396
+ if (isBlockFormat(format) && !dom.isBlock(node)) {
23397
+ const parentBlock = dom.getParent(node, dom.isBlock);
23398
+ if (dom.isEditable(parentBlock)) {
23399
+ const wrapperElementName = format.block;
23400
+ if (parentBlock.nodeName.toLowerCase() === wrapperElementName.toLowerCase()) {
23401
+ setElementFormat(ed, parentBlock, format, vars, node);
23402
+ }
23403
+ else if (!isWrappingBlockFormat(format)) {
23404
+ const elm = dom.rename(parentBlock, wrapperElementName);
23405
+ setElementFormat(ed, elm, format, vars, node);
23406
+ }
23407
+ }
23408
+ }
23409
+ else {
23410
+ const selectorFormats = filter$5(formatList, isSelectorFormat);
23411
+ Optional.from(dom.getParent(node, (candidate) => exists(selectorFormats, (fmt) => dom.is(candidate, fmt.selector))))
23412
+ .filter(dom.isEditable)
23413
+ .each((parent) => applyNodeStyle(formatList, parent));
23414
+ }
22378
23415
  fireFormatApply(ed, name, node, vars);
22379
23416
  return;
22380
23417
  }
@@ -22408,7 +23445,7 @@
22408
23445
  applyCaretFormat(ed, name, vars);
22409
23446
  }
22410
23447
  getExpandedListItemFormat(ed.formatter, name).each((liFmt) => {
22411
- const list = getFullySelectedListItems(ed.selection);
23448
+ const list = getFullySelectedListItems(ed);
22412
23449
  each$e(list, (li) => applyStyles(dom, li, liFmt, vars));
22413
23450
  });
22414
23451
  }
@@ -25454,7 +26491,8 @@
25454
26491
  }, (href) => {
25455
26492
  e.preventDefault();
25456
26493
  if (/^#/.test(href)) {
25457
- const targetEl = editor.dom.select(`${href},[name="${removeLeading(href, '#')}"]`);
26494
+ const id = removeLeading(href, '#');
26495
+ const targetEl = editor.dom.select(`[id="${id}"],[name="${id}"]`);
25458
26496
  if (targetEl.length) {
25459
26497
  editor.selection.scrollIntoView(targetEl[0], true);
25460
26498
  }
@@ -26164,7 +27202,7 @@
26164
27202
  preview: 'font-family font-size'
26165
27203
  },
26166
27204
  {
26167
- selector: '.mce-preview-object,[data-ephox-embed-iri]',
27205
+ selector: '.mce-preview-object,[data-ephox-embed-iri],.tiny-pageembed',
26168
27206
  ceFalseOverride: true,
26169
27207
  styles: {
26170
27208
  float: 'left'
@@ -26216,7 +27254,7 @@
26216
27254
  preview: 'font-family font-size'
26217
27255
  },
26218
27256
  {
26219
- selector: '.mce-preview-object',
27257
+ selector: '.mce-preview-object,.tiny-pageembed',
26220
27258
  ceFalseOverride: true,
26221
27259
  styles: {
26222
27260
  display: 'table', // Needs to be `table` to properly render while editing
@@ -26280,7 +27318,7 @@
26280
27318
  preview: 'font-family font-size'
26281
27319
  },
26282
27320
  {
26283
- selector: '.mce-preview-object,[data-ephox-embed-iri]',
27321
+ selector: '.mce-preview-object,[data-ephox-embed-iri],.tiny-pageembed',
26284
27322
  ceFalseOverride: true,
26285
27323
  styles: {
26286
27324
  float: 'right'
@@ -26967,8 +28005,8 @@
26967
28005
  isFirstTypedCharacter.set(true);
26968
28006
  return;
26969
28007
  }
26970
- const hasOnlyMetaOrCtrlModifier = Env.os.isMacOS() ? e.metaKey : e.ctrlKey && !e.altKey;
26971
- if (hasOnlyMetaOrCtrlModifier) {
28008
+ const hasMetaOrCtrlModifier = Env.os.isMacOS() ? e.metaKey : e.ctrlKey && !e.altKey;
28009
+ if (hasMetaOrCtrlModifier && (e.key === 'Backspace' || e.key === 'Delete')) {
26972
28010
  undoManager.beforeChange();
26973
28011
  }
26974
28012
  });
@@ -27533,7 +28571,7 @@
27533
28571
  const isIndented = (entry) => entry.depth > 0;
27534
28572
  const isSelected = (entry) => entry.isSelected;
27535
28573
  const cloneItemContent = (li) => {
27536
- const children = children$1(li);
28574
+ const children = children$2(li);
27537
28575
  const content = hasLastChildList(li) ? children.slice(0, -1) : children;
27538
28576
  return map$3(content, deep);
27539
28577
  };
@@ -27731,7 +28769,7 @@
27731
28769
  return currentItemEntry.toArray().concat(childListEntries);
27732
28770
  };
27733
28771
  const parseItem = (depth, itemSelection, selectionState, item) => firstChild(item).filter(isList).fold(() => parseSingleItem(depth, itemSelection, selectionState, item), (list) => {
27734
- const parsedSiblings = foldl(children$1(item), (acc, liChild, i) => {
28772
+ const parsedSiblings = foldl(children$2(item), (acc, liChild, i) => {
27735
28773
  if (i === 0) {
27736
28774
  return acc;
27737
28775
  }
@@ -27754,7 +28792,7 @@
27754
28792
  }, []);
27755
28793
  return parseList(depth, itemSelection, selectionState, list).concat(parsedSiblings);
27756
28794
  });
27757
- const parseList = (depth, itemSelection, selectionState, list) => bind$3(children$1(list), (element) => {
28795
+ const parseList = (depth, itemSelection, selectionState, list) => bind$3(children$2(list), (element) => {
27758
28796
  const parser = isList(element) ? parseList : parseItem;
27759
28797
  const newDepth = depth + 1;
27760
28798
  return parser(newDepth, itemSelection, selectionState, element);
@@ -28417,7 +29455,7 @@
28417
29455
  const rng = normalizeRange(editor.selection.getRng());
28418
29456
  const nextCaretContainer = findNextCaretContainer(editor, rng, isForward, root);
28419
29457
  const otherLi = dom.getParent(nextCaretContainer, 'LI', root);
28420
- if (nextCaretContainer && otherLi) {
29458
+ if (nextCaretContainer && otherLi && (isForward || !dom.isChildOf(nextCaretContainer, block))) {
28421
29459
  const findValidElement = (element) => contains$2(['td', 'th', 'caption'], name(element));
28422
29460
  const findRoot = (node) => node.dom === root;
28423
29461
  const otherLiCell = closest$5(SugarElement.fromDom(otherLi), findValidElement, findRoot);
@@ -28515,7 +29553,7 @@
28515
29553
  const read$1 = (schema, rootNode, forward, rng) => rng.collapsed ? readFromRange(schema, rootNode, forward, rng) : Optional.none();
28516
29554
 
28517
29555
  const getChildrenUntilBlockBoundary = (block, schema) => {
28518
- const children = children$1(block);
29556
+ const children = children$2(block);
28519
29557
  return findIndex$2(children, (el) => schema.isBlock(name(el))).fold(constant(children), (index) => children.slice(0, index));
28520
29558
  };
28521
29559
  const extractChildren = (block, schema) => {
@@ -29910,7 +30948,11 @@
29910
30948
  const canIndent = (editor) => !editor.mode.isReadOnly() && canIndent$1(editor);
29911
30949
  const isListComponent = (el) => isList$1(el) || isListItem$2(el);
29912
30950
  const parentIsListComponent = (el) => parent(el).exists(isListComponent);
29913
- const getBlocksToIndent = (editor) => filter$5(fromDom$1(editor.selection.getSelectedBlocks()), (el) => !isListComponent(el) && !parentIsListComponent(el) && isEditable(el));
30951
+ const getBlocksToIndent = (editor) => {
30952
+ const selectedCells = getCellsFromEditor(editor);
30953
+ return selectedCells.length === 0 ?
30954
+ filter$5(fromDom$1(editor.selection.getSelectedBlocks()), (el) => !isListComponent(el) && !parentIsListComponent(el) && isEditable(el)) : selectedCells;
30955
+ };
29914
30956
  const handle = (editor, command) => {
29915
30957
  if (editor.mode.isReadOnly()) {
29916
30958
  return;
@@ -30585,7 +31627,7 @@
30585
31627
  return filterFirstLayer(scope, selector, always);
30586
31628
  };
30587
31629
  const filterFirstLayer = (scope, selector, predicate) => {
30588
- return bind$3(children$1(scope), (x) => {
31630
+ return bind$3(children$2(scope), (x) => {
30589
31631
  if (is$2(x, selector)) {
30590
31632
  return predicate(x) ? [x] : [];
30591
31633
  }
@@ -30795,7 +31837,7 @@
30795
31837
  nextSibling: nextSibling
30796
31838
  }),
30797
31839
  property: constant({
30798
- children: children$1,
31840
+ children: children$2,
30799
31841
  name: name,
30800
31842
  parent: parent,
30801
31843
  document,
@@ -30885,10 +31927,14 @@
30885
31927
  };
30886
31928
  const isInDragStartEvent = checkEvent(0 /* Event.Dragstart */);
30887
31929
 
30888
- const createEmptyFileList = () => Object.freeze({
30889
- length: 0,
30890
- item: (_) => null
30891
- });
31930
+ const createEmptyFileList = () => {
31931
+ const empty = [];
31932
+ return Object.freeze({
31933
+ length: 0,
31934
+ item: (_) => null,
31935
+ [Symbol.iterator]: () => empty[Symbol.iterator]()
31936
+ });
31937
+ };
30892
31938
 
30893
31939
  const modeId = generate('mode');
30894
31940
  const getMode = (transfer) => {
@@ -33902,15 +34948,20 @@
33902
34948
  blobCache.add(blobInfo);
33903
34949
  return blobInfo;
33904
34950
  };
33905
- const pasteImage = (editor, imageItem) => {
33906
- parseDataUri(imageItem.uri).each(({ data, type, base64Encoded }) => {
34951
+ const pasteImage = async (editor, imageItem) => {
34952
+ return parseDataUri(imageItem.uri).fold(() => Promise.resolve(), ({ data, type, base64Encoded }) => {
33907
34953
  const base64 = base64Encoded ? data : btoa(data);
33908
34954
  const file = imageItem.file;
33909
34955
  // TODO: Move the bulk of the cache logic to EditorUpload
33910
34956
  const blobCache = editor.editorUpload.blobCache;
33911
34957
  const existingBlobInfo = blobCache.getByData(base64, type);
33912
34958
  const blobInfo = existingBlobInfo ?? createBlobInfo(editor, blobCache, file, base64);
33913
- pasteHtml(editor, `<img src="${blobInfo.blobUri()}">`, false, true);
34959
+ const imgUrl = blobInfo.blobUri();
34960
+ return getImageSize(imgUrl).then(({ width, height }) => {
34961
+ pasteHtml(editor, `<img width="${width}" height="${height}" src="${imgUrl}">`, false, true);
34962
+ }).catch(() => {
34963
+ pasteHtml(editor, `<img src="${imgUrl}">`, false, true);
34964
+ });
33914
34965
  });
33915
34966
  };
33916
34967
  const isClipboardEvent = (event) => event.type === 'paste';
@@ -33941,13 +34992,13 @@
33941
34992
  if (images.length > 0) {
33942
34993
  e.preventDefault();
33943
34994
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
33944
- readFilesAsDataUris(images).then((fileResults) => {
34995
+ readFilesAsDataUris(images).then(async (fileResults) => {
33945
34996
  if (rng) {
33946
34997
  editor.selection.setRng(rng);
33947
34998
  }
33948
- each$e(fileResults, (result) => {
33949
- pasteImage(editor, result);
33950
- });
34999
+ for (const result of fileResults) {
35000
+ await pasteImage(editor, result);
35001
+ }
33951
35002
  });
33952
35003
  return true;
33953
35004
  }
@@ -36095,6 +37146,7 @@
36095
37146
  const browser = Env.browser;
36096
37147
  const isGecko = browser.isFirefox();
36097
37148
  const isWebKit = browser.isChromium() || browser.isSafari();
37149
+ const isSafari = browser.isSafari();
36098
37150
  const isiOS = Env.deviceType.isiPhone() || Env.deviceType.isiPad();
36099
37151
  const isMac = Env.os.isMacOS() || Env.os.isiOS();
36100
37152
  /**
@@ -36701,6 +37753,51 @@
36701
37753
  }
36702
37754
  });
36703
37755
  };
37756
+ /**
37757
+ * this is needed to manage the difference between
37758
+ * ```
37759
+ * <li><span class="fake">a</span><div>b</div></li>
37760
+ * ```
37761
+ * and
37762
+ * ```
37763
+ * <li><span class="fake">a</span> <div>b</div></li>
37764
+ * ```
37765
+ * since if the indentation of the HTML has a new line it creates a fake child in the `li` that is an empty text
37766
+ * it's check it trying to get the rects and if it can't it means that it's the false unwanted new line
37767
+ **/
37768
+ const isValidSibling = (el) => getClientRects([el.dom]).length > 0;
37769
+ const firstBlockChildOrNewLine = (target) => child(target, (child) => isBr$6(child) || isElement$8(child) && get$8(child, 'display') === 'block');
37770
+ const clickAfterEl = (clientX, clientY, el) => get$c(getClientRects([el.dom]), 0).exists((rect) => clientX >= rect.right && clientY >= rect.top && clientY <= rect.bottom);
37771
+ const selectPos = (editor, e, pos) => {
37772
+ e.preventDefault();
37773
+ editor.focus();
37774
+ editor.selection.setRng(pos.toRange());
37775
+ };
37776
+ /**
37777
+ * In Chrome in a `LI` that contains a block element and where the first child is an inline element
37778
+ * clicking on the right side of the first child the carret goes at the start of the element instead that in the end of it
37779
+ * issue: https://issues.chromium.org/issues/40767343
37780
+ **/
37781
+ const fixInLISelection = () => {
37782
+ editor.on('mousedown', (e) => {
37783
+ const target = SugarElement.fromDom(e.target);
37784
+ if (isListItem$2(target)) {
37785
+ firstBlockChildOrNewLine(target).fold(() => {
37786
+ lastChild(target).each((lastChild) => {
37787
+ if (clickAfterEl(e.clientX, e.clientY, lastChild)) {
37788
+ lastPositionIn(target.dom).each((pos) => selectPos(editor, e, pos));
37789
+ }
37790
+ });
37791
+ }, (firstBlock) => {
37792
+ findLast(prevSiblings(firstBlock), isValidSibling).each((lastInlineBeforeBlock) => {
37793
+ if (clickAfterEl(e.clientX, e.clientY, lastInlineBeforeBlock)) {
37794
+ prevPosition(target.dom, CaretPosition(firstBlock.dom, 0)).each((pos) => selectPos(editor, e, pos));
37795
+ }
37796
+ });
37797
+ });
37798
+ }
37799
+ });
37800
+ };
36704
37801
  // No-op since Mozilla seems to have fixed the caret repaint issues
36705
37802
  const refreshContentEditable = noop;
36706
37803
  const isHidden = () => {
@@ -36747,6 +37844,9 @@
36747
37844
  blockFormSubmitInsideEditor();
36748
37845
  disableBackspaceIntoATable();
36749
37846
  removeAppleInterchangeBrs();
37847
+ if (!isSafari) {
37848
+ fixInLISelection();
37849
+ }
36750
37850
  // touchClickEvent();
36751
37851
  // iOS
36752
37852
  if (isiOS) {
@@ -40843,6 +41943,21 @@
40843
41943
  hasEditableRoot() {
40844
41944
  return hasEditableRoot(this);
40845
41945
  }
41946
+ /**
41947
+ * Announces a message to screen readers via the page-wide aria-live region, without shifting focus.
41948
+ * Delegates to {@link tinymce.dom.AriaAnnouncer#announce}.
41949
+ *
41950
+ * @method announce
41951
+ * @param {String} message The message to announce to screen readers.
41952
+ * @param {Object} options Optional settings.
41953
+ * @param {Boolean} options.assertive If true, uses aria-live="assertive" (role="alert") instead of polite.
41954
+ * @example
41955
+ * tinymce.activeEditor.announce('Bold on');
41956
+ * tinymce.activeEditor.announce('Error occurred', { assertive: true });
41957
+ */
41958
+ announce(message, options) {
41959
+ AriaAnnouncer.announce(message, options);
41960
+ }
40846
41961
  /**
40847
41962
  * Removes the editor from the dom and tinymce collection.
40848
41963
  *
@@ -40967,14 +42082,14 @@
40967
42082
  * @property minorVersion
40968
42083
  * @type String
40969
42084
  */
40970
- minorVersion: '6.0',
42085
+ minorVersion: '8.2',
40971
42086
  /**
40972
42087
  * Release date of TinyMCE build.
40973
42088
  *
40974
42089
  * @property releaseDate
40975
42090
  * @type String
40976
42091
  */
40977
- releaseDate: '2026-06-03',
42092
+ releaseDate: '2026-07-27',
40978
42093
  /**
40979
42094
  * Collection of language pack data.
40980
42095
  *
@@ -41832,6 +42947,7 @@
41832
42947
  ControlSelection,
41833
42948
  BookmarkManager,
41834
42949
  Selection: EditorSelection,
42950
+ AriaAnnouncer,
41835
42951
  Event: EventUtils.Event
41836
42952
  },
41837
42953
  html: {
@@ -41890,7 +43006,7 @@
41890
43006
  }
41891
43007
  catch {
41892
43008
  // It will thrown an error when running this module
41893
- // within webpack where the module.exports object is sealed
43009
+ // within rspack where the module.exports object is sealed
41894
43010
  }
41895
43011
  }
41896
43012
  };