@meridianlabs/log-viewer 0.3.282 → 0.3.283

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 (197) hide show
  1. package/lib/{AnsiDisplayRich-302CIkEj.js → AnsiDisplayRich-Dpc1-E4A.js} +31 -34
  2. package/lib/AnsiDisplayRich-Dpc1-E4A.js.map +1 -0
  3. package/lib/{AsciinemaPlayerImpl-BG5NPs0z.js → AsciinemaPlayerImpl-CTd51CWg.js} +13 -13
  4. package/lib/{AsciinemaPlayerImpl-BG5NPs0z.js.map → AsciinemaPlayerImpl-CTd51CWg.js.map} +1 -1
  5. package/lib/ToolButton-BGW3G4cu.js +374 -0
  6. package/lib/ToolButton-BGW3G4cu.js.map +1 -0
  7. package/lib/e2e/csp/csp.spec.d.ts +2 -0
  8. package/lib/e2e/csp/csp.spec.d.ts.map +1 -0
  9. package/lib/e2e/csp/cspLogs.d.ts +10 -0
  10. package/lib/e2e/csp/cspLogs.d.ts.map +1 -0
  11. package/lib/e2e/csp/media.d.ts +3 -0
  12. package/lib/e2e/csp/media.d.ts.map +1 -0
  13. package/lib/e2e/expandable-panel-nested-toggles.spec.d.ts +2 -0
  14. package/lib/e2e/expandable-panel-nested-toggles.spec.d.ts.map +1 -0
  15. package/lib/e2e/fixtures/app.d.ts +12 -1
  16. package/lib/e2e/fixtures/app.d.ts.map +1 -1
  17. package/lib/e2e/message-selection.spec.d.ts +2 -0
  18. package/lib/e2e/message-selection.spec.d.ts.map +1 -0
  19. package/lib/index.js +35243 -34924
  20. package/lib/index.js.map +1 -1
  21. package/lib/{markdownPipeline-C_z-iU9a.js → markdownPipeline-bhdCQvtQ.js} +280 -306
  22. package/lib/markdownPipeline-bhdCQvtQ.js.map +1 -0
  23. package/lib/{prismHighlighter-D-PZtkPX.js → prismHighlighter-7qrXrStR.js} +1 -2
  24. package/lib/{prismHighlighter-D-PZtkPX.js.map → prismHighlighter-7qrXrStR.js.map} +1 -1
  25. package/lib/src/app/App.d.ts.map +1 -1
  26. package/lib/src/app/AppProviders.d.ts +10 -0
  27. package/lib/src/app/AppProviders.d.ts.map +1 -0
  28. package/lib/src/app/log-list/LogsPanel.d.ts.map +1 -1
  29. package/lib/src/app/log-list/ViewerOptionsButton.d.ts +1 -0
  30. package/lib/src/app/log-list/ViewerOptionsButton.d.ts.map +1 -1
  31. package/lib/src/app/log-list/ViewerOptionsPopover.d.ts +1 -0
  32. package/lib/src/app/log-list/ViewerOptionsPopover.d.ts.map +1 -1
  33. package/lib/src/app/log-list/grid/columns/hooks.d.ts.map +1 -1
  34. package/lib/src/app/log-view/error/TaskErrorPanel.d.ts.map +1 -1
  35. package/lib/src/app/log-view/tabs/InfoTab.d.ts +1 -1
  36. package/lib/src/app/log-view/tabs/JsonTab.d.ts.map +1 -1
  37. package/lib/src/app/log-view/tabs/ModelsTab.d.ts +1 -1
  38. package/lib/src/app/log-view/tabs/SamplesTab.d.ts.map +1 -1
  39. package/lib/src/app/log-view/tabs/timeline/HistoryList.d.ts.map +1 -1
  40. package/lib/src/app/log-view/tabs/timeline/TimelineChart.d.ts.map +1 -1
  41. package/lib/src/app/log-view/tabs/timeline/TimelineTab.d.ts +1 -1
  42. package/lib/src/app/log-view/tabs/timeline/TimelineTab.d.ts.map +1 -1
  43. package/lib/src/app/log-view/title-view/CollapsedTitleBar.d.ts.map +1 -1
  44. package/lib/src/app/log-view/title-view/EditAnnotationsDialog.d.ts +22 -0
  45. package/lib/src/app/log-view/title-view/EditAnnotationsDialog.d.ts.map +1 -0
  46. package/lib/src/app/log-view/title-view/EditMetadataDialog.d.ts +3 -3
  47. package/lib/src/app/log-view/title-view/EditMetadataDialog.d.ts.map +1 -1
  48. package/lib/src/app/log-view/title-view/EditTagsDialog.d.ts.map +1 -1
  49. package/lib/src/app/log-view/title-view/RunningStatusPanel.d.ts.map +1 -1
  50. package/lib/src/app/log-view/title-view/ScoreGrid.d.ts.map +1 -1
  51. package/lib/src/app/log-view/title-view/StatusPanel.d.ts +2 -1
  52. package/lib/src/app/log-view/title-view/StatusPanel.d.ts.map +1 -1
  53. package/lib/src/app/log-view/title-view/renderEditDialog.d.ts +12 -0
  54. package/lib/src/app/log-view/title-view/renderEditDialog.d.ts.map +1 -0
  55. package/lib/src/app/navbar/ApplicationNavbar.d.ts +3 -0
  56. package/lib/src/app/navbar/ApplicationNavbar.d.ts.map +1 -1
  57. package/lib/src/app/navbar/Navbar.d.ts.map +1 -1
  58. package/lib/src/app/navbar/NavbarButton.d.ts +2 -1
  59. package/lib/src/app/navbar/NavbarButton.d.ts.map +1 -1
  60. package/lib/src/app/navbar/ViewSegmentedControl.d.ts.map +1 -1
  61. package/lib/src/app/plan/DetailStep.d.ts +2 -1
  62. package/lib/src/app/plan/DetailStep.d.ts.map +1 -1
  63. package/lib/src/app/plan/ScorerDetailView.d.ts.map +1 -1
  64. package/lib/src/app/plan/SolverDetailView.d.ts.map +1 -1
  65. package/lib/src/app/routing/url.d.ts +8 -3
  66. package/lib/src/app/routing/url.d.ts.map +1 -1
  67. package/lib/src/app/samples/InlineSampleDisplay.d.ts.map +1 -1
  68. package/lib/src/app/samples/SampleDisplay.d.ts.map +1 -1
  69. package/lib/src/app/samples/SampleRetriedErrors.d.ts.map +1 -1
  70. package/lib/src/app/samples/SamplesTools.d.ts.map +1 -1
  71. package/lib/src/app/samples/error/SampleErrorView.d.ts.map +1 -1
  72. package/lib/src/app/samples/event/SampleEventView.d.ts.map +1 -1
  73. package/lib/src/app/samples/header-v2/ScorePanel.d.ts.map +1 -1
  74. package/lib/src/app/samples/list/samplesView.d.ts +1 -1
  75. package/lib/src/app/samples/print/SamplePrintView.d.ts +3 -1
  76. package/lib/src/app/samples/print/SamplePrintView.d.ts.map +1 -1
  77. package/lib/src/app/samples/retry-display/RetryAttemptCard.d.ts.map +1 -1
  78. package/lib/src/app/samples/retry-display/RetryTerminalAnchor.d.ts.map +1 -1
  79. package/lib/src/app/samples/sample-tools/SelectScorer.d.ts.map +1 -1
  80. package/lib/src/app/samples/sample-tools/sample-filter/SampleFilter.d.ts.map +1 -1
  81. package/lib/src/app/samples/scans/ScansSidebarPanel.d.ts.map +1 -1
  82. package/lib/src/app/samples/status/status.d.ts.map +1 -1
  83. package/lib/src/app/samples/transcript/TranscriptPanel.d.ts +4 -2
  84. package/lib/src/app/samples/transcript/TranscriptPanel.d.ts.map +1 -1
  85. package/lib/src/app/samples/transcript/search/SearchScoutUnavailable.d.ts.map +1 -1
  86. package/lib/src/app/samples/useEvidenceSelection.d.ts +56 -0
  87. package/lib/src/app/samples/useEvidenceSelection.d.ts.map +1 -0
  88. package/lib/src/app/samples-panel/SamplesPanel.d.ts.map +1 -1
  89. package/lib/src/app/server/useUserInfo.d.ts +12 -0
  90. package/lib/src/app/server/useUserInfo.d.ts.map +1 -0
  91. package/lib/src/app/shared/ColumnSelectorPopover.d.ts.map +1 -1
  92. package/lib/src/app/shared/contentTrust.d.ts +1 -5
  93. package/lib/src/app/shared/contentTrust.d.ts.map +1 -1
  94. package/lib/src/app/shared/data-grid/DataGrid.d.ts +1 -2
  95. package/lib/src/app/shared/data-grid/DataGrid.d.ts.map +1 -1
  96. package/lib/src/app/types.d.ts +2 -2
  97. package/lib/src/app/types.d.ts.map +1 -1
  98. package/lib/src/app_config/LogLocationGate.d.ts +6 -5
  99. package/lib/src/app_config/LogLocationGate.d.ts.map +1 -1
  100. package/lib/src/app_config/appConfig.d.ts +1 -2
  101. package/lib/src/app_config/appConfig.d.ts.map +1 -1
  102. package/lib/src/app_config/logLocationTrust.d.ts +5 -4
  103. package/lib/src/app_config/logLocationTrust.d.ts.map +1 -1
  104. package/lib/src/app_config/resolveBackend.d.ts +3 -3
  105. package/lib/src/app_config/resolveBackend.d.ts.map +1 -1
  106. package/lib/src/client/api/client-api.d.ts.map +1 -1
  107. package/lib/src/client/api/shared/api-shared.d.ts.map +1 -1
  108. package/lib/src/client/api/testClientApi.d.ts +2 -1
  109. package/lib/src/client/api/testClientApi.d.ts.map +1 -1
  110. package/lib/src/client/api/types.d.ts +2 -5
  111. package/lib/src/client/api/types.d.ts.map +1 -1
  112. package/lib/src/client/api/vscode/testExtensionHost.d.ts +28 -0
  113. package/lib/src/client/api/vscode/testExtensionHost.d.ts.map +1 -0
  114. package/lib/src/client/database/schema.d.ts.map +1 -1
  115. package/lib/src/client/json-parse.worker.d.ts +2 -0
  116. package/lib/src/client/json-parse.worker.d.ts.map +1 -0
  117. package/lib/src/client/jsonParseWorker.d.ts +2 -0
  118. package/lib/src/client/jsonParseWorker.d.ts.map +1 -0
  119. package/lib/src/client/remote/{zstd-worker.d.ts → decompression-worker.d.ts} +15 -8
  120. package/lib/src/client/remote/decompression-worker.d.ts.map +1 -0
  121. package/lib/src/client/remote/decompression.d.ts.map +1 -1
  122. package/lib/src/client/remote/decompression.worker.d.ts +2 -0
  123. package/lib/src/client/remote/decompression.worker.d.ts.map +1 -0
  124. package/lib/src/client/remote/inflate.d.ts +11 -0
  125. package/lib/src/client/remote/inflate.d.ts.map +1 -0
  126. package/lib/src/client/remote/zstd-decoder.d.ts.map +1 -1
  127. package/lib/src/client/utils/derive.d.ts.map +1 -1
  128. package/lib/src/components/DownloadLogButton.d.ts.map +1 -1
  129. package/lib/src/components/LinkButton.d.ts +2 -1
  130. package/lib/src/components/LinkButton.d.ts.map +1 -1
  131. package/lib/src/components/MessageBand.d.ts.map +1 -1
  132. package/lib/src/index.d.ts +0 -9
  133. package/lib/src/index.d.ts.map +1 -1
  134. package/lib/src/log_data/databaseInstance.d.ts +7 -0
  135. package/lib/src/log_data/databaseInstance.d.ts.map +1 -1
  136. package/lib/src/log_data/databaseListings.d.ts +3 -1
  137. package/lib/src/log_data/databaseListings.d.ts.map +1 -1
  138. package/lib/src/log_data/fetchEngine.d.ts +4 -0
  139. package/lib/src/log_data/fetchEngine.d.ts.map +1 -1
  140. package/lib/src/log_data/imperativeLogData.d.ts +1 -1
  141. package/lib/src/log_data/index.d.ts +3 -1
  142. package/lib/src/log_data/index.d.ts.map +1 -1
  143. package/lib/src/log_data/runningSampleQuery.d.ts +4 -1
  144. package/lib/src/log_data/runningSampleQuery.d.ts.map +1 -1
  145. package/lib/src/log_data/samplesListing.d.ts +1 -2
  146. package/lib/src/log_data/samplesListing.d.ts.map +1 -1
  147. package/lib/src/log_data/testFixtures.d.ts +1 -1
  148. package/lib/src/log_data/testFixtures.d.ts.map +1 -1
  149. package/lib/src/log_data/useFetchEngineStatus.d.ts +5 -1
  150. package/lib/src/log_data/useFetchEngineStatus.d.ts.map +1 -1
  151. package/lib/src/log_data/useLogsSync.d.ts +7 -1
  152. package/lib/src/log_data/useLogsSync.d.ts.map +1 -1
  153. package/lib/src/main.d.ts +0 -1
  154. package/lib/src/main.d.ts.map +1 -1
  155. package/lib/src/scoring/headline.d.ts.map +1 -1
  156. package/lib/src/state/hooks.d.ts.map +1 -1
  157. package/lib/src/state/sampleSlice.d.ts +6 -6
  158. package/lib/src/state/sampleSlice.d.ts.map +1 -1
  159. package/lib/src/test/mswServer.d.ts +9 -0
  160. package/lib/src/test/mswServer.d.ts.map +1 -0
  161. package/lib/src/test/nodeWorker.d.ts +2 -0
  162. package/lib/src/test/nodeWorker.d.ts.map +1 -0
  163. package/lib/src/test/testApp.d.ts +36 -0
  164. package/lib/src/test/testApp.d.ts.map +1 -0
  165. package/lib/styles/index.css +12649 -12533
  166. package/package.json +19 -19
  167. package/lib/AnsiDisplayRich-302CIkEj.js.map +0 -1
  168. package/lib/ToolButton-BmBvTvKO.js +0 -124
  169. package/lib/ToolButton-BmBvTvKO.js.map +0 -1
  170. package/lib/markdownPipeline-C_z-iU9a.js.map +0 -1
  171. package/lib/src/app/appearance/colors.d.ts +0 -10
  172. package/lib/src/app/appearance/colors.d.ts.map +0 -1
  173. package/lib/src/app/appearance/icons.d.ts +0 -148
  174. package/lib/src/app/appearance/icons.d.ts.map +0 -1
  175. package/lib/src/app/log-view/title-view/ProvenanceFields.d.ts +0 -11
  176. package/lib/src/app/log-view/title-view/ProvenanceFields.d.ts.map +0 -1
  177. package/lib/src/app/samples/error/FlatSampleErrorView.d.ts +0 -10
  178. package/lib/src/app/samples/error/FlatSampleErrorView.d.ts.map +0 -1
  179. package/lib/src/app/samples/sampleDataAdapter.d.ts +0 -7
  180. package/lib/src/app/samples/sampleDataAdapter.d.ts.map +0 -1
  181. package/lib/src/app/samples/transcript/types.d.ts +0 -9
  182. package/lib/src/app/samples/transcript/types.d.ts.map +0 -1
  183. package/lib/src/app/shared/openInNewTab.d.ts +0 -13
  184. package/lib/src/app/shared/openInNewTab.d.ts.map +0 -1
  185. package/lib/src/client/database/utils.d.ts +0 -3
  186. package/lib/src/client/database/utils.d.ts.map +0 -1
  187. package/lib/src/client/remote/zstd-worker-code.d.ts +0 -20
  188. package/lib/src/client/remote/zstd-worker-code.d.ts.map +0 -1
  189. package/lib/src/client/remote/zstd-worker.d.ts.map +0 -1
  190. package/lib/src/components/CodePanel.d.ts +0 -8
  191. package/lib/src/components/CodePanel.d.ts.map +0 -1
  192. package/lib/src/test/nodeBlobWorker.d.ts +0 -2
  193. package/lib/src/test/nodeBlobWorker.d.ts.map +0 -1
  194. package/lib/src/utils/debugging.d.ts +0 -3
  195. package/lib/src/utils/debugging.d.ts.map +0 -1
  196. package/lib/src-s8Cexy_j.js +0 -9977
  197. package/lib/src-s8Cexy_j.js.map +0 -1
@@ -1,5 +1,4 @@
1
1
  import { n as __exportAll$1 } from "./rolldown-runtime-B-lAHAz2.js";
2
- import "./src-s8Cexy_j.js";
3
2
  import { d as parseDataUri, n as escapeHtmlCharacters, o as canonicalImageSource, r as simpleMarkdownTruncate, t as defaultMarkdownRenderer, u as parseAbsoluteHttpUrl } from "./markdownText-z5R6PHwt.js";
4
3
  //#region ../../node_modules/.pnpm/mdurl@2.1.0/node_modules/mdurl/lib/decode.mjs
5
4
  var decodeCache = {};
@@ -5520,6 +5519,8 @@ var getMathjaxPlugin = () => {
5520
5519
  }
5521
5520
  return mathjaxPluginPromise;
5522
5521
  };
5522
+ var MATHJAX_STYLE = /^(\s*<span id="mjx-[a-f0-9]+">\s*)<style>[\s\S]*?<\/style>/i;
5523
+ var withoutMathJaxStyle = (html) => html.replace(MATHJAX_STYLE, "$1");
5523
5524
  var hasMathContent = (text) => text.includes("$") || text.includes("\\(") || text.includes("\\[");
5524
5525
  var mdInstanceCache = {};
5525
5526
  /** Unescape HTML entities within math token content before MathJax processing.
@@ -5570,12 +5571,12 @@ var getMarkdownInstance = async (renderer, contentHasMath) => {
5570
5571
  if (origInline) md.renderer.rules.math_inline = (tokens, idx, options, env, self) => {
5571
5572
  const token = tokens[idx];
5572
5573
  if (token) token.content = unescapeHtmlForMath(token.content);
5573
- return origInline(tokens, idx, options, env, self);
5574
+ return withoutMathJaxStyle(origInline(tokens, idx, options, env, self));
5574
5575
  };
5575
5576
  if (origBlock) md.renderer.rules.math_block = (tokens, idx, options, env, self) => {
5576
5577
  const token = tokens[idx];
5577
5578
  if (token) token.content = unescapeHtmlForMath(token.content);
5578
- return origBlock(tokens, idx, options, env, self);
5579
+ return withoutMathJaxStyle(origBlock(tokens, idx, options, env, self));
5579
5580
  };
5580
5581
  }
5581
5582
  mdInstanceCache[cacheKey] = md;
@@ -5843,8 +5844,8 @@ function hasLinkSyntax(text) {
5843
5844
  return substr;
5844
5845
  }
5845
5846
  //#endregion
5846
- //#region ../../node_modules/.pnpm/dompurify@3.4.16/node_modules/dompurify/dist/purify.es.mjs
5847
- /*! @license DOMPurify 3.4.16 | (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.16/LICENSE */
5847
+ //#region ../../node_modules/.pnpm/dompurify@3.4.17/node_modules/dompurify/dist/purify.es.mjs
5848
+ /*! @license DOMPurify 3.4.17 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.17/LICENSE */
5848
5849
  function _OverloadYield(e, d) {
5849
5850
  this.v = e, this.k = d;
5850
5851
  }
@@ -5968,9 +5969,12 @@ Array.prototype.indexOf;
5968
5969
  var arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
5969
5970
  var arrayPop = unapply(Array.prototype.pop);
5970
5971
  var arrayPush = unapply(Array.prototype.push);
5971
- Array.prototype.slice;
5972
+ var arraySlice = unapply(Array.prototype.slice);
5972
5973
  var arraySplice = unapply(Array.prototype.splice);
5973
5974
  var arrayIsArray = Array.isArray;
5975
+ var setCreate = unconstruct(Set);
5976
+ var setAdd = unapply(Set.prototype.add);
5977
+ var setHas = unapply(Set.prototype.has);
5974
5978
  var stringToLowerCase = unapply(String.prototype.toLowerCase);
5975
5979
  var stringToString = unapply(String.prototype.toString);
5976
5980
  var stringMatch = unapply(String.prototype.match);
@@ -6115,6 +6119,25 @@ function lookupGetter(object, prop) {
6115
6119
  }
6116
6120
  return fallbackValue;
6117
6121
  }
6122
+ /**
6123
+ * Like lookupGetter, but for accessor properties only, and returns null
6124
+ * instead of a null-returning fallback when no getter exists on the chain.
6125
+ * Lets a caller fall back to a direct property read in environments that
6126
+ * lack the getter, where a fallback returning null would be indistinguishable
6127
+ * from a legitimate null value (e.g. namespaceURI of a no-namespace element).
6128
+ *
6129
+ * @param object - The object (usually a prototype) to start the lookup at.
6130
+ * @param prop - The accessor property name.
6131
+ * @returns The unapplied getter, or null if none was found.
6132
+ */
6133
+ function lookupAccessor(object, prop) {
6134
+ while (object !== null) {
6135
+ const desc = getOwnPropertyDescriptor(object, prop);
6136
+ if (desc) return desc.get ? unapply(desc.get) : null;
6137
+ object = getPrototypeOf(object);
6138
+ }
6139
+ return null;
6140
+ }
6118
6141
  function isRegex(value) {
6119
6142
  try {
6120
6143
  regExpTest(value, "");
@@ -6799,7 +6822,7 @@ var NODE_TYPE = {
6799
6822
  documentFragment: 11,
6800
6823
  notation: 12
6801
6824
  };
6802
- var LITERAL_TEXT_ELEMENT_NAMES = [
6825
+ var LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, [
6803
6826
  "style",
6804
6827
  "script",
6805
6828
  "xmp",
@@ -6808,15 +6831,7 @@ var LITERAL_TEXT_ELEMENT_NAMES = [
6808
6831
  "noframes",
6809
6832
  "plaintext",
6810
6833
  "noscript"
6811
- ];
6812
- var LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, LITERAL_TEXT_ELEMENT_NAMES));
6813
- var LITERAL_TEXT_CLOSE = function() {
6814
- const map = {};
6815
- arrayForEach(LITERAL_TEXT_ELEMENT_NAMES, (name) => {
6816
- map[name] = seal(new RegExp("</" + name + "(?=[\\t\\n\\f\\r />])", "i"));
6817
- });
6818
- return freeze(map);
6819
- }();
6834
+ ]));
6820
6835
  var getGlobal = function getGlobal() {
6821
6836
  return typeof window === "undefined" ? null : window;
6822
6837
  };
@@ -6894,7 +6909,7 @@ var _resolveObjectOption = function _resolveObjectOption(cfg, key, makeFallback)
6894
6909
  function createDOMPurify() {
6895
6910
  let window = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
6896
6911
  const DOMPurify = (root) => createDOMPurify(root);
6897
- DOMPurify.version = "3.4.16";
6912
+ DOMPurify.version = "3.4.17";
6898
6913
  DOMPurify.removed = [];
6899
6914
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
6900
6915
  DOMPurify.isSupported = false;
@@ -6926,6 +6941,10 @@ function createDOMPurify() {
6926
6941
  const _readNodeName = function _readNodeName(node) {
6927
6942
  return getNodeName ? getNodeName(node) : node.nodeName;
6928
6943
  };
6944
+ const getNamespaceURI = lookupAccessor(ElementPrototype, "namespaceURI");
6945
+ const _readNamespaceURI = function _readNamespaceURI(element) {
6946
+ return getNamespaceURI ? getNamespaceURI(element) : element.namespaceURI;
6947
+ };
6929
6948
  if (typeof HTMLTemplateElement === "function") {
6930
6949
  const template = document.createElement("template");
6931
6950
  if (template.content && template.content.ownerDocument) document = template.content.ownerDocument;
@@ -7046,6 +7065,7 @@ function createDOMPurify() {
7046
7065
  const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
7047
7066
  let KEEP_CONTENT = true;
7048
7067
  let IN_PLACE = false;
7068
+ let IN_PLACE_VISITED = null;
7049
7069
  let USE_PROFILES = {};
7050
7070
  let FORBID_CONTENTS = null;
7051
7071
  const DEFAULT_FORBID_CONTENTS = addToSet({}, [
@@ -7319,18 +7339,23 @@ function createDOMPurify() {
7319
7339
  * return. Return true otherwise.
7320
7340
  */
7321
7341
  const _checkValidNamespace = function _checkValidNamespace(element) {
7322
- let parent = getParentNode(element);
7323
- if (!parent || !parent.tagName) parent = {
7324
- namespaceURI: NAMESPACE,
7325
- tagName: "template"
7326
- };
7327
- const tagName = stringToLowerCase(element.tagName);
7328
- const parentTagName = stringToLowerCase(parent.tagName);
7329
- if (!ALLOWED_NAMESPACES[element.namespaceURI]) return false;
7330
- if (element.namespaceURI === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parent, parentTagName);
7331
- if (element.namespaceURI === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parent, parentTagName);
7332
- if (element.namespaceURI === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parent, parentTagName);
7333
- if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element.namespaceURI]) return true;
7342
+ const elementNamespace = _readNamespaceURI(element);
7343
+ const tagName = stringToLowerCase(_readNodeName(element));
7344
+ const parentNode = getParentNode(element);
7345
+ let parent;
7346
+ let parentTagName;
7347
+ if (parentNode && _readNodeType(parentNode) === NODE_TYPE.element) {
7348
+ parent = { namespaceURI: _readNamespaceURI(parentNode) };
7349
+ parentTagName = stringToLowerCase(_readNodeName(parentNode));
7350
+ } else {
7351
+ parent = { namespaceURI: NAMESPACE };
7352
+ parentTagName = "template";
7353
+ }
7354
+ if (!ALLOWED_NAMESPACES[elementNamespace]) return false;
7355
+ if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parent, parentTagName);
7356
+ if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parent, parentTagName);
7357
+ if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parent, parentTagName);
7358
+ if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[elementNamespace]) return true;
7334
7359
  return false;
7335
7360
  };
7336
7361
  /**
@@ -7374,36 +7399,21 @@ function createDOMPurify() {
7374
7399
  }
7375
7400
  };
7376
7401
  /**
7377
- * _neutralizeRoot
7378
- *
7379
- * Fail-closed teardown of an in-place root after the sanitize walk aborts
7380
- * (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
7381
- * custom element's reaction detaches a node so `_forceRemove`'s deliberate
7382
- * parentless guard throws, or any other re-entrant engine mutation — would
7383
- * otherwise leave the caller's *live* tree half-sanitized, with everything
7384
- * after the abort point still carrying its handlers. There is no safe way
7385
- * to resume the walk (the tree mutated under us), so we strip the root bare:
7386
- * remove every child and every attribute, then let the caller's catch see
7387
- * the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
7388
- * getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
7402
+ * Fail-closed teardown of an in-place root: strip every disallowed attribute
7403
+ * in the subtree first, so nothing armed is left behind, then remove all
7404
+ * children and the root's own attributes.
7389
7405
  *
7390
7406
  * @param root the in-place root to empty
7391
7407
  */
7392
7408
  const _neutralizeRoot = function _neutralizeRoot(root) {
7393
7409
  _neutralizeSubtree(root);
7394
7410
  const childNodes = getChildNodes(root);
7395
- if (childNodes) {
7396
- const snapshot = [];
7397
- arrayForEach(childNodes, (child) => {
7398
- arrayPush(snapshot, child);
7399
- });
7400
- arrayForEach(snapshot, (child) => {
7401
- try {
7402
- remove(child);
7403
- } catch (_) {}
7404
- });
7405
- }
7406
- const attributes = getAttributes(root);
7411
+ if (childNodes) arrayForEach(arraySlice(childNodes), (child) => {
7412
+ try {
7413
+ remove(child);
7414
+ } catch (_) {}
7415
+ });
7416
+ const attributes = _readNodeType(root) === NODE_TYPE.element ? getAttributes(root) : null;
7407
7417
  if (attributes) for (let i = attributes.length - 1; i >= 0; --i) {
7408
7418
  const attribute = attributes[i];
7409
7419
  const name = attribute && attribute.name;
@@ -7411,18 +7421,9 @@ function createDOMPurify() {
7411
7421
  }
7412
7422
  };
7413
7423
  /**
7414
- * _removeAttribute
7415
- *
7416
- * Name-based getAttributeNode()/removeAttribute() ASCII-lowercase their
7417
- * lookup key for HTML elements in an HTML document, so they silently miss an
7418
- * attribute whose stored qualified name still contains uppercase ASCII
7419
- * letters. That happens when the node came from a case-preserving source
7420
- * (an XML/XHTML document imported via importNode(), or createAttributeNS()),
7421
- * where e.g. `ONERROR` survives the walk: the policy check lowercases to
7422
- * `onerror` and rejects it, but `removeAttribute('ONERROR')` looks up
7423
- * `onerror` and finds nothing. Remove the exact Attr node instead, which is
7424
- * case- and namespace-exact, and fall back to name-based removal only when
7425
- * the caller could not supply the node.
7424
+ * Removes an attribute, preferably as its exact Attr node: name-based
7425
+ * removal lowercases the name in HTML documents and misses case-preserved
7426
+ * names, e.g. from imported XHTML.
7426
7427
  *
7427
7428
  * @param name an Attribute name
7428
7429
  * @param element a DOM node
@@ -7456,12 +7457,8 @@ function createDOMPurify() {
7456
7457
  }
7457
7458
  };
7458
7459
  /**
7459
- * _stripDisallowedAttributes
7460
- *
7461
- * Removes every attribute the active configuration does not allow from a
7462
- * single element, using the same allowlist as the main attribute pass (so
7463
- * `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
7464
- * neutralise nodes that are being discarded from an in-place tree.
7460
+ * Removes every attribute the configuration does not allow. Used to
7461
+ * neutralize nodes discarded from an in-place tree.
7465
7462
  *
7466
7463
  * @param element the element to strip
7467
7464
  */
@@ -7476,77 +7473,158 @@ function createDOMPurify() {
7476
7473
  }
7477
7474
  };
7478
7475
  /**
7479
- * _neutralizeSubtree
7480
- *
7481
- * Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
7482
- * move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
7483
- * namespace, comment, processing-instruction and KEEP_CONTENT:false removals
7484
- * all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
7485
- * those dropped nodes are detached from the caller's LIVE tree but a
7486
- * handler-bearing original among them (an `<img onerror>`/`<video>` that was
7487
- * loading) keeps its queued resource event, which fires in page scope after
7488
- * sanitize returns. This walks a removed subtree and strips every attribute
7489
- * the active configuration does not allow — so `on*` handlers are cancelled
7490
- * through the SAME allowlist that governs kept nodes, not a separate `/^on/`
7491
- * blocklist. Run synchronously before sanitize returns, i.e. before any
7492
- * queued event can fire. Hook-free by design: these nodes leave the output,
7493
- * so firing attribute hooks for them would be surprising. Clobber-safe reads;
7494
- * a doomed clobbered node may shadow `removeAttribute` (its own attributes are
7495
- * irrelevant — it is discarded — while its non-clobbered descendants, e.g.
7496
- * the `<img>`, are reached and scrubbed).
7476
+ * Iterative depth-first walk, so deep trees cannot overflow the call stack,
7477
+ * reading through the cached getters, so clobbering cannot hide children.
7478
+ * When `visit` returns false, the node's children are skipped. With
7479
+ * `intoShadow`, open shadow roots are walked after their host's children.
7497
7480
  *
7498
- * @param root the root of a removed subtree to neutralise
7481
+ * @param root where to start
7482
+ * @param visit called for every node
7483
+ * @param intoShadow whether to enter open shadow roots
7499
7484
  */
7500
- const _neutralizeSubtree = function _neutralizeSubtree(root) {
7485
+ const _walkTree = function _walkTree(root, visit) {
7486
+ let intoShadow = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
7501
7487
  const stack = [root];
7502
7488
  while (stack.length > 0) {
7503
7489
  const node = stack.pop();
7504
- if (_readNodeType(node) === NODE_TYPE.element) _stripDisallowedAttributes(node);
7490
+ if (visit(node) === false) continue;
7491
+ if (intoShadow && _readNodeType(node) === NODE_TYPE.element) {
7492
+ const shadowRoot = getShadowRoot(node);
7493
+ if (_isDocumentFragment(shadowRoot)) stack.push(shadowRoot);
7494
+ }
7505
7495
  const childNodes = getChildNodes(node);
7506
7496
  if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push(childNodes[i]);
7507
7497
  }
7508
7498
  };
7509
7499
  /**
7510
- * _neutralizePatchLinkage
7500
+ * Strips disallowed attributes from every element of a discarded subtree,
7501
+ * so a handler that is already queued (a loading image) cannot fire.
7511
7502
  *
7512
- * IN_PLACE entry pre-pass (declarative-partial-updates / streaming
7513
- * hardening, https://github.com/WICG/declarative-partial-updates).
7503
+ * @param root the root of a removed subtree
7504
+ */
7505
+ const _neutralizeSubtree = function _neutralizeSubtree(root) {
7506
+ _walkTree(root, (node) => {
7507
+ if (_readNodeType(node) === NODE_TYPE.element) _stripDisallowedAttributes(node);
7508
+ });
7509
+ };
7510
+ /**
7511
+ * All nodes under `root`, root first, including open shadow roots. Template
7512
+ * content is not entered, it is inert.
7514
7513
  *
7515
- * The main walk strips patch linkage (`for`/`patchsrc`) and removes range
7516
- * markers (PIs / markup comments) node-by-node, in document order, AS it
7517
- * reaches each node. On a live in-place root that leaves a window: from the
7518
- * moment the root is connected until the walk arrives at a given node, that
7519
- * node's linkage is live. A patch applied on connection/stream can fire as
7520
- * a microtask during the walk and inject or teleport an unsanitized DOM
7521
- * range into a region the iterator has already passed and will not revisit,
7522
- * so the post-return "tree is sanitized" contract is violated. Sweep the
7523
- * whole tree once up front and sever every linkage before the walk begins,
7524
- * closing that window.
7514
+ * @param root the in-place root
7515
+ * @return the nodes
7516
+ */
7517
+ const _collectLiveNodes = function _collectLiveNodes(root) {
7518
+ const nodes = [];
7519
+ _walkTree(root, (node) => {
7520
+ nodes.push(node);
7521
+ }, true);
7522
+ return nodes;
7523
+ };
7524
+ /**
7525
+ * Strips disallowed attributes from every element that was under the
7526
+ * in-place root when the call started and no longer is, whatever removed
7527
+ * or moved it.
7525
7528
  *
7526
- * This CANNOT undo a patch that already fired before sanitize ran — that is
7527
- * the irreducible "do not IN_PLACE a live-connected attacker tree" caveat —
7528
- * but it closes everything from sanitize-start onward. Gated on SAFE_FOR_XML
7529
- * to group with the rest of the declarative-partial-updates handling and
7530
- * stay overridable, consistent with the codebase.
7529
+ * @param root the in-place root
7530
+ * @param before the root's nodes, collected before the walk
7531
+ */
7532
+ const _neutralizeEscapedElements = function _neutralizeEscapedElements(root, before) {
7533
+ const reachable = setCreate();
7534
+ arrayForEach(_collectLiveNodes(root), (node) => {
7535
+ if (_readNodeType(node) === NODE_TYPE.element) setAdd(reachable, node);
7536
+ });
7537
+ arrayForEach(before, (node) => {
7538
+ if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node)) _stripDisallowedAttributes(node);
7539
+ });
7540
+ };
7541
+ /**
7542
+ * Neutralizes everything that left the in-place tree during the call: what
7543
+ * DOMPurify removed, and what hooks or custom elements removed or moved out.
7531
7544
  *
7532
- * Clobber-safe traversal (cached childNodes getter); per-node try/catch so a
7533
- * clobbered root cannot defeat the sweep of its non-clobbered descendants.
7545
+ * @param root the in-place root
7546
+ * @param before the root's nodes, collected before the walk
7547
+ * @return true if the root itself was removed
7548
+ */
7549
+ const _neutralizeDiscarded = function _neutralizeDiscarded(root, before) {
7550
+ let rootRemoved = false;
7551
+ arrayForEach(DOMPurify.removed, (entry) => {
7552
+ if (entry.element) {
7553
+ rootRemoved = rootRemoved || entry.element === root;
7554
+ _neutralizeSubtree(entry.element);
7555
+ }
7556
+ });
7557
+ _neutralizeEscapedElements(root, before);
7558
+ return rootRemoved;
7559
+ };
7560
+ const MAX_UNVISITED_ROUNDS = 8;
7561
+ /**
7562
+ * The walk only moves forward, so a node moved to a position it already
7563
+ * passed is never visited. Give every original node that is still in the
7564
+ * tree but unvisited the normal treatment, hooks included. Nodes created
7565
+ * during the call are left alone. Fails closed if the tree keeps changing.
7534
7566
  *
7535
- * NOTE (pending real-Chrome confirmation, see test/declarative-patch-probe
7536
- * .html Q1): this mirrors the existing policy of keeping `for` on
7537
- * <label>/<output>. If the shipping feature can drive a patch through a
7538
- * surviving `for`-on-label/output + `id` pair, this pre-pass and the
7539
- * attribute check at _isBasicCustomElement's caller must additionally drop
7540
- * that pair on the IN_PLACE path. Left as-is until the taxonomy is verified.
7567
+ * @param root the in-place root
7568
+ * @param before the root's nodes, collected before the walk
7569
+ */
7570
+ const _sanitizeUnvisitedNodes = function _sanitizeUnvisitedNodes(root, before) {
7571
+ const visited = IN_PLACE_VISITED;
7572
+ let original = null;
7573
+ const getOriginal = () => {
7574
+ if (!original) {
7575
+ original = setCreate();
7576
+ arrayForEach(before, (beforeNode) => {
7577
+ setAdd(original, beforeNode);
7578
+ });
7579
+ }
7580
+ return original;
7581
+ };
7582
+ for (let round = 0;; round++) {
7583
+ const live = _collectLiveNodes(root);
7584
+ const containers = [root];
7585
+ let pending = false;
7586
+ arrayForEach(live, (node) => {
7587
+ if (_readNodeType(node) === NODE_TYPE.documentFragment) arrayPush(containers, node);
7588
+ else if (!pending && !setHas(visited, node)) pending = setHas(getOriginal(), node);
7589
+ });
7590
+ if (!pending) return;
7591
+ if (round >= MAX_UNVISITED_ROUNDS) throw typeErrorCreate("the tree kept changing during in-place sanitization; refusing to return it");
7592
+ arrayForEach(containers, (container, index) => {
7593
+ _sanitizeUnvisitedIn(container, index > 0, root, getOriginal());
7594
+ });
7595
+ }
7596
+ };
7597
+ /**
7598
+ * One _sanitizeUnvisitedNodes pass over the root or an open shadow root.
7541
7599
  *
7542
- * @param root the in-place root to sweep
7600
+ * @param container the root or an open shadow root
7601
+ * @param inShadow whether container is a shadow root
7602
+ * @param root the in-place root
7603
+ * @param original the root's nodes collected before the walk, as a set
7543
7604
  */
7605
+ const _sanitizeUnvisitedIn = function _sanitizeUnvisitedIn(container, inShadow, root, original) {
7606
+ const iterator = _createNodeIterator(container);
7607
+ let node;
7608
+ while (node = iterator.nextNode()) {
7609
+ if (!setHas(original, node) || setHas(IN_PLACE_VISITED, node)) continue;
7610
+ if (inShadow) _executeHooks(hooks.uponSanitizeShadowNode, node, null);
7611
+ _sanitizeElements(node, root);
7612
+ _sanitizeAttributes(node, root);
7613
+ if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
7614
+ }
7615
+ };
7544
7616
  /**
7545
- * Central policy for declarative-partial-updates patch-linkage attributes,
7546
- * shared by the _neutralizePatchLinkage pre-pass and _isValidAttribute so
7547
- * the two sites cannot drift: `patchsrc` always links, `for` links
7548
- * everywhere except on <label>/<output>, and the whole policy is gated on
7549
- * SAFE_FOR_XML (see the rationale block in _isValidAttribute).
7617
+ * Records that _sanitizeElements processed `node`. No-op outside IN_PLACE.
7618
+ *
7619
+ * @param node the node being processed
7620
+ */
7621
+ const _markVisited = function _markVisited(node) {
7622
+ if (IN_PLACE_VISITED) setAdd(IN_PLACE_VISITED, node);
7623
+ };
7624
+ /**
7625
+ * Patch-linkage attributes (declarative partial updates): `patchsrc`
7626
+ * always, `for` everywhere except on <label> and <output>. Gated on
7627
+ * SAFE_FOR_XML. Shared by the IN_PLACE pre-pass and _isValidAttribute.
7550
7628
  *
7551
7629
  * @param lcName the transformCaseFunc'd attribute name
7552
7630
  * @param lcTag the transformCaseFunc'd tag name of the carrying element
@@ -7557,17 +7635,26 @@ function createDOMPurify() {
7557
7635
  if (lcName === "patchsrc") return true;
7558
7636
  return lcName === "for" && lcTag !== "label" && lcTag !== "output";
7559
7637
  };
7638
+ /**
7639
+ * IN_PLACE pre-pass: sever all patch linkage before the walk, so no patch
7640
+ * can fire mid-walk into a part of the tree the walker already passed.
7641
+ * Removes range markers (processing instructions, comments with markup)
7642
+ * and strips linkage attributes. It cannot undo a patch that already fired.
7643
+ *
7644
+ * TODO: if the shipped feature can patch through `for` on <label>/<output>,
7645
+ * drop that pair here too (see test/declarative-patch-probe.html).
7646
+ *
7647
+ * @param root the in-place root to sweep
7648
+ */
7560
7649
  const _neutralizePatchLinkage = function _neutralizePatchLinkage(root) {
7561
7650
  if (!SAFE_FOR_XML) return;
7562
- const stack = [root];
7563
- while (stack.length > 0) {
7564
- const node = stack.pop();
7651
+ _walkTree(root, (node) => {
7565
7652
  const nodeType = _readNodeType(node);
7566
7653
  if (nodeType === NODE_TYPE.processingInstruction || nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, node.data)) {
7567
7654
  try {
7568
7655
  remove(node);
7569
7656
  } catch (_) {}
7570
- continue;
7657
+ return false;
7571
7658
  }
7572
7659
  if (nodeType === NODE_TYPE.element) {
7573
7660
  const element = node;
@@ -7577,9 +7664,8 @@ function createDOMPurify() {
7577
7664
  if (element.hasAttribute && element.hasAttribute("for") && _isPatchLinkageAttribute("for", lcTag)) element.removeAttribute("for");
7578
7665
  } catch (_) {}
7579
7666
  }
7580
- const childNodes = getChildNodes(node);
7581
- if (childNodes) for (let i = childNodes.length - 1; i >= 0; --i) stack.push(childNodes[i]);
7582
- }
7667
+ return true;
7668
+ });
7583
7669
  };
7584
7670
  /**
7585
7671
  * _initDocument
@@ -7656,6 +7742,27 @@ function createDOMPurify() {
7656
7742
  */
7657
7743
  const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
7658
7744
  var _node$querySelectorAl;
7745
+ _scrubOwnCharacterData(node);
7746
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, "template");
7747
+ if (templates) arrayForEach(templates, (tmpl) => {
7748
+ if (_isDocumentFragment(tmpl.content)) _scrubTemplateExpressions2(tmpl.content);
7749
+ });
7750
+ };
7751
+ /**
7752
+ * _scrubOwnCharacterData
7753
+ *
7754
+ * Non-recursive core of _scrubTemplateExpressions: normalize `node` and
7755
+ * strip template expressions from its own character data only. Does not
7756
+ * enter <template>.content or attached shadow roots (NodeIterator never
7757
+ * does). Used by _sanitizeShadowDOM, where every nested template content
7758
+ * and shadow root is already walked - and therefore scrubbed - by its own
7759
+ * recursive _sanitizeShadowDOM call; recursing here as well would rescrub
7760
+ * each nested fragment once per ancestor, which is quadratic in nesting
7761
+ * depth.
7762
+ *
7763
+ * @param node The root whose own character data should be scrubbed.
7764
+ */
7765
+ const _scrubOwnCharacterData = function _scrubOwnCharacterData(node) {
7659
7766
  node.normalize();
7660
7767
  const doc = getOwnerDocument ? getOwnerDocument(node) : node.ownerDocument;
7661
7768
  const walker = createNodeIterator.call(doc || node, node, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
@@ -7664,10 +7771,6 @@ function createDOMPurify() {
7664
7771
  currentNode.data = _stripTemplateExpressions(currentNode.data);
7665
7772
  currentNode = walker.nextNode();
7666
7773
  }
7667
- const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, "template");
7668
- if (templates) arrayForEach(templates, (tmpl) => {
7669
- if (_isDocumentFragment(tmpl.content)) _scrubTemplateExpressions2(tmpl.content);
7670
- });
7671
7774
  };
7672
7775
  /**
7673
7776
  * _isClobbered
@@ -7743,7 +7846,7 @@ function createDOMPurify() {
7743
7846
  */
7744
7847
  const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
7745
7848
  if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
7746
- if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && LITERAL_TEXT_ELEMENTS[tagName] && (_isNode(currentNode.firstElementChild) || typeof currentNode.textContent === "string" && regExpTest(LITERAL_TEXT_CLOSE[tagName], currentNode.textContent))) return true;
7849
+ if (SAFE_FOR_XML && LITERAL_TEXT_ELEMENTS[tagName] && _readNodeType(currentNode) === NODE_TYPE.element && _readNamespaceURI(currentNode) === HTML_NAMESPACE && (_isNode(currentNode.firstElementChild) || typeof currentNode.textContent === "string" && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent))) return true;
7747
7850
  if (currentNode.nodeType === NODE_TYPE.processingInstruction) return true;
7748
7851
  if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
7749
7852
  return false;
@@ -7787,7 +7890,7 @@ function createDOMPurify() {
7787
7890
  */
7788
7891
  const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName, root) {
7789
7892
  if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
7790
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
7893
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName] && !FORBID_CONTENTS[stringToLowerCase(tagName)]) {
7791
7894
  const parentNode = getParentNode(currentNode);
7792
7895
  const childNodes = getChildNodes(currentNode);
7793
7896
  if (childNodes && parentNode) {
@@ -7820,35 +7923,13 @@ function createDOMPurify() {
7820
7923
  return set === defaultSet || set === setConfigSet ? clone(set) : set;
7821
7924
  };
7822
7925
  /**
7823
- * Shared guard for a node that a hook has detached from the walk tree,
7824
- * used after each element-hook site in _sanitizeElements. Detaching is a
7825
- * long-standing user pattern (issue #469; draw.io-style foreignObject
7826
- * filtering). Per the cached, unclobberable parentNode getter the node is
7827
- * genuinely out of the tree, so it can reach neither the serialized
7828
- * output nor an IN_PLACE live tree; treat it as removed and stop
7829
- * processing it. Without this guard, the unsafe-node / namespace checks
7830
- * would call _forceRemove on a parentless node and hit the REPORT-3
7831
- * fail-closed throw — which exists for nodes DOMPurify wants gone but
7832
- * *cannot* detach (clobbered / parentless roots), the opposite of a node
7833
- * that is already safely gone. The walk root is exempt: a detached
7834
- * IN_PLACE root is legitimate input and must still be fully sanitized,
7835
- * and a kill-decision on it must keep hitting the REPORT-3 throw.
7836
- *
7837
- * Nodes detached by hooks stay the hook's responsibility for placement:
7838
- * they are not recorded in DOMPurify.removed, so the post-walk IN_PLACE
7839
- * pass (which iterates DOMPurify.removed) does not reach them. But a
7840
- * hook-detached subtree can still hold a queued resource-event handler -
7841
- * e.g. an <img onload> that began loading when the caller built the live
7842
- * tree - which fires in page scope after sanitize returns even though the
7843
- * handler never reached the returned tree. That is the audit-5 F1 hazard,
7844
- * and the documented node.remove() hook pattern walks straight into it.
7845
- * So on the IN_PLACE path we neutralize the detached subtree inline,
7846
- * stripping its non-allow-listed attributes before returning, exactly as
7847
- * the post-walk pass does for _forceRemove'd subtrees.
7926
+ * A hook may have detached the node it was called for. If so, treat it as
7927
+ * removed and stop processing it; the walk root is exempt. On the IN_PLACE
7928
+ * path the detached subtree is neutralized right away.
7848
7929
  *
7849
7930
  * @param currentNode the node a hook may have detached
7850
7931
  * @param root the current walk root
7851
- * @return true if the node is detached and now handled, false otherwise
7932
+ * @return true if the node was detached
7852
7933
  */
7853
7934
  const _handleHookDetachedNode = function _handleHookDetachedNode(currentNode, root) {
7854
7935
  if (currentNode === root || getParentNode(currentNode) !== null) return false;
@@ -7865,6 +7946,7 @@ function createDOMPurify() {
7865
7946
  * @return true if node was killed, false if left alive
7866
7947
  */
7867
7948
  const _sanitizeElements = function _sanitizeElements(currentNode, root) {
7949
+ _markVisited(currentNode);
7868
7950
  _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
7869
7951
  if (_handleHookDetachedNode(currentNode, root)) return true;
7870
7952
  if (_isClobbered(currentNode)) {
@@ -8008,6 +8090,22 @@ function createDOMPurify() {
8008
8090
  }
8009
8091
  };
8010
8092
  /**
8093
+ * _isUnsafeAttributeValue
8094
+ *
8095
+ * Value-based attribute checks that the attribute walk applies before any
8096
+ * hook can force-keep an attribute, shared with the public
8097
+ * isValidAttribute() so that it never approves a value sanitize() would
8098
+ * strip.
8099
+ *
8100
+ * @param name the attribute name as found on the node (case preserved)
8101
+ * @param value the attribute value
8102
+ * @returns true if the attribute must be removed because of its value
8103
+ */
8104
+ const _isUnsafeAttributeValue = function _isUnsafeAttributeValue(name, value) {
8105
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) return true;
8106
+ return stringToLowerCase(name) === "attributename" && stringMatch(value, "href") !== null;
8107
+ };
8108
+ /**
8011
8109
  * _sanitizeAttributes
8012
8110
  *
8013
8111
  * @protect attributes
@@ -8051,11 +8149,7 @@ function createDOMPurify() {
8051
8149
  value = SANITIZE_NAMED_PROPS_PREFIX + value;
8052
8150
  recreatedNamedProp = true;
8053
8151
  }
8054
- if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
8055
- _removeAttribute(name, currentNode, attr);
8056
- continue;
8057
- }
8058
- if (lcName === "attributename" && stringMatch(value, "href")) {
8152
+ if (_isUnsafeAttributeValue(name, value)) {
8059
8153
  _removeAttribute(name, currentNode, attr);
8060
8154
  continue;
8061
8155
  }
@@ -8103,24 +8197,13 @@ function createDOMPurify() {
8103
8197
  }
8104
8198
  }
8105
8199
  }
8200
+ if (SAFE_FOR_TEMPLATES) _scrubOwnCharacterData(fragment);
8106
8201
  _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
8107
8202
  };
8108
8203
  /**
8109
- * _sanitizeAttachedShadowRoots
8110
- *
8111
- * Walks `root` and feeds every attached shadow root we encounter into
8112
- * the existing _sanitizeShadowDOM pipeline. The default node iterator
8113
- * does not descend into shadow trees, so nodes inside an attached
8114
- * shadow root would otherwise be skipped entirely.
8115
- *
8116
- * Two real input paths put attached shadow roots in front of us:
8117
- * 1. IN_PLACE on a DOM node that already has shadow roots attached.
8118
- * 2. DOM-node input where importNode(dirty, true) deep-clones the
8119
- * shadow root because it was created with `clonable: true`.
8120
- *
8121
- * This pass runs once, up front, so the main iteration loop (and the
8122
- * existing _sanitizeShadowDOM template-content recursion) stay
8123
- * untouched — string-input paths are not affected.
8204
+ * Sanitizes every attached shadow root under `root`, since the node
8205
+ * iterator does not enter shadow trees. Needed for IN_PLACE input and for
8206
+ * DOM input whose clonable shadow roots were copied by importNode().
8124
8207
  *
8125
8208
  * @param root the subtree root to walk for attached shadow roots
8126
8209
  */
@@ -8185,6 +8268,8 @@ function createDOMPurify() {
8185
8268
  if (hooks.uponSanitizeAttribute.length > 0) ALLOWED_ATTR = clone(ALLOWED_ATTR);
8186
8269
  DOMPurify.removed = [];
8187
8270
  const inPlace = IN_PLACE && typeof dirty !== "string" && _isNode(dirty);
8271
+ let inPlaceNodes = [];
8272
+ const outerVisited = IN_PLACE_VISITED;
8188
8273
  if (inPlace) {
8189
8274
  _neutralizePatchLinkage(dirty);
8190
8275
  const nn = _readNodeName(dirty);
@@ -8199,12 +8284,8 @@ function createDOMPurify() {
8199
8284
  _neutralizeRoot(dirty);
8200
8285
  throw typeErrorCreate("root node is clobbered and cannot be sanitized in-place");
8201
8286
  }
8202
- try {
8203
- _sanitizeAttachedShadowRoots(dirty);
8204
- } catch (error) {
8205
- _neutralizeRoot(dirty);
8206
- throw error;
8207
- }
8287
+ inPlaceNodes = _collectLiveNodes(dirty);
8288
+ IN_PLACE_VISITED = setCreate();
8208
8289
  } else if (_isNode(dirty)) {
8209
8290
  body = _initDocument("<!---->");
8210
8291
  importedNode = body.ownerDocument.importNode(dirty, true);
@@ -8220,30 +8301,25 @@ function createDOMPurify() {
8220
8301
  if (body && FORCE_BODY) _forceRemove(body.firstChild);
8221
8302
  const walkRoot = inPlace ? dirty : body;
8222
8303
  try {
8304
+ if (inPlace) _sanitizeAttachedShadowRoots(dirty);
8223
8305
  const nodeIterator = _createNodeIterator(walkRoot);
8224
8306
  while (currentNode = nodeIterator.nextNode()) {
8225
8307
  _sanitizeElements(currentNode, walkRoot);
8226
8308
  _sanitizeAttributes(currentNode, walkRoot);
8227
8309
  if (_isDocumentFragment(currentNode.content)) _sanitizeShadowDOM2(currentNode.content);
8228
8310
  }
8311
+ if (inPlace) _sanitizeUnvisitedNodes(dirty, inPlaceNodes);
8229
8312
  } catch (error) {
8230
8313
  if (inPlace) {
8231
8314
  _neutralizeRoot(dirty);
8232
- arrayForEach(DOMPurify.removed, (entry) => {
8233
- if (entry.element) _neutralizeSubtree(entry.element);
8234
- });
8315
+ _neutralizeDiscarded(dirty, inPlaceNodes);
8235
8316
  }
8236
8317
  throw error;
8318
+ } finally {
8319
+ IN_PLACE_VISITED = outerVisited;
8237
8320
  }
8238
8321
  if (inPlace) {
8239
- let rootWasRemoved = false;
8240
- arrayForEach(DOMPurify.removed, (entry) => {
8241
- if (entry.element) {
8242
- if (entry.element === dirty) rootWasRemoved = true;
8243
- _neutralizeSubtree(entry.element);
8244
- }
8245
- });
8246
- if (rootWasRemoved) throw typeErrorCreate("a node selected for removal could not be safely returned; refusing to sanitize in place");
8322
+ if (_neutralizeDiscarded(dirty, inPlaceNodes)) throw typeErrorCreate("a node selected for removal could not be safely returned; refusing to sanitize in place");
8247
8323
  if (SAFE_FOR_TEMPLATES) _scrubTemplateExpressions2(dirty);
8248
8324
  return dirty;
8249
8325
  }
@@ -8280,6 +8356,7 @@ function createDOMPurify() {
8280
8356
  if (!CONFIG) _parseConfig({});
8281
8357
  const lcTag = transformCaseFunc(tag);
8282
8358
  const lcName = transformCaseFunc(attr);
8359
+ if (typeof value === "string" && (_isUnsafeAttributeValue(attr, value) || !ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value))) return false;
8283
8360
  return _isValidAttribute(lcTag, lcName, value);
8284
8361
  };
8285
8362
  DOMPurify.addHook = function(entryPoint, hookFunction) {
@@ -8306,93 +8383,6 @@ function createDOMPurify() {
8306
8383
  }
8307
8384
  var purify_default = createDOMPurify();
8308
8385
  //#endregion
8309
- //#region ../../packages/react/src/components/mathjaxStyles.ts
8310
- var MATHJAX_STYLES = `
8311
- :scope {
8312
- display: contents;
8313
- }
8314
- :scope mjx-container[jax="SVG"] {
8315
- direction: ltr;
8316
- position: relative;
8317
- }
8318
- :scope mjx-container[jax="SVG"] > svg {
8319
- /* WebKit ignores overflow-clip-margin and clips at the SVG box. */
8320
- overflow: clip;
8321
- overflow-clip-margin: 1em;
8322
- min-height: 1px;
8323
- min-width: 1px;
8324
- }
8325
- :scope mjx-container[jax="SVG"] > svg a {
8326
- fill: blue;
8327
- stroke: blue;
8328
- }
8329
- :scope mjx-assistive-mml {
8330
- top: 0px;
8331
- left: 0px;
8332
- clip: rect(1px, 1px, 1px, 1px) !important;
8333
- user-select: text !important;
8334
- position: absolute !important;
8335
- padding: 1px 0px 0px !important;
8336
- border: 0px !important;
8337
- display: block !important;
8338
- width: auto !important;
8339
- overflow: hidden !important;
8340
- }
8341
- :scope mjx-assistive-mml[display="block"] {
8342
- width: 100% !important;
8343
- }
8344
- :scope mjx-container[jax="SVG"][display="true"] {
8345
- display: block;
8346
- text-align: center;
8347
- margin: 1em 0px;
8348
- }
8349
- :scope mjx-container[jax="SVG"][display="true"][width="full"] {
8350
- display: flex;
8351
- }
8352
- :scope mjx-container[jax="SVG"][justify="left"] {
8353
- text-align: left;
8354
- }
8355
- :scope mjx-container[jax="SVG"][justify="right"] {
8356
- text-align: right;
8357
- }
8358
- :scope g[data-mml-node="merror"] > g {
8359
- fill: red;
8360
- stroke: red;
8361
- }
8362
- :scope g[data-mml-node="merror"] > rect[data-background] {
8363
- fill: yellow;
8364
- stroke: none;
8365
- }
8366
- :scope g[data-mml-node="mtable"] > line[data-line], :scope svg[data-table] > g > line[data-line] {
8367
- stroke-width: 70px;
8368
- fill: none;
8369
- }
8370
- :scope g[data-mml-node="mtable"] > rect[data-frame], :scope svg[data-table] > g > rect[data-frame] {
8371
- stroke-width: 70px;
8372
- fill: none;
8373
- }
8374
- :scope g[data-mml-node="mtable"] > .mjx-dashed, :scope svg[data-table] > g > .mjx-dashed {
8375
- stroke-dasharray: 140;
8376
- }
8377
- :scope g[data-mml-node="mtable"] > .mjx-dotted, :scope svg[data-table] > g > .mjx-dotted {
8378
- stroke-linecap: round;
8379
- stroke-dasharray: 0, 140;
8380
- }
8381
- :scope g[data-mml-node="mtable"] > g > svg {
8382
- overflow: visible;
8383
- }
8384
- :scope g[data-mml-node="maction"][data-toggle] {
8385
- cursor: pointer;
8386
- }
8387
- :scope mjx-container[jax="SVG"] path[data-c], :scope mjx-container[jax="SVG"] use[data-c] {
8388
- stroke-width: 3;
8389
- }
8390
- :scope g[data-mml-node="xypic"] path {
8391
- stroke-width: inherit;
8392
- }
8393
- `;
8394
- var mathJaxStyles = (scopeId) => MATHJAX_STYLES.replaceAll(":scope", `#${scopeId}`).trim();
8395
- //#endregion
8396
8386
  //#region ../../packages/react/src/components/renderedHtmlSanitizer.ts
8397
8387
  var FORBIDDEN_TAGS = [
8398
8388
  "animate",
@@ -8417,15 +8407,12 @@ var FORBIDDEN_TAGS = [
8417
8407
  "select",
8418
8408
  "set",
8419
8409
  "source",
8410
+ "style",
8420
8411
  "textarea",
8421
8412
  "track",
8422
8413
  "video"
8423
8414
  ];
8424
- var MATHJAX_TAGS = [
8425
- "mjx-assistive-mml",
8426
- "mjx-container",
8427
- "style"
8428
- ];
8415
+ var MATHJAX_TAGS = ["mjx-assistive-mml", "mjx-container"];
8429
8416
  var MATHJAX_ATTRS = [
8430
8417
  "display",
8431
8418
  "focusable",
@@ -8501,7 +8488,6 @@ var SAFE_CSS_FUNCTIONS = /* @__PURE__ */ new Set([
8501
8488
  ]);
8502
8489
  var UNSAFE_CSS_PATTERN = /@import|behavior\s*:|binding\s*:|expression\s*\(|javascript\s*:|vbscript\s*:|url\s*\(/i;
8503
8490
  var RAW_CSS_REJECT_PATTERN = /[\\@<]/;
8504
- var MATHJAX_WRAPPER_ID = /^mjx-[a-f0-9]+$/i;
8505
8491
  var PURIFY_CONFIG = {
8506
8492
  ADD_ATTR: [...MATHJAX_ATTRS, "target"],
8507
8493
  ADD_DATA_URI_TAGS: ["img"],
@@ -8537,12 +8523,6 @@ var getPurify = () => {
8537
8523
  var installHooks = (purify) => {
8538
8524
  if (hooksInstalled) return;
8539
8525
  hooksInstalled = true;
8540
- purify.addHook("uponSanitizeElement", (node, hookEvent) => {
8541
- if (hookEvent.tagName !== "style" || !(node instanceof Element)) return;
8542
- const css = sanitizeMathJaxStyleElement(node);
8543
- if (css) node.textContent = css;
8544
- else node.remove();
8545
- });
8546
8526
  purify.addHook("uponSanitizeAttribute", (node, hookEvent) => {
8547
8527
  if (hookEvent.attrName === "style") {
8548
8528
  if (node.tagName.toLowerCase() === "mjx-assistive-mml") {
@@ -8629,13 +8609,7 @@ var isSafeStyleValue = (property, value) => {
8629
8609
  if (property.startsWith("margin") && /(?:^|\s)-/.test(value)) return false;
8630
8610
  return true;
8631
8611
  };
8632
- var sanitizeMathJaxStyleElement = (element) => {
8633
- const parent = element.parentElement;
8634
- const scopeId = parent?.getAttribute("id") ?? "";
8635
- if (parent?.tagName.toLowerCase() !== "span" || !MATHJAX_WRAPPER_ID.test(scopeId)) return "";
8636
- return mathJaxStyles(scopeId);
8637
- };
8638
8612
  //#endregion
8639
8613
  export { renderMarkdown, sanitizeRenderedHtml, truncateMarkdown };
8640
8614
 
8641
- //# sourceMappingURL=markdownPipeline-C_z-iU9a.js.map
8615
+ //# sourceMappingURL=markdownPipeline-bhdCQvtQ.js.map