@lango-project/lango-client 0.4.1 → 0.4.2

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 (65) hide show
  1. package/README.md +26 -0
  2. package/cli/.lango/runtime.mjs +16 -0
  3. package/dist/.lango/runtime.mjs +16 -0
  4. package/dist/accordion.mjs +9 -8
  5. package/dist/accordion.mjs.map +1 -1
  6. package/dist/activities.mjs +8 -7
  7. package/dist/activities.mjs.map +1 -1
  8. package/dist/app.mjs +465 -50
  9. package/dist/app.mjs.map +1 -1
  10. package/dist/boot.mjs +3 -2
  11. package/dist/boot.mjs.map +1 -1
  12. package/dist/button.mjs +8 -7
  13. package/dist/button.mjs.map +1 -1
  14. package/dist/chip.mjs +5 -4
  15. package/dist/chip.mjs.map +1 -1
  16. package/dist/combo_box.mjs +15 -14
  17. package/dist/combo_box.mjs.map +1 -1
  18. package/dist/content.mjs +9 -8
  19. package/dist/content.mjs.map +1 -1
  20. package/dist/date_input.mjs +3 -2
  21. package/dist/date_input.mjs.map +1 -1
  22. package/dist/error_reporter.mjs +6 -5
  23. package/dist/error_reporter.mjs.map +1 -1
  24. package/dist/fields.mjs +9 -8
  25. package/dist/fields.mjs.map +1 -1
  26. package/dist/file_input.mjs +19 -18
  27. package/dist/file_input.mjs.map +1 -1
  28. package/dist/form.mjs +14 -2
  29. package/dist/form.mjs.map +1 -1
  30. package/dist/heartbeat.mjs +12 -11
  31. package/dist/heartbeat.mjs.map +1 -1
  32. package/dist/input_changes.mjs +5 -4
  33. package/dist/input_changes.mjs.map +1 -1
  34. package/dist/longpoll.mjs +12 -11
  35. package/dist/longpoll.mjs.map +1 -1
  36. package/dist/main.mjs +35 -18
  37. package/dist/main.mjs.map +1 -1
  38. package/dist/menus.mjs +19 -18
  39. package/dist/menus.mjs.map +1 -1
  40. package/dist/navigation.mjs +7 -6
  41. package/dist/navigation.mjs.map +1 -1
  42. package/dist/numeric_input.mjs +9 -8
  43. package/dist/numeric_input.mjs.map +1 -1
  44. package/dist/otp_input.mjs +5 -4
  45. package/dist/otp_input.mjs.map +1 -1
  46. package/dist/presentations.mjs +17 -16
  47. package/dist/presentations.mjs.map +1 -1
  48. package/dist/renderer.mjs +74 -0
  49. package/dist/renderer.mjs.map +1 -1
  50. package/dist/table_scope.mjs +3 -2
  51. package/dist/table_scope.mjs.map +1 -1
  52. package/dist/tables.mjs +11 -10
  53. package/dist/tables.mjs.map +1 -1
  54. package/dist/tabs.mjs +7 -6
  55. package/dist/tabs.mjs.map +1 -1
  56. package/dist/vendor/dompurify.mjs +267 -181
  57. package/dist/vendor/purify.es.mjs.map +1 -1
  58. package/dist/widgets.mjs +5 -4
  59. package/dist/widgets.mjs.map +1 -1
  60. package/package.json +4 -3
  61. package/src/app.lango +325 -11
  62. package/src/form.lango +12 -2
  63. package/src/heartbeat.lango +2 -2
  64. package/src/main.lango +15 -0
  65. package/src/renderer.lango +61 -0
@@ -1,4 +1,4 @@
1
- /*! @license DOMPurify 3.4.18 | (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.18/LICENSE */
1
+ /*! @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 */
2
2
  function _OverloadYield(e, d) {
3
3
  this.v = e, this.k = d;
4
4
  }
@@ -93,7 +93,6 @@ AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator ||
93
93
  return this._invoke("return", e);
94
94
  };
95
95
  const entries = Object.entries;
96
- const objectKeys = Object.keys;
97
96
  const setPrototypeOf = Object.setPrototypeOf;
98
97
  const isFrozen = Object.isFrozen;
99
98
  const getPrototypeOf = Object.getPrototypeOf;
@@ -119,6 +118,7 @@ if (!construct) construct = function construct(Func) {
119
118
  return new Func(...args);
120
119
  };
121
120
  const arrayForEach = unapply(Array.prototype.forEach);
121
+ Array.prototype.indexOf;
122
122
  const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
123
123
  const arrayPop = unapply(Array.prototype.pop);
124
124
  const arrayPush = unapply(Array.prototype.push);
@@ -140,11 +140,7 @@ const bigintToString = typeof BigInt === "undefined" ? null : unapply(BigInt.pro
140
140
  const symbolToString = typeof Symbol === "undefined" ? null : unapply(Symbol.prototype.toString);
141
141
  const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
142
142
  const objectToString = unapply(Object.prototype.toString);
143
- const regExpTestRaw = RegExp.prototype.test;
144
- const regExpTest = function regExpTest(regExp, value) {
145
- if (regExp instanceof RegExp) regExp.lastIndex = 0;
146
- return apply(regExpTestRaw, regExp, [value]);
147
- };
143
+ const regExpTest = unapply(RegExp.prototype.test);
148
144
  const typeErrorCreate = unconstruct(TypeError);
149
145
  /**
150
146
  * Creates a new function that calls the given function with a specified thisArg and arguments.
@@ -154,6 +150,7 @@ const typeErrorCreate = unconstruct(TypeError);
154
150
  */
155
151
  function unapply(func) {
156
152
  return function(thisArg) {
153
+ if (thisArg instanceof RegExp) thisArg.lastIndex = 0;
157
154
  for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) args[_key3 - 1] = arguments[_key3];
158
155
  return apply(func, thisArg, args);
159
156
  };
@@ -227,19 +224,6 @@ function clone(object) {
227
224
  return newObject;
228
225
  }
229
226
  /**
230
- * Copy a flat lookup table
231
- *
232
- * @param set - The set to copy.
233
- * @returns A new prototype-free set with the same entries.
234
- */
235
- function cloneSet(set) {
236
- const newSet = create(null);
237
- const keys = objectKeys(set);
238
- let l = keys.length;
239
- while (l--) newSet[keys[l]] = set[keys[l]];
240
- return newSet;
241
- }
242
- /**
243
227
  * Convert non-node values into strings without depending on direct property access.
244
228
  *
245
229
  * @param value - The value to stringify.
@@ -308,7 +292,6 @@ function lookupAccessor(object, prop) {
308
292
  return null;
309
293
  }
310
294
  function isRegex(value) {
311
- if (!value) return false;
312
295
  try {
313
296
  regExpTest(value, "");
314
297
  return true;
@@ -451,6 +434,8 @@ const svg$1 = freeze([
451
434
  "defs",
452
435
  "desc",
453
436
  "ellipse",
437
+ "enterkeyhint",
438
+ "exportparts",
454
439
  "filter",
455
440
  "font",
456
441
  "g",
@@ -458,12 +443,14 @@ const svg$1 = freeze([
458
443
  "glyphref",
459
444
  "hkern",
460
445
  "image",
446
+ "inputmode",
461
447
  "line",
462
448
  "lineargradient",
463
449
  "marker",
464
450
  "mask",
465
451
  "metadata",
466
452
  "mpath",
453
+ "part",
467
454
  "path",
468
455
  "pattern",
469
456
  "polygon",
@@ -963,7 +950,6 @@ const xml = freeze([
963
950
  const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
964
951
  const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
965
952
  const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
966
- const TMPL_MARKER_SERIALIZED = seal(/{{|}}|\${|<%|%>|&lt;%|%&gt;/);
967
953
  const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
968
954
  const ARIA_ATTR = seal(/^aria-[\-\w]+$/);
969
955
  const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
@@ -975,15 +961,19 @@ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
975
961
  const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
976
962
  const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
977
963
  const SELF_CLOSING_TAG = seal(/\/>/i);
978
- const ATTR_VALUE_BREAKOUT = seal(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i);
979
- const LEADING_WHITESPACE = seal(/^[\r\n\t ]+/);
980
964
  const NODE_TYPE = {
981
965
  element: 1,
966
+ attribute: 2,
982
967
  text: 3,
968
+ cdataSection: 4,
969
+ entityReference: 5,
970
+ entityNode: 6,
983
971
  processingInstruction: 7,
984
972
  comment: 8,
985
973
  document: 9,
986
- documentFragment: 11
974
+ documentType: 10,
975
+ documentFragment: 11,
976
+ notation: 12
987
977
  };
988
978
  const LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, [
989
979
  "style",
@@ -1040,33 +1030,39 @@ const _createHooksMap = function _createHooksMap() {
1040
1030
  };
1041
1031
  };
1042
1032
  /**
1043
- * Resolve a set-valued configuration option.
1033
+ * Resolve a set-valued configuration option: a fresh set built from
1034
+ * cfg[key] when it is an own array property (seeded with a clone of
1035
+ * options.base when given, case-normalized via options.transform),
1036
+ * the fallback set otherwise.
1044
1037
  *
1045
1038
  * @param cfg the cloned, prototype-free configuration object
1046
1039
  * @param key the configuration property to read
1047
1040
  * @param fallback the set to use when the option is absent or not an array
1048
- * @param options case transform, and an optional base set to extend a copy of
1049
- * @returns a fresh set built from cfg[key], or the fallback
1041
+ * @param options transform and optional base set to merge into
1042
+ * @returns the resolved set
1050
1043
  */
1051
1044
  const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
1052
- return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? cloneSet(options.base) : {}, cfg[key], options.transform) : fallback;
1045
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
1053
1046
  };
1054
1047
  /**
1055
- * Resolve an object-valued configuration option.
1048
+ * Resolve an object-valued configuration option: a prototype-free clone
1049
+ * of cfg[key] when it is an own, truthy object property, else a fresh
1050
+ * fallback built by makeFallback (fresh on every parse, so a previous
1051
+ * parse can never leak state into the next one).
1056
1052
  *
1057
1053
  * @param cfg the cloned, prototype-free configuration object
1058
1054
  * @param key the configuration property to read
1059
- * @param fallback the read-only value to use when the option is absent
1060
- * @returns a prototype-free clone of cfg[key], or the fallback
1055
+ * @param makeFallback builds the fallback value when the option is absent
1056
+ * @returns the resolved object
1061
1057
  */
1062
- const _resolveObjectOption = function _resolveObjectOption(cfg, key, fallback) {
1058
+ const _resolveObjectOption = function _resolveObjectOption(cfg, key, makeFallback) {
1063
1059
  const value = objectHasOwnProperty(cfg, key) ? cfg[key] : void 0;
1064
- return value && typeof value === "object" ? clone(value) : fallback;
1060
+ return value && typeof value === "object" ? clone(value) : makeFallback();
1065
1061
  };
1066
1062
  function createDOMPurify() {
1067
1063
  let window = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
1068
1064
  const DOMPurify = (root) => createDOMPurify(root);
1069
- DOMPurify.version = "3.4.18";
1065
+ DOMPurify.version = "3.4.17";
1070
1066
  DOMPurify.removed = [];
1071
1067
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
1072
1068
  DOMPurify.isSupported = false;
@@ -1075,7 +1071,11 @@ function createDOMPurify() {
1075
1071
  let document = window.document;
1076
1072
  const originalDocument = document;
1077
1073
  const currentScript = originalDocument.currentScript;
1078
- const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter, DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
1074
+ window.DocumentFragment;
1075
+ const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter;
1076
+ window.NamedNodeMap === void 0 && (window.NamedNodeMap || window.MozNamedAttrMap);
1077
+ window.HTMLFormElement;
1078
+ const DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
1079
1079
  const ElementPrototype = Element.prototype;
1080
1080
  const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
1081
1081
  const remove = lookupGetter(ElementPrototype, "remove");
@@ -1119,9 +1119,6 @@ function createDOMPurify() {
1119
1119
  IN_TRUSTED_TYPES_POLICY--;
1120
1120
  }
1121
1121
  };
1122
- const _signOutput = function _signOutput(html) {
1123
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(html) : html;
1124
- };
1125
1122
  const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
1126
1123
  _assertNotInTrustedTypesPolicy();
1127
1124
  IN_TRUSTED_TYPES_POLICY++;
@@ -1166,7 +1163,26 @@ function createDOMPurify() {
1166
1163
  ...mathMl,
1167
1164
  ...xml
1168
1165
  ]);
1169
- let CUSTOM_ELEMENT_HANDLING = null;
1166
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
1167
+ tagNameCheck: {
1168
+ writable: true,
1169
+ configurable: false,
1170
+ enumerable: true,
1171
+ value: null
1172
+ },
1173
+ attributeNameCheck: {
1174
+ writable: true,
1175
+ configurable: false,
1176
+ enumerable: true,
1177
+ value: null
1178
+ },
1179
+ allowCustomizedBuiltInElements: {
1180
+ writable: true,
1181
+ configurable: false,
1182
+ enumerable: true,
1183
+ value: false
1184
+ }
1185
+ }));
1170
1186
  let FORBID_TAGS = null;
1171
1187
  let FORBID_ATTR = null;
1172
1188
  const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
@@ -1203,7 +1219,7 @@ function createDOMPurify() {
1203
1219
  let KEEP_CONTENT = true;
1204
1220
  let IN_PLACE = false;
1205
1221
  let IN_PLACE_VISITED = null;
1206
- let USE_PROFILES = false;
1222
+ let USE_PROFILES = {};
1207
1223
  let FORBID_CONTENTS = null;
1208
1224
  const DEFAULT_FORBID_CONTENTS = addToSet({}, [
1209
1225
  "annotation-xml",
@@ -1270,17 +1286,16 @@ function createDOMPurify() {
1270
1286
  SVG_NAMESPACE,
1271
1287
  HTML_NAMESPACE
1272
1288
  ], stringToString);
1273
- const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(addToSet({}, [
1289
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze([
1274
1290
  "mi",
1275
1291
  "mo",
1276
1292
  "mn",
1277
1293
  "ms",
1278
1294
  "mtext"
1279
- ]));
1280
- let MATHML_TEXT_INTEGRATION_POINTS = null;
1281
- const DEFAULT_HTML_INTEGRATION_POINTS = freeze(addToSet({}, ["annotation-xml"]));
1282
- let HTML_INTEGRATION_POINTS = null;
1283
- const DEFAULT_CUSTOM_ELEMENT_HANDLING = freeze(create(null));
1295
+ ]);
1296
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
1297
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(["annotation-xml"]);
1298
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
1284
1299
  const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
1285
1300
  "title",
1286
1301
  "style",
@@ -1304,6 +1319,7 @@ function createDOMPurify() {
1304
1319
  */
1305
1320
  const _parseConfig = function _parseConfig() {
1306
1321
  let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1322
+ if (CONFIG && CONFIG === cfg) return;
1307
1323
  if (!cfg || typeof cfg !== "object") cfg = {};
1308
1324
  cfg = clone(cfg);
1309
1325
  PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
@@ -1320,8 +1336,8 @@ function createDOMPurify() {
1320
1336
  base: DEFAULT_DATA_URI_TAGS
1321
1337
  });
1322
1338
  FORBID_CONTENTS = _resolveSetOption(cfg, "FORBID_CONTENTS", DEFAULT_FORBID_CONTENTS, { transform: transformCaseFunc });
1323
- FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", create(null), { transform: transformCaseFunc });
1324
- FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", create(null), { transform: transformCaseFunc });
1339
+ FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", clone({}), { transform: transformCaseFunc });
1340
+ FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", clone({}), { transform: transformCaseFunc });
1325
1341
  USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === "object" ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
1326
1342
  ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
1327
1343
  ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
@@ -1340,9 +1356,9 @@ function createDOMPurify() {
1340
1356
  IN_PLACE = cfg.IN_PLACE || false;
1341
1357
  IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI;
1342
1358
  NAMESPACE = typeof cfg.NAMESPACE === "string" ? cfg.NAMESPACE : HTML_NAMESPACE;
1343
- MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS", DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
1344
- HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS", DEFAULT_HTML_INTEGRATION_POINTS);
1345
- const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", DEFAULT_CUSTOM_ELEMENT_HANDLING);
1359
+ MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS));
1360
+ HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS));
1361
+ const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", () => create(null));
1346
1362
  CUSTOM_ELEMENT_HANDLING = create(null);
1347
1363
  if (objectHasOwnProperty(customElementHandling, "tagNameCheck") && isRegexOrFunction(customElementHandling.tagNameCheck)) CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck;
1348
1364
  if (objectHasOwnProperty(customElementHandling, "attributeNameCheck") && isRegexOrFunction(customElementHandling.attributeNameCheck)) CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck;
@@ -1351,7 +1367,6 @@ function createDOMPurify() {
1351
1367
  if (SAFE_FOR_TEMPLATES) ALLOW_DATA_ATTR = false;
1352
1368
  if (RETURN_DOM_FRAGMENT) RETURN_DOM = true;
1353
1369
  if (USE_PROFILES) {
1354
- if ((objectHasOwnProperty(cfg, "ALLOWED_TAGS") || objectHasOwnProperty(cfg, "ALLOWED_ATTR")) && typeof console !== "undefined" && typeof console.warn === "function") console.warn("DOMPurify: USE_PROFILES overrides ALLOWED_TAGS and ALLOWED_ATTR. Do not use these options together.");
1355
1370
  ALLOWED_TAGS = addToSet({}, text);
1356
1371
  ALLOWED_ATTR = create(null);
1357
1372
  if (USE_PROFILES.html === true) {
@@ -1379,19 +1394,19 @@ function createDOMPurify() {
1379
1394
  if (objectHasOwnProperty(cfg, "ADD_TAGS")) {
1380
1395
  if (typeof cfg.ADD_TAGS === "function") EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
1381
1396
  else if (arrayIsArray(cfg.ADD_TAGS)) {
1382
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = cloneSet(ALLOWED_TAGS);
1397
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = clone(ALLOWED_TAGS);
1383
1398
  addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
1384
1399
  }
1385
1400
  }
1386
1401
  if (objectHasOwnProperty(cfg, "ADD_ATTR")) {
1387
1402
  if (typeof cfg.ADD_ATTR === "function") EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
1388
1403
  else if (arrayIsArray(cfg.ADD_ATTR)) {
1389
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = cloneSet(ALLOWED_ATTR);
1404
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = clone(ALLOWED_ATTR);
1390
1405
  addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
1391
1406
  }
1392
1407
  }
1393
1408
  if (objectHasOwnProperty(cfg, "ADD_FORBID_CONTENTS") && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
1394
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = cloneSet(FORBID_CONTENTS);
1409
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = clone(FORBID_CONTENTS);
1395
1410
  addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
1396
1411
  }
1397
1412
  if (KEEP_CONTENT) ALLOWED_TAGS["#text"] = true;
@@ -1401,7 +1416,7 @@ function createDOMPurify() {
1401
1416
  "body"
1402
1417
  ]);
1403
1418
  if (ALLOWED_TAGS.table) {
1404
- ALLOWED_TAGS.tbody = true;
1419
+ addToSet(ALLOWED_TAGS, ["tbody"]);
1405
1420
  delete FORBID_TAGS.tbody;
1406
1421
  }
1407
1422
  if (cfg.TRUSTED_TYPES_POLICY) {
@@ -1422,7 +1437,8 @@ function createDOMPurify() {
1422
1437
  if (trustedTypesPolicy === void 0) trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
1423
1438
  if (trustedTypesPolicy && typeof emptyHTML === "string") emptyHTML = _createTrustedHTML("");
1424
1439
  }
1425
- CONFIG = freeze(cfg);
1440
+ if (freeze) freeze(cfg);
1441
+ CONFIG = cfg;
1426
1442
  };
1427
1443
  const ALL_SVG_TAGS = addToSet({}, [
1428
1444
  ...svg$1,
@@ -1434,39 +1450,39 @@ function createDOMPurify() {
1434
1450
  * Namespace rules for an element in the SVG namespace.
1435
1451
  *
1436
1452
  * @param tagName the element's lowercase tag name
1437
- * @param parentNamespace the (possibly simulated) parent's namespace
1453
+ * @param parent the (possibly simulated) parent node
1438
1454
  * @param parentTagName the parent's lowercase tag name
1439
1455
  * @returns true if a spec-compliant parser could produce this element
1440
1456
  */
1441
- const _checkSvgNamespace = function _checkSvgNamespace(tagName, parentNamespace, parentTagName) {
1442
- if (parentNamespace === HTML_NAMESPACE) return tagName === "svg";
1443
- if (parentNamespace === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1457
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
1458
+ if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "svg";
1459
+ if (parent.namespaceURI === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1444
1460
  return Boolean(ALL_SVG_TAGS[tagName]);
1445
1461
  };
1446
1462
  /**
1447
1463
  * Namespace rules for an element in the MathML namespace.
1448
1464
  *
1449
1465
  * @param tagName the element's lowercase tag name
1450
- * @param parentNamespace the (possibly simulated) parent's namespace
1466
+ * @param parent the (possibly simulated) parent node
1451
1467
  * @param parentTagName the parent's lowercase tag name
1452
1468
  * @returns true if a spec-compliant parser could produce this element
1453
1469
  */
1454
- const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parentNamespace, parentTagName) {
1455
- if (parentNamespace === HTML_NAMESPACE) return tagName === "math";
1456
- if (parentNamespace === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
1470
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
1471
+ if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "math";
1472
+ if (parent.namespaceURI === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
1457
1473
  return Boolean(ALL_MATHML_TAGS[tagName]);
1458
1474
  };
1459
1475
  /**
1460
1476
  * Namespace rules for an element in the HTML namespace.
1461
1477
  *
1462
1478
  * @param tagName the element's lowercase tag name
1463
- * @param parentNamespace the (possibly simulated) parent's namespace
1479
+ * @param parent the (possibly simulated) parent node
1464
1480
  * @param parentTagName the parent's lowercase tag name
1465
1481
  * @returns true if a spec-compliant parser could produce this element
1466
1482
  */
1467
- const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parentNamespace, parentTagName) {
1468
- if (parentNamespace === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
1469
- if (parentNamespace === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
1483
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
1484
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
1485
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
1470
1486
  return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1471
1487
  };
1472
1488
  /**
@@ -1479,17 +1495,21 @@ function createDOMPurify() {
1479
1495
  const elementNamespace = _readNamespaceURI(element);
1480
1496
  const tagName = stringToLowerCase(_readNodeName(element));
1481
1497
  const parentNode = getParentNode(element);
1482
- let parentNamespace = NAMESPACE;
1483
- let parentTagName = "template";
1498
+ let parent;
1499
+ let parentTagName;
1484
1500
  if (parentNode && _readNodeType(parentNode) === NODE_TYPE.element) {
1485
- parentNamespace = _readNamespaceURI(parentNode);
1501
+ parent = { namespaceURI: _readNamespaceURI(parentNode) };
1486
1502
  parentTagName = stringToLowerCase(_readNodeName(parentNode));
1503
+ } else {
1504
+ parent = { namespaceURI: NAMESPACE };
1505
+ parentTagName = "template";
1487
1506
  }
1488
1507
  if (!ALLOWED_NAMESPACES[elementNamespace]) return false;
1489
- if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parentNamespace, parentTagName);
1490
- if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parentNamespace, parentTagName);
1491
- if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parentNamespace, parentTagName);
1492
- return PARSER_MEDIA_TYPE === "application/xhtml+xml";
1508
+ if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parent, parentTagName);
1509
+ if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parent, parentTagName);
1510
+ if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parent, parentTagName);
1511
+ if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[elementNamespace]) return true;
1512
+ return false;
1493
1513
  };
1494
1514
  /**
1495
1515
  * _forceRemove
@@ -1506,10 +1526,17 @@ function createDOMPurify() {
1506
1526
  }
1507
1527
  };
1508
1528
  /**
1509
- * Removes an Attr node as that exact node, without book-keeping. Name-based
1510
- * removal lowercases the name in HTML documents and would miss a
1511
- * case-preserved one such as `ONERROR`, so it is only the fallback for
1512
- * clobbered or detached nodes.
1529
+ * _stripAttributeNode
1530
+ *
1531
+ * Remove a single Attr node case/namespace-exactly on an attribute-teardown
1532
+ * path. Name-based removeAttribute() ASCII-lowercases its lookup key for an
1533
+ * HTML element in an HTML document and so silently misses a case-preserved
1534
+ * handler (e.g. `ONERROR` off an XML/XHTML import) - the same defect
1535
+ * _removeAttribute() was fixed for, which a name-based call would reintroduce
1536
+ * on these IN_PLACE teardown paths. Unlike _removeAttribute this does not
1537
+ * record into DOMPurify.removed: the neutralize passes intentionally do not
1538
+ * book-keep. A clobbered/detached node falls back to best-effort name-based
1539
+ * removal.
1513
1540
  *
1514
1541
  * @param element the element to strip the attribute from
1515
1542
  * @param attribute the Attr node to remove
@@ -1539,7 +1566,12 @@ function createDOMPurify() {
1539
1566
  remove(child);
1540
1567
  } catch (_) {}
1541
1568
  });
1542
- if (_readNodeType(root) === NODE_TYPE.element) _stripAttributes(root, false);
1569
+ const attributes = _readNodeType(root) === NODE_TYPE.element ? getAttributes(root) : null;
1570
+ if (attributes) for (let i = attributes.length - 1; i >= 0; --i) {
1571
+ const attribute = attributes[i];
1572
+ const name = attribute && attribute.name;
1573
+ if (typeof name === "string") _stripAttributeNode(root, attribute, name);
1574
+ }
1543
1575
  };
1544
1576
  /**
1545
1577
  * Removes an attribute, preferably as its exact Attr node: name-based
@@ -1560,10 +1592,14 @@ function createDOMPurify() {
1560
1592
  attribute: attr || null,
1561
1593
  from: element
1562
1594
  });
1563
- if (attr) _stripAttributeNode(element, attr, name);
1564
- else try {
1565
- element.removeAttribute(name);
1566
- } catch (_) {}
1595
+ try {
1596
+ if (attr) removeAttributeNode(element, attr);
1597
+ else element.removeAttribute(name);
1598
+ } catch (_) {
1599
+ try {
1600
+ element.removeAttribute(name);
1601
+ } catch (_) {}
1602
+ }
1567
1603
  if (name === "is") {
1568
1604
  if (RETURN_DOM || RETURN_DOM_FRAGMENT) try {
1569
1605
  _forceRemove(element);
@@ -1574,19 +1610,19 @@ function createDOMPurify() {
1574
1610
  }
1575
1611
  };
1576
1612
  /**
1577
- * Removes an element's attributes without book-keeping. Used to neutralize
1578
- * nodes discarded from an in-place tree.
1613
+ * Removes every attribute the configuration does not allow. Used to
1614
+ * neutralize nodes discarded from an in-place tree.
1579
1615
  *
1580
1616
  * @param element the element to strip
1581
- * @param keepAllowed whether attributes on the allowlist stay
1582
1617
  */
1583
- const _stripAttributes = function _stripAttributes(element, keepAllowed) {
1618
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
1584
1619
  const attributes = getAttributes(element);
1585
1620
  if (!attributes) return;
1586
1621
  for (let i = attributes.length - 1; i >= 0; --i) {
1587
1622
  const attribute = attributes[i];
1588
1623
  const name = attribute && attribute.name;
1589
- if (typeof name === "string" && !(keepAllowed && ALLOWED_ATTR[transformCaseFunc(name)])) _stripAttributeNode(element, attribute, name);
1624
+ if (typeof name !== "string" || ALLOWED_ATTR[transformCaseFunc(name)]) continue;
1625
+ _stripAttributeNode(element, attribute, name);
1590
1626
  }
1591
1627
  };
1592
1628
  /**
@@ -1621,7 +1657,7 @@ function createDOMPurify() {
1621
1657
  */
1622
1658
  const _neutralizeSubtree = function _neutralizeSubtree(root) {
1623
1659
  _walkTree(root, (node) => {
1624
- if (_readNodeType(node) === NODE_TYPE.element) _stripAttributes(node, true);
1660
+ if (_readNodeType(node) === NODE_TYPE.element) _stripDisallowedAttributes(node);
1625
1661
  });
1626
1662
  };
1627
1663
  /**
@@ -1652,7 +1688,7 @@ function createDOMPurify() {
1652
1688
  if (_readNodeType(node) === NODE_TYPE.element) setAdd(reachable, node);
1653
1689
  });
1654
1690
  arrayForEach(before, (node) => {
1655
- if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node)) _stripAttributes(node, true);
1691
+ if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node)) _stripDisallowedAttributes(node);
1656
1692
  });
1657
1693
  };
1658
1694
  /**
@@ -1725,7 +1761,9 @@ function createDOMPurify() {
1725
1761
  while (node = iterator.nextNode()) {
1726
1762
  if (!setHas(original, node) || setHas(IN_PLACE_VISITED, node)) continue;
1727
1763
  if (inShadow) _executeHooks(hooks.uponSanitizeShadowNode, node, null);
1728
- _sanitizeNode(node, root);
1764
+ _sanitizeElements(node, root);
1765
+ _sanitizeAttributes(node, root);
1766
+ if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
1729
1767
  }
1730
1768
  };
1731
1769
  /**
@@ -1757,7 +1795,7 @@ function createDOMPurify() {
1757
1795
  * and strips linkage attributes. It cannot undo a patch that already fired.
1758
1796
  *
1759
1797
  * TODO: if the shipped feature can patch through `for` on <label>/<output>,
1760
- * drop that pair here too.
1798
+ * drop that pair here too (see test/declarative-patch-probe.html).
1761
1799
  *
1762
1800
  * @param root the in-place root to sweep
1763
1801
  */
@@ -1793,7 +1831,7 @@ function createDOMPurify() {
1793
1831
  let leadingWhitespace = null;
1794
1832
  if (FORCE_BODY) dirty = "<remove></remove>" + dirty;
1795
1833
  else {
1796
- const matches = stringMatch(dirty, LEADING_WHITESPACE);
1834
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
1797
1835
  leadingWhitespace = matches && matches[0];
1798
1836
  }
1799
1837
  if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) dirty = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body>" + dirty + "</body></html>";
@@ -1813,18 +1851,14 @@ function createDOMPurify() {
1813
1851
  return WHOLE_DOCUMENT ? doc.documentElement : body;
1814
1852
  };
1815
1853
  /**
1816
- * Creates a NodeIterator over `root`. ownerDocument is read through the
1817
- * cached getter: a form child named "ownerDocument" shadows the direct
1818
- * read and would make createNodeIterator throw.
1854
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
1819
1855
  *
1820
- * @param root The node to start traversing on.
1821
- * @param characterDataOnly whether to skip elements
1856
+ * @param root The root element or node to start traversing on.
1822
1857
  * @return The created NodeIterator
1823
1858
  */
1824
1859
  const _createNodeIterator = function _createNodeIterator(root) {
1825
- let characterDataOnly = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1826
1860
  const doc = getOwnerDocument ? getOwnerDocument(root) : root.ownerDocument;
1827
- return createNodeIterator.call(doc || root, root, (characterDataOnly ? 0 : NodeFilter.SHOW_ELEMENT) | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
1861
+ return createNodeIterator.call(doc || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
1828
1862
  };
1829
1863
  /**
1830
1864
  * Replace template expression syntax (mustache, ERB, template
@@ -1841,11 +1875,21 @@ function createDOMPurify() {
1841
1875
  return value;
1842
1876
  };
1843
1877
  /**
1844
- * Strips template expressions from the character data under `node`,
1845
- * template contents included. Runs after the walk, since an expression can
1846
- * also form when a removed element leaves two text nodes adjacent. Works on
1847
- * the nodes rather than on markup, which keeps node references intact and
1848
- * sees `<%` unescaped. Attribute values are handled in _sanitizeAttributes.
1878
+ * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
1879
+ * character data of an element subtree. Used as the final safety net for
1880
+ * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
1881
+ * which only form after text-node normalization (e.g. fragments split across
1882
+ * stripped elements) cannot survive into a template-evaluating framework.
1883
+ *
1884
+ * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
1885
+ * in place rather than round-tripping through innerHTML. This preserves
1886
+ * descendant node references (important for IN_PLACE callers), avoids a
1887
+ * serialize/reparse cycle, and reads literal character data — which means
1888
+ * `<%...%>` in text content matches the ERB regex against its real bytes
1889
+ * instead of the HTML-entity-escaped form innerHTML would produce.
1890
+ *
1891
+ * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
1892
+ * attributes is performed during the per-node `_sanitizeAttributes` pass.
1849
1893
  *
1850
1894
  * @param node The root element whose character data should be scrubbed.
1851
1895
  */
@@ -1858,15 +1902,23 @@ function createDOMPurify() {
1858
1902
  });
1859
1903
  };
1860
1904
  /**
1861
- * Normalizes `node` and strips template expressions from its own character
1862
- * data. Template contents and shadow roots are not entered, their own
1863
- * _sanitizeShadowDOM call scrubs them.
1905
+ * _scrubOwnCharacterData
1906
+ *
1907
+ * Non-recursive core of _scrubTemplateExpressions: normalize `node` and
1908
+ * strip template expressions from its own character data only. Does not
1909
+ * enter <template>.content or attached shadow roots (NodeIterator never
1910
+ * does). Used by _sanitizeShadowDOM, where every nested template content
1911
+ * and shadow root is already walked - and therefore scrubbed - by its own
1912
+ * recursive _sanitizeShadowDOM call; recursing here as well would rescrub
1913
+ * each nested fragment once per ancestor, which is quadratic in nesting
1914
+ * depth.
1864
1915
  *
1865
1916
  * @param node The root whose own character data should be scrubbed.
1866
1917
  */
1867
1918
  const _scrubOwnCharacterData = function _scrubOwnCharacterData(node) {
1868
1919
  node.normalize();
1869
- const walker = _createNodeIterator(node, true);
1920
+ const doc = getOwnerDocument ? getOwnerDocument(node) : node.ownerDocument;
1921
+ const walker = createNodeIterator.call(doc || node, node, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
1870
1922
  let currentNode = walker.nextNode();
1871
1923
  while (currentNode) {
1872
1924
  currentNode.data = _stripTemplateExpressions(currentNode.data);
@@ -1874,9 +1926,13 @@ function createDOMPurify() {
1874
1926
  }
1875
1927
  };
1876
1928
  /**
1877
- * Detects DOM clobbering on a form, the only element whose named children
1878
- * shadow its own properties. Each probe compares a direct read with what
1879
- * the property has to be.
1929
+ * _isClobbered
1930
+ *
1931
+ * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
1932
+ * interface with [LegacyOverrideBuiltIns]; a descendant element with a
1933
+ * `name` attribute matching a prototype property shadows that property
1934
+ * on direct reads. We use this check at the IN_PLACE entry-point and
1935
+ * during attribute sanitization to refuse clobbered forms.
1880
1936
  *
1881
1937
  * @param element element to check for clobbering attacks
1882
1938
  * @return true if clobbered, false if safe
@@ -1888,26 +1944,42 @@ function createDOMPurify() {
1888
1944
  return typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || element.attributes !== getAttributes(element) || typeof element.removeAttribute !== "function" || typeof element.removeAttributeNode !== "function" || typeof element.getAttributeNode !== "function" || typeof element.setAttribute !== "function" || typeof element.namespaceURI !== "string" || typeof element.insertBefore !== "function" || typeof element.hasChildNodes !== "function" || element.nodeType !== getNodeType(element) || element.childNodes !== getChildNodes(element);
1889
1945
  };
1890
1946
  /**
1891
- * Reads nodeType through the cached getter, so the result holds for nodes
1892
- * from any realm (GHSA-4w3q-35jp-p934) and cannot be clobbered.
1947
+ * Checks whether the given value is a DocumentFragment from any realm.
1893
1948
  *
1894
- * @param value anything
1895
- * @return the node type, or null if value is not a DOM node
1949
+ * The realm-independent replacement reads `nodeType` through the cached
1950
+ * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
1951
+ * constant (11). nodeType is a numeric value resolved from the node's
1952
+ * internal slot, identical across realms for the same kind of node.
1953
+ *
1954
+ * @param value object to check
1955
+ * @return true if value is a DocumentFragment-shaped node from any realm
1896
1956
  */
1897
- const _nodeTypeOf = function _nodeTypeOf(value) {
1898
- if (!getNodeType || typeof value !== "object" || value === null) return null;
1957
+ const _isDocumentFragment = function _isDocumentFragment(value) {
1958
+ if (!getNodeType || typeof value !== "object" || value === null) return false;
1899
1959
  try {
1900
- const nodeType = getNodeType(value);
1901
- return typeof nodeType === "number" ? nodeType : null;
1960
+ return getNodeType(value) === NODE_TYPE.documentFragment;
1902
1961
  } catch (_) {
1903
- return null;
1962
+ return false;
1904
1963
  }
1905
1964
  };
1906
- const _isDocumentFragment = function _isDocumentFragment(value) {
1907
- return _nodeTypeOf(value) === NODE_TYPE.documentFragment;
1908
- };
1965
+ /**
1966
+ * Checks whether the given object is a DOM node, including nodes that
1967
+ * originate from a different window/realm (e.g. an iframe's
1968
+ * contentDocument). The previous `value instanceof Node` check was
1969
+ * realm-bound: nodes from a different window failed it, causing
1970
+ * sanitize() to silently stringify them and reset IN_PLACE to false,
1971
+ * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
1972
+ *
1973
+ * @param value object to check whether it's a DOM node
1974
+ * @return true if value is a DOM node from any realm
1975
+ */
1909
1976
  const _isNode = function _isNode(value) {
1910
- return _nodeTypeOf(value) !== null;
1977
+ if (!getNodeType || typeof value !== "object" || value === null) return false;
1978
+ try {
1979
+ return typeof getNodeType(value) === "number";
1980
+ } catch (_) {
1981
+ return false;
1982
+ }
1911
1983
  };
1912
1984
  function _executeHooks(hooks, currentNode, data) {
1913
1985
  if (hooks.length === 0) return;
@@ -1923,14 +1995,13 @@ function createDOMPurify() {
1923
1995
  *
1924
1996
  * @param currentNode the node to inspect
1925
1997
  * @param tagName the node's transformCaseFunc'd tag name
1926
- * @param nodeType the node's type, read through the cached getter
1927
1998
  * @return true if the node must be removed
1928
1999
  */
1929
- const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName, nodeType) {
1930
- if (SAFE_FOR_XML && nodeType === NODE_TYPE.element && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
1931
- if (SAFE_FOR_XML && LITERAL_TEXT_ELEMENTS[tagName] && nodeType === NODE_TYPE.element && _readNamespaceURI(currentNode) === HTML_NAMESPACE && (_isNode(currentNode.firstElementChild) || typeof currentNode.textContent === "string" && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent))) return true;
1932
- if (nodeType === NODE_TYPE.processingInstruction) return true;
1933
- if (SAFE_FOR_XML && nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
2000
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
2001
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
2002
+ 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;
2003
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) return true;
2004
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
1934
2005
  return false;
1935
2006
  };
1936
2007
  /**
@@ -1954,9 +2025,17 @@ function createDOMPurify() {
1954
2025
  return false;
1955
2026
  };
1956
2027
  /**
1957
- * Handles a node whose tag is forbidden or not allowlisted: hoists its
1958
- * content per KEEP_CONTENT and removes it. The one exception is a custom
1959
- * element allowed via CUSTOM_ELEMENT_HANDLING, which is kept.
2028
+ * Handle a node whose tag is forbidden or not allowlisted: keep
2029
+ * allowed custom elements (false return exits _sanitizeElements
2030
+ * early - the namespace and fallback-tag removal checks are
2031
+ * intentionally skipped for kept custom elements), else hoist
2032
+ * content per KEEP_CONTENT and remove.
2033
+ *
2034
+ * A kept custom element is the ONLY case in which this function
2035
+ * returns false, so the caller uses that return value to run the
2036
+ * afterSanitizeElements hook on the kept element and keep the
2037
+ * element-hook lifecycle consistent with normal allowlisted
2038
+ * elements (GHSA-c2j3-45gr-mqc4).
1960
2039
  *
1961
2040
  * @param currentNode the disallowed node
1962
2041
  * @param tagName the node's transformCaseFunc'd tag name
@@ -1979,9 +2058,11 @@ function createDOMPurify() {
1979
2058
  return true;
1980
2059
  };
1981
2060
  /**
1982
- * Forks an allowlist off its shared binding (the instance default or the
1983
- * setConfig() capture) before a hook sees it, so a hook's widening stays
1984
- * within the call. A set that is already call-local is returned as is.
2061
+ * Fork a hook-mutable allowlist off its shared binding the first time a
2062
+ * (possibly lazily-installed) uponSanitize* hook is about to see it, so the
2063
+ * hook cannot widen the per-instance default or the setConfig binding by
2064
+ * reference and leak past the call. Returns the set unchanged once it is
2065
+ * already call-local, so repeated calls across elements are idempotent.
1985
2066
  *
1986
2067
  * @param hookList the uponSanitize* hook array for this event
1987
2068
  * @param set the current ALLOWED_TAGS / ALLOWED_ATTR binding
@@ -1992,7 +2073,7 @@ function createDOMPurify() {
1992
2073
  */
1993
2074
  const _forkSharedAllowlist = function _forkSharedAllowlist(hookList, set, defaultSet, setConfigSet) {
1994
2075
  if (hookList.length === 0) return set;
1995
- return set === defaultSet || set === setConfigSet ? cloneSet(set) : set;
2076
+ return set === defaultSet || set === setConfigSet ? clone(set) : set;
1996
2077
  };
1997
2078
  /**
1998
2079
  * A hook may have detached the node it was called for. If so, treat it as
@@ -2026,14 +2107,13 @@ function createDOMPurify() {
2026
2107
  return true;
2027
2108
  }
2028
2109
  const tagName = transformCaseFunc(_readNodeName(currentNode));
2029
- const nodeType = _readNodeType(currentNode);
2030
2110
  ALLOWED_TAGS = _forkSharedAllowlist(hooks.uponSanitizeElement, ALLOWED_TAGS, DEFAULT_ALLOWED_TAGS, SET_CONFIG_ALLOWED_TAGS);
2031
2111
  _executeHooks(hooks.uponSanitizeElement, currentNode, {
2032
2112
  tagName,
2033
2113
  allowedTags: ALLOWED_TAGS
2034
2114
  });
2035
2115
  if (_handleHookDetachedNode(currentNode, root)) return true;
2036
- if (_isUnsafeNode(currentNode, tagName, nodeType)) {
2116
+ if (_isUnsafeNode(currentNode, tagName)) {
2037
2117
  _forceRemove(currentNode);
2038
2118
  return true;
2039
2119
  }
@@ -2045,7 +2125,7 @@ function createDOMPurify() {
2045
2125
  }
2046
2126
  return removed;
2047
2127
  }
2048
- if (nodeType === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
2128
+ if (_readNodeType(currentNode) === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
2049
2129
  _forceRemove(currentNode);
2050
2130
  return true;
2051
2131
  }
@@ -2053,10 +2133,9 @@ function createDOMPurify() {
2053
2133
  _forceRemove(currentNode);
2054
2134
  return true;
2055
2135
  }
2056
- if (SAFE_FOR_TEMPLATES && nodeType === NODE_TYPE.text) {
2057
- const text = currentNode.textContent;
2058
- const content = _stripTemplateExpressions(text);
2059
- if (text !== content) {
2136
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
2137
+ const content = _stripTemplateExpressions(currentNode.textContent);
2138
+ if (currentNode.textContent !== content) {
2060
2139
  arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
2061
2140
  currentNode.textContent = content;
2062
2141
  }
@@ -2081,10 +2160,9 @@ function createDOMPurify() {
2081
2160
  if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) return true;
2082
2161
  if (!nameIsPermitted) return _isBasicCustomElement(lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName, lcTag) || lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value);
2083
2162
  if (URI_SAFE_ATTRIBUTES[lcName]) return true;
2084
- const compactValue = stringReplace(value, ATTR_WHITESPACE$1, "");
2085
- if (regExpTest(IS_ALLOWED_URI$1, compactValue)) return true;
2163
+ if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
2086
2164
  if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) return true;
2087
- if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, compactValue)) return true;
2165
+ if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
2088
2166
  return !value;
2089
2167
  };
2090
2168
  const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, [
@@ -2128,8 +2206,21 @@ function createDOMPurify() {
2128
2206
  return value;
2129
2207
  };
2130
2208
  /**
2131
- * Writes a changed attribute value back. If the new value clobbers, the
2132
- * element is removed; if the write fails, the attribute is.
2209
+ * Write a modified attribute value back onto the element. On
2210
+ * success, re-probe for clobbering introduced by the new value and
2211
+ * remove the element when found; otherwise, when this writeback is the
2212
+ * recreate half of the SANITIZE_NAMED_PROPS remove-and-recreate, pop the
2213
+ * removal entry that path recorded so it does not show as removed. On
2214
+ * failure, remove the attribute instead.
2215
+ *
2216
+ * Returns true only on a clean write (the value was set and the new value
2217
+ * introduced no clobbering). The caller uses that, together with its own
2218
+ * knowledge of whether this attribute pushed a DOMPurify.removed record, to
2219
+ * decide whether to pop that record. The pop must happen ONLY for the
2220
+ * named-prop remove-and-recreate; popping on any other value change (trim,
2221
+ * template scrubbing, Trusted Types) would consume an unrelated _forceRemove
2222
+ * subtree-cleanup record and let that detached subtree keep a live event
2223
+ * handler through the IN_PLACE neutralization pass (SO-001).
2133
2224
  *
2134
2225
  * @param currentNode the element carrying the attribute
2135
2226
  * @param name the attribute name as present on the element
@@ -2152,17 +2243,20 @@ function createDOMPurify() {
2152
2243
  }
2153
2244
  };
2154
2245
  /**
2155
- * Value checks that apply before a hook can force-keep an attribute. Also
2156
- * used by isValidAttribute(), so it never approves a value that sanitize()
2157
- * would strip.
2246
+ * _isUnsafeAttributeValue
2247
+ *
2248
+ * Value-based attribute checks that the attribute walk applies before any
2249
+ * hook can force-keep an attribute, shared with the public
2250
+ * isValidAttribute() so that it never approves a value sanitize() would
2251
+ * strip.
2158
2252
  *
2159
2253
  * @param name the attribute name as found on the node (case preserved)
2160
2254
  * @param value the attribute value
2161
2255
  * @returns true if the attribute must be removed because of its value
2162
2256
  */
2163
2257
  const _isUnsafeAttributeValue = function _isUnsafeAttributeValue(name, value) {
2164
- if (SAFE_FOR_XML && regExpTest(ATTR_VALUE_BREAKOUT, value)) return true;
2165
- return stringToLowerCase(name) === "attributename" && stringIndexOf(value, "href") !== -1;
2258
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) return true;
2259
+ return stringToLowerCase(name) === "attributename" && stringMatch(value, "href") !== null;
2166
2260
  };
2167
2261
  /**
2168
2262
  * _sanitizeAttributes
@@ -2189,7 +2283,7 @@ function createDOMPurify() {
2189
2283
  forceKeepAttr: void 0
2190
2284
  };
2191
2285
  let l = attributes.length;
2192
- const lcTag = transformCaseFunc(_readNodeName(currentNode));
2286
+ const lcTag = transformCaseFunc(currentNode.nodeName);
2193
2287
  while (l--) {
2194
2288
  const attr = attributes[l];
2195
2289
  const name = attr.name, namespaceURI = attr.namespaceURI, attrValue = attr.value;
@@ -2235,18 +2329,6 @@ function createDOMPurify() {
2235
2329
  _handleHookDetachedNode(currentNode, root);
2236
2330
  };
2237
2331
  /**
2238
- * Sanitizes one node: the node itself, its attributes and, for a
2239
- * template, its content.
2240
- *
2241
- * @param node the node to sanitize
2242
- * @param root the current walk root
2243
- */
2244
- const _sanitizeNode = function _sanitizeNode(node, root) {
2245
- _sanitizeElements(node, root);
2246
- _sanitizeAttributes(node, root);
2247
- if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
2248
- };
2249
- /**
2250
2332
  * _sanitizeShadowDOM
2251
2333
  *
2252
2334
  * @param fragment to iterate over recursively
@@ -2257,7 +2339,9 @@ function createDOMPurify() {
2257
2339
  _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
2258
2340
  while (shadowNode = shadowIterator.nextNode()) {
2259
2341
  _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
2260
- _sanitizeNode(shadowNode, fragment);
2342
+ _sanitizeElements(shadowNode, fragment);
2343
+ _sanitizeAttributes(shadowNode, fragment);
2344
+ if (_isDocumentFragment(shadowNode.content)) _sanitizeShadowDOM2(shadowNode.content);
2261
2345
  if (_readNodeType(shadowNode) === NODE_TYPE.element) {
2262
2346
  const innerSr = getShadowRoot(shadowNode);
2263
2347
  if (_isDocumentFragment(innerSr)) {
@@ -2333,6 +2417,8 @@ function createDOMPurify() {
2333
2417
  ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
2334
2418
  ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
2335
2419
  } else _parseConfig(cfg);
2420
+ if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) ALLOWED_TAGS = clone(ALLOWED_TAGS);
2421
+ if (hooks.uponSanitizeAttribute.length > 0) ALLOWED_ATTR = clone(ALLOWED_ATTR);
2336
2422
  DOMPurify.removed = [];
2337
2423
  const inPlace = IN_PLACE && typeof dirty !== "string" && _isNode(dirty);
2338
2424
  let inPlaceNodes = [];
@@ -2361,7 +2447,7 @@ function createDOMPurify() {
2361
2447
  else body.appendChild(importedNode);
2362
2448
  _sanitizeAttachedShadowRoots(body);
2363
2449
  } else {
2364
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return _signOutput(dirty);
2450
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
2365
2451
  body = _initDocument(dirty);
2366
2452
  if (!body) return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
2367
2453
  }
@@ -2370,7 +2456,11 @@ function createDOMPurify() {
2370
2456
  try {
2371
2457
  if (inPlace) _sanitizeAttachedShadowRoots(dirty);
2372
2458
  const nodeIterator = _createNodeIterator(walkRoot);
2373
- while (currentNode = nodeIterator.nextNode()) _sanitizeNode(currentNode, walkRoot);
2459
+ while (currentNode = nodeIterator.nextNode()) {
2460
+ _sanitizeElements(currentNode, walkRoot);
2461
+ _sanitizeAttributes(currentNode, walkRoot);
2462
+ if (_isDocumentFragment(currentNode.content)) _sanitizeShadowDOM2(currentNode.content);
2463
+ }
2374
2464
  if (inPlace) _sanitizeUnvisitedNodes(dirty, inPlaceNodes);
2375
2465
  } catch (error) {
2376
2466
  if (inPlace) {
@@ -2395,14 +2485,10 @@ function createDOMPurify() {
2395
2485
  if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) returnNode = importNode.call(originalDocument, returnNode, true);
2396
2486
  return returnNode;
2397
2487
  }
2398
- const serialize = () => WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
2399
- let serializedHTML = serialize();
2400
- if (SAFE_FOR_TEMPLATES && regExpTest(TMPL_MARKER_SERIALIZED, serializedHTML)) {
2401
- _scrubOwnCharacterData(body);
2402
- serializedHTML = serialize();
2403
- }
2488
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
2404
2489
  if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
2405
- return _signOutput(serializedHTML);
2490
+ if (SAFE_FOR_TEMPLATES) serializedHTML = _stripTemplateExpressions(serializedHTML);
2491
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
2406
2492
  };
2407
2493
  DOMPurify.setConfig = function() {
2408
2494
  let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};