@cjser/parse5 8.0.1-cjser.2 → 8.1.0-cjser.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.
@@ -16,10 +16,11 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/index.js
19
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/index.js
20
20
  var index_exports = {};
21
21
  __export(index_exports, {
22
22
  ErrorCodes: () => ERR,
23
+ InsertionMode: () => InsertionMode,
23
24
  Parser: () => Parser,
24
25
  Token: () => token_exports,
25
26
  Tokenizer: () => Tokenizer,
@@ -34,7 +35,7 @@ __export(index_exports, {
34
35
  });
35
36
  module.exports = __toCommonJS(index_exports);
36
37
 
37
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/common/unicode.js
38
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/common/unicode.js
38
39
  var UNDEFINED_CODE_POINTS = /* @__PURE__ */ new Set([
39
40
  65534,
40
41
  65535,
@@ -125,7 +126,7 @@ function isUndefinedCodePoint(cp) {
125
126
  return cp >= 64976 && cp <= 65007 || UNDEFINED_CODE_POINTS.has(cp);
126
127
  }
127
128
 
128
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/common/error-codes.js
129
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/common/error-codes.js
129
130
  var ERR;
130
131
  (function(ERR2) {
131
132
  ERR2["controlCharacterInInputStream"] = "control-character-in-input-stream";
@@ -190,7 +191,7 @@ var ERR;
190
191
  ERR2["eofInElementThatCanContainOnlyText"] = "eof-in-element-that-can-contain-only-text";
191
192
  })(ERR || (ERR = {}));
192
193
 
193
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/tokenizer/preprocessor.js
194
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/tokenizer/preprocessor.js
194
195
  var DEFAULT_BUFFER_WATERLINE = 1 << 16;
195
196
  var Preprocessor = class {
196
197
  constructor(handler) {
@@ -213,8 +214,13 @@ var Preprocessor = class {
213
214
  get col() {
214
215
  return this.pos - this.lineStartPos + Number(this.lastGapPos !== this.pos);
215
216
  }
217
+ /** The index in `html` at which the current code point starts (the high surrogate of a pair). */
218
+ get codePointStart() {
219
+ return this.pos - Number(this.lastGapPos === this.pos);
220
+ }
221
+ /** The offset of the current code point, before the second unit of a surrogate pair. */
216
222
  get offset() {
217
- return this.droppedBufferSize + this.pos;
223
+ return this.droppedBufferSize + this.codePointStart;
218
224
  }
219
225
  getError(code, cpOffset) {
220
226
  const { line, col, offset } = this;
@@ -260,12 +266,15 @@ var Preprocessor = class {
260
266
  }
261
267
  dropParsedChunk() {
262
268
  if (this.willDropParsedChunk()) {
263
- this.html = this.html.substring(this.pos);
264
- this.lineStartPos -= this.pos;
265
- this.droppedBufferSize += this.pos;
266
- this.pos = 0;
269
+ const droppedSize = this.offset - this.droppedBufferSize;
270
+ this.html = this.html.substring(droppedSize);
271
+ this.lineStartPos -= droppedSize;
272
+ this.droppedBufferSize += droppedSize;
273
+ this.pos -= droppedSize;
267
274
  this.lastGapPos = -2;
268
275
  this.gapStack.length = 0;
276
+ if (this.pos > 0)
277
+ this._addGap();
269
278
  }
270
279
  }
271
280
  write(chunk, isLastChunk) {
@@ -359,7 +368,7 @@ var Preprocessor = class {
359
368
  }
360
369
  };
361
370
 
362
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/common/token.js
371
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/common/token.js
363
372
  var token_exports = {};
364
373
  __export(token_exports, {
365
374
  TokenType: () => TokenType,
@@ -386,10 +395,10 @@ function getTokenAttr(token, attrName) {
386
395
  return null;
387
396
  }
388
397
 
389
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/tokenizer/index.js
398
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/tokenizer/index.js
390
399
  var import_decode = require("@cjser/entities/decode");
391
400
 
392
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/common/html.js
401
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/common/html.js
393
402
  var html_exports = {};
394
403
  __export(html_exports, {
395
404
  ATTRS: () => ATTRS,
@@ -915,7 +924,7 @@ function hasUnescapedText(tn, scriptingEnabled) {
915
924
  return UNESCAPED_TEXT.has(tn) || scriptingEnabled && tn === TAG_NAMES.NOSCRIPT;
916
925
  }
917
926
 
918
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/tokenizer/index.js
927
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/tokenizer/index.js
919
928
  var State;
920
929
  (function(State2) {
921
930
  State2[State2["DATA"] = 0] = "DATA";
@@ -1019,7 +1028,7 @@ function toAsciiLower(cp) {
1019
1028
  return cp + 32;
1020
1029
  }
1021
1030
  function isWhitespace(cp) {
1022
- return cp === CODE_POINTS.SPACE || cp === CODE_POINTS.LINE_FEED || cp === CODE_POINTS.TABULATION || cp === CODE_POINTS.FORM_FEED;
1031
+ return cp === CODE_POINTS.SPACE || cp === CODE_POINTS.LINE_FEED || cp === CODE_POINTS.TABULATION || cp === CODE_POINTS.FORM_FEED || cp === CODE_POINTS.CARRIAGE_RETURN;
1023
1032
  }
1024
1033
  function isScriptDataDoubleEscapeSequenceEnd(cp) {
1025
1034
  return isWhitespace(cp) || cp === CODE_POINTS.SOLIDUS || cp === CODE_POINTS.GREATER_THAN_SIGN;
@@ -1054,11 +1063,17 @@ var Tokenizer = class {
1054
1063
  this.currentCharacterToken = null;
1055
1064
  this.currentToken = null;
1056
1065
  this.currentAttr = { name: "", value: "" };
1066
+ this.currentAttrLocation = null;
1067
+ this.runStart = 0;
1068
+ this.runEnd = 0;
1057
1069
  this.preprocessor = new Preprocessor(handler);
1058
1070
  this.currentLocation = this.getCurrentLocation(-1);
1059
- this.entityDecoder = new import_decode.EntityDecoder(import_decode.htmlDecodeTree, (cp, consumed) => {
1071
+ this.entityDecoder = new import_decode.HtmlEntityDecoder((cp, consumed) => {
1060
1072
  this.preprocessor.pos = this.entityStartPos + consumed - 1;
1061
- this._flushCodePointConsumedAsCharacterReference(cp);
1073
+ if (!this._isCharacterReferenceInAttribute()) {
1074
+ this._ensureCharacterToken(isWhitespace(cp) ? TokenType.WHITESPACE_CHARACTER : cp === CODE_POINTS.NULL ? TokenType.NULL_CHARACTER : TokenType.CHARACTER);
1075
+ }
1076
+ this._extendRunWith(String.fromCodePoint(cp), 0);
1062
1077
  }, handler.onParseError ? {
1063
1078
  missingSemicolonAfterCharacterReference: () => {
1064
1079
  this._err(ERR.missingSemicolonAfterCharacterReference, 1);
@@ -1106,6 +1121,92 @@ var Tokenizer = class {
1106
1121
  this.inLoop = false;
1107
1122
  }
1108
1123
  //API
1124
+ /** Emit buffered character tokens without completing the current token or emitting EOF. */
1125
+ flushCharacters() {
1126
+ var _a;
1127
+ if (this.inLoop) {
1128
+ throw new Error("Cannot flush characters from a tokenizer callback");
1129
+ }
1130
+ const location = (_a = this.currentCharacterToken) === null || _a === void 0 ? void 0 : _a.location;
1131
+ let nextLocation = null;
1132
+ if (location) {
1133
+ nextLocation = this.getCharacterTokenEndLocation(location);
1134
+ this.currentLocation = nextLocation;
1135
+ }
1136
+ this.inLoop = true;
1137
+ try {
1138
+ this._emitCurrentCharacterToken(nextLocation);
1139
+ } finally {
1140
+ this.inLoop = false;
1141
+ }
1142
+ this._runParsingLoop();
1143
+ }
1144
+ getCharacterTokenEndLocation(location) {
1145
+ const endOffset = this.getCharacterTokenEndOffset();
1146
+ const html = this.preprocessor.html.slice(location.startOffset - this.preprocessor.droppedBufferSize, endOffset - this.preprocessor.droppedBufferSize);
1147
+ let line = location.startLine;
1148
+ let lastLineBreak = -1;
1149
+ for (let i = html.indexOf("\n"); i !== -1; i = html.indexOf("\n", i + 1)) {
1150
+ line++;
1151
+ lastLineBreak = i;
1152
+ }
1153
+ for (let i = html.indexOf("\r"); i !== -1; i = html.indexOf("\r", i + 1)) {
1154
+ if (html.charCodeAt(i + 1) !== CODE_POINTS.LINE_FEED) {
1155
+ line++;
1156
+ lastLineBreak = Math.max(lastLineBreak, i);
1157
+ }
1158
+ }
1159
+ return {
1160
+ startLine: line,
1161
+ startCol: lastLineBreak === -1 ? location.startCol + html.length : html.length - lastLineBreak,
1162
+ startOffset: endOffset,
1163
+ endLine: -1,
1164
+ endCol: -1,
1165
+ endOffset: -1
1166
+ };
1167
+ }
1168
+ // Return the input boundary before any unfinished token or buffered delimiter.
1169
+ getCharacterTokenEndOffset() {
1170
+ var _a;
1171
+ const end = this.preprocessor.droppedBufferSize + this.preprocessor.pos + 1;
1172
+ const tokenLocation = (_a = this.currentToken) === null || _a === void 0 ? void 0 : _a.location;
1173
+ switch (this.state) {
1174
+ case State.TAG_OPEN:
1175
+ case State.RCDATA_LESS_THAN_SIGN:
1176
+ case State.RAWTEXT_LESS_THAN_SIGN:
1177
+ case State.SCRIPT_DATA_LESS_THAN_SIGN:
1178
+ case State.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:
1179
+ case State.CDATA_SECTION_BRACKET: {
1180
+ return end - 1;
1181
+ }
1182
+ case State.END_TAG_OPEN:
1183
+ case State.MARKUP_DECLARATION_OPEN:
1184
+ case State.RCDATA_END_TAG_OPEN:
1185
+ case State.RCDATA_END_TAG_NAME:
1186
+ case State.RAWTEXT_END_TAG_OPEN:
1187
+ case State.RAWTEXT_END_TAG_NAME:
1188
+ case State.SCRIPT_DATA_END_TAG_OPEN:
1189
+ case State.SCRIPT_DATA_END_TAG_NAME:
1190
+ case State.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:
1191
+ case State.SCRIPT_DATA_ESCAPED_END_TAG_NAME:
1192
+ case State.CDATA_SECTION_END: {
1193
+ return end - 2;
1194
+ }
1195
+ case State.CHARACTER_REFERENCE: {
1196
+ return this._isCharacterReferenceInAttribute() && tokenLocation ? tokenLocation.startOffset : this.preprocessor.droppedBufferSize + this.entityStartPos;
1197
+ }
1198
+ case State.DOCTYPE:
1199
+ case State.BEFORE_DOCTYPE_NAME: {
1200
+ return this.currentLocation.startOffset;
1201
+ }
1202
+ default: {
1203
+ if (tokenLocation && (this.state === State.TAG_NAME || this.state >= State.BEFORE_ATTRIBUTE_NAME && this.state <= State.BOGUS_COMMENT || this.state >= State.COMMENT_START && this.state <= State.BOGUS_DOCTYPE)) {
1204
+ return tokenLocation.startOffset;
1205
+ }
1206
+ return end;
1207
+ }
1208
+ }
1209
+ }
1109
1210
  pause() {
1110
1211
  this.paused = true;
1111
1212
  }
@@ -1164,6 +1265,7 @@ var Tokenizer = class {
1164
1265
  }
1165
1266
  //Token creation
1166
1267
  _createStartTagToken() {
1268
+ this._flushRun("");
1167
1269
  this.currentToken = {
1168
1270
  type: TokenType.START_TAG,
1169
1271
  tagName: "",
@@ -1175,6 +1277,7 @@ var Tokenizer = class {
1175
1277
  };
1176
1278
  }
1177
1279
  _createEndTagToken() {
1280
+ this._flushRun("");
1178
1281
  this.currentToken = {
1179
1282
  type: TokenType.END_TAG,
1180
1283
  tagName: "",
@@ -1186,6 +1289,7 @@ var Tokenizer = class {
1186
1289
  };
1187
1290
  }
1188
1291
  _createCommentToken(offset) {
1292
+ this._flushRun("");
1189
1293
  this.currentToken = {
1190
1294
  type: TokenType.COMMENT,
1191
1295
  data: "",
@@ -1193,6 +1297,7 @@ var Tokenizer = class {
1193
1297
  };
1194
1298
  }
1195
1299
  _createDoctypeToken(initialName) {
1300
+ this._flushRun("");
1196
1301
  this.currentToken = {
1197
1302
  type: TokenType.DOCTYPE,
1198
1303
  name: initialName,
@@ -1202,20 +1307,27 @@ var Tokenizer = class {
1202
1307
  location: this.currentLocation
1203
1308
  };
1204
1309
  }
1205
- _createCharacterToken(type, chars) {
1310
+ _createCharacterToken(type) {
1311
+ if (this.currentLocation) {
1312
+ const start = this.currentLocation.startOffset - this.preprocessor.droppedBufferSize;
1313
+ if (this.preprocessor.html[start] === "\n" && this.preprocessor.html[start - 1] === "\r") {
1314
+ this.currentLocation.startOffset++;
1315
+ }
1316
+ }
1206
1317
  this.currentCharacterToken = {
1207
1318
  type,
1208
- chars,
1319
+ chars: "",
1209
1320
  location: this.currentLocation
1210
1321
  };
1211
1322
  }
1212
1323
  //Tag attributes
1213
1324
  _createAttr(attrNameFirstCh) {
1325
+ this._flushRun("");
1214
1326
  this.currentAttr = {
1215
1327
  name: attrNameFirstCh,
1216
1328
  value: ""
1217
1329
  };
1218
- this.currentLocation = this.getCurrentLocation(0);
1330
+ this.currentAttrLocation = this.getCurrentLocation(0);
1219
1331
  }
1220
1332
  _leaveAttrName() {
1221
1333
  var _a;
@@ -1223,9 +1335,9 @@ var Tokenizer = class {
1223
1335
  const token = this.currentToken;
1224
1336
  if (getTokenAttr(token, this.currentAttr.name) === null) {
1225
1337
  token.attrs.push(this.currentAttr);
1226
- if (token.location && this.currentLocation) {
1338
+ if (token.location && this.currentAttrLocation) {
1227
1339
  const attrLocations = (_a = (_b = token.location).attrs) !== null && _a !== void 0 ? _a : _b.attrs = /* @__PURE__ */ Object.create(null);
1228
- attrLocations[this.currentAttr.name] = this.currentLocation;
1340
+ attrLocations[this.currentAttr.name] = this.currentAttrLocation;
1229
1341
  this._leaveAttrValue();
1230
1342
  }
1231
1343
  } else {
@@ -1233,11 +1345,66 @@ var Tokenizer = class {
1233
1345
  }
1234
1346
  }
1235
1347
  _leaveAttrValue() {
1236
- if (this.currentLocation) {
1237
- this.currentLocation.endLine = this.preprocessor.line;
1238
- this.currentLocation.endCol = this.preprocessor.col;
1239
- this.currentLocation.endOffset = this.preprocessor.offset;
1348
+ if (this.currentAttrLocation) {
1349
+ this.currentAttrLocation.endLine = this.preprocessor.line;
1350
+ this.currentAttrLocation.endCol = this.preprocessor.col;
1351
+ this.currentAttrLocation.endOffset = this.preprocessor.offset;
1352
+ }
1353
+ }
1354
+ /**
1355
+ * Append the pending run and `text` to the attribute value, comment data or character token being built.
1356
+ * The run is a string of its own: V8 copies a slice of fewer than 13 characters but lets a longer one share
1357
+ * the input's buffer, which would keep that buffer alive for as long as any attribute value or text cut from
1358
+ * it is; a concatenation is flattened into a buffer of its own when it is sliced.
1359
+ */
1360
+ _flushRun(text) {
1361
+ if (this.runEnd === this.runStart && text.length === 0) {
1362
+ return;
1363
+ }
1364
+ const slice = this.preprocessor.html.slice(this.runStart, this.runEnd);
1365
+ const run = (slice.length < 13 ? slice : ` ${slice}`.slice(1)) + text;
1366
+ const token = this.currentToken;
1367
+ this.runStart = this.runEnd;
1368
+ if (token === null) {
1369
+ this.currentCharacterToken.chars += run;
1370
+ } else if (token.type === TokenType.COMMENT) {
1371
+ token.data += run;
1372
+ } else {
1373
+ this.currentAttr.value += run;
1374
+ }
1375
+ }
1376
+ /** Extend the pending run by the current input code point, read as `cp`, or flush it and start a new one. */
1377
+ _extendRun(cp) {
1378
+ const { preprocessor } = this;
1379
+ if (cp === CODE_POINTS.LINE_FEED && preprocessor.html.charCodeAt(preprocessor.pos) !== CODE_POINTS.LINE_FEED) {
1380
+ this._flushRun("\n");
1381
+ this.runStart = preprocessor.pos + 1;
1382
+ } else {
1383
+ const start = preprocessor.pos - Number(cp > 65535);
1384
+ if (start !== this.runEnd) {
1385
+ this._flushRun("");
1386
+ this.runStart = start;
1387
+ }
1388
+ }
1389
+ this.runEnd = preprocessor.pos + 1;
1390
+ }
1391
+ /**
1392
+ * Extend the pending run by `text`, the input that ends `cpOffset` code points after the current one, or flush
1393
+ * the run and append `text` where the input differs (a NUL replacement, a decoded reference, a dropped chunk).
1394
+ */
1395
+ _extendRunWith(text, cpOffset) {
1396
+ const { preprocessor } = this;
1397
+ const start = preprocessor.codePointStart + 1 + cpOffset - text.length;
1398
+ if (start >= 0 && preprocessor.html.startsWith(text, start)) {
1399
+ if (start !== this.runEnd) {
1400
+ this._flushRun("");
1401
+ this.runStart = start;
1402
+ }
1403
+ } else {
1404
+ this._flushRun(text);
1405
+ this.runStart = start + text.length;
1240
1406
  }
1407
+ this.runEnd = start + text.length;
1241
1408
  }
1242
1409
  //Token emission
1243
1410
  prepareToken(ct) {
@@ -1279,6 +1446,7 @@ var Tokenizer = class {
1279
1446
  this.preprocessor.dropParsedChunk();
1280
1447
  }
1281
1448
  _emitCurrentCharacterToken(nextLocation) {
1449
+ this._flushRun("");
1282
1450
  if (this.currentCharacterToken) {
1283
1451
  if (nextLocation && this.currentCharacterToken.location) {
1284
1452
  this.currentCharacterToken.location.endLine = nextLocation.startLine;
@@ -1322,27 +1490,39 @@ var Tokenizer = class {
1322
1490
  //1)TokenType.NULL_CHARACTER - \u0000-character sequences (e.g. '\u0000\u0000\u0000')
1323
1491
  //2)TokenType.WHITESPACE_CHARACTER - any whitespace/new-line character sequences (e.g. '\n \r\t \f')
1324
1492
  //3)TokenType.CHARACTER - any character sequence which don't belong to groups 1 and 2 (e.g. 'abcdef1234@@#$%^')
1325
- _appendCharToCurrentCharacterToken(type, ch) {
1493
+ /** Make the current character token one of `type`, emitting the current one if it has another type. */
1494
+ _ensureCharacterToken(type) {
1326
1495
  if (this.currentCharacterToken) {
1327
1496
  if (this.currentCharacterToken.type === type) {
1328
- this.currentCharacterToken.chars += ch;
1329
1497
  return;
1330
- } else {
1331
- this.currentLocation = this.getCurrentLocation(0);
1332
- this._emitCurrentCharacterToken(this.currentLocation);
1333
- this.preprocessor.dropParsedChunk();
1334
1498
  }
1499
+ this.currentLocation = this.getCurrentLocation(0);
1500
+ this._emitCurrentCharacterToken(this.currentLocation);
1501
+ this.preprocessor.dropParsedChunk();
1335
1502
  }
1336
- this._createCharacterToken(type, ch);
1503
+ this._createCharacterToken(type);
1337
1504
  }
1505
+ /** Emit the current input code point, read as `cp`. */
1338
1506
  _emitCodePoint(cp) {
1339
1507
  const type = isWhitespace(cp) ? TokenType.WHITESPACE_CHARACTER : cp === CODE_POINTS.NULL ? TokenType.NULL_CHARACTER : TokenType.CHARACTER;
1340
- this._appendCharToCurrentCharacterToken(type, cp < 65536 ? String.fromCharCode(cp) : String.fromCodePoint(cp));
1508
+ const token = this.currentCharacterToken;
1509
+ if (token === null || token.type !== type) {
1510
+ this._ensureCharacterToken(type);
1511
+ }
1512
+ this._extendRun(cp);
1341
1513
  }
1342
1514
  //NOTE: used when we emit characters explicitly.
1343
1515
  //This is always for non-whitespace and non-null characters, which allows us to avoid additional checks.
1344
- _emitChars(ch) {
1345
- this._appendCharToCurrentCharacterToken(TokenType.CHARACTER, ch);
1516
+ // Negative `cpOffset` values locate text emitted before the current input character.
1517
+ _emitChars(ch, cpOffset = 0) {
1518
+ if (this.options.sourceCodeLocationInfo && cpOffset !== 0 && this.currentCharacterToken && this.currentCharacterToken.type !== TokenType.CHARACTER) {
1519
+ this.currentLocation = this.getCurrentLocation(ch.length - 1 - cpOffset);
1520
+ this._emitCurrentCharacterToken(this.currentLocation);
1521
+ this._createCharacterToken(TokenType.CHARACTER);
1522
+ } else {
1523
+ this._ensureCharacterToken(TokenType.CHARACTER);
1524
+ }
1525
+ this._extendRunWith(ch, cpOffset);
1346
1526
  }
1347
1527
  // Character reference helpers
1348
1528
  _startCharacterReference() {
@@ -1356,7 +1536,7 @@ var Tokenizer = class {
1356
1536
  }
1357
1537
  _flushCodePointConsumedAsCharacterReference(cp) {
1358
1538
  if (this._isCharacterReferenceInAttribute()) {
1359
- this.currentAttr.value += String.fromCodePoint(cp);
1539
+ this._extendRun(cp);
1360
1540
  } else {
1361
1541
  this._emitCodePoint(cp);
1362
1542
  }
@@ -1802,13 +1982,13 @@ var Tokenizer = class {
1802
1982
  }
1803
1983
  case CODE_POINTS.EOF: {
1804
1984
  this._err(ERR.eofBeforeTagName);
1805
- this._emitChars("<");
1985
+ this._emitChars("<", -1);
1806
1986
  this._emitEOFToken();
1807
1987
  break;
1808
1988
  }
1809
1989
  default: {
1810
1990
  this._err(ERR.invalidFirstCharacterOfTagName);
1811
- this._emitChars("<");
1991
+ this._emitChars("<", -1);
1812
1992
  this.state = State.DATA;
1813
1993
  this._stateData(cp);
1814
1994
  }
@@ -1830,7 +2010,7 @@ var Tokenizer = class {
1830
2010
  }
1831
2011
  case CODE_POINTS.EOF: {
1832
2012
  this._err(ERR.eofBeforeTagName);
1833
- this._emitChars("</");
2013
+ this._emitChars("</", -1);
1834
2014
  this._emitEOFToken();
1835
2015
  break;
1836
2016
  }
@@ -1884,7 +2064,7 @@ var Tokenizer = class {
1884
2064
  if (cp === CODE_POINTS.SOLIDUS) {
1885
2065
  this.state = State.RCDATA_END_TAG_OPEN;
1886
2066
  } else {
1887
- this._emitChars("<");
2067
+ this._emitChars("<", -1);
1888
2068
  this.state = State.RCDATA;
1889
2069
  this._stateRcdata(cp);
1890
2070
  }
@@ -1896,7 +2076,7 @@ var Tokenizer = class {
1896
2076
  this.state = State.RCDATA_END_TAG_NAME;
1897
2077
  this._stateRcdataEndTagName(cp);
1898
2078
  } else {
1899
- this._emitChars("</");
2079
+ this._emitChars("</", -1);
1900
2080
  this.state = State.RCDATA;
1901
2081
  this._stateRcdata(cp);
1902
2082
  }
@@ -1930,6 +2110,7 @@ var Tokenizer = class {
1930
2110
  return false;
1931
2111
  }
1932
2112
  default: {
2113
+ this.currentToken = null;
1933
2114
  return !this._ensureHibernation();
1934
2115
  }
1935
2116
  }
@@ -1938,7 +2119,7 @@ var Tokenizer = class {
1938
2119
  //------------------------------------------------------------------
1939
2120
  _stateRcdataEndTagName(cp) {
1940
2121
  if (this.handleSpecialEndTag(cp)) {
1941
- this._emitChars("</");
2122
+ this._emitChars("</", -1);
1942
2123
  this.state = State.RCDATA;
1943
2124
  this._stateRcdata(cp);
1944
2125
  }
@@ -1949,7 +2130,7 @@ var Tokenizer = class {
1949
2130
  if (cp === CODE_POINTS.SOLIDUS) {
1950
2131
  this.state = State.RAWTEXT_END_TAG_OPEN;
1951
2132
  } else {
1952
- this._emitChars("<");
2133
+ this._emitChars("<", -1);
1953
2134
  this.state = State.RAWTEXT;
1954
2135
  this._stateRawtext(cp);
1955
2136
  }
@@ -1961,7 +2142,7 @@ var Tokenizer = class {
1961
2142
  this.state = State.RAWTEXT_END_TAG_NAME;
1962
2143
  this._stateRawtextEndTagName(cp);
1963
2144
  } else {
1964
- this._emitChars("</");
2145
+ this._emitChars("</", -1);
1965
2146
  this.state = State.RAWTEXT;
1966
2147
  this._stateRawtext(cp);
1967
2148
  }
@@ -1970,7 +2151,7 @@ var Tokenizer = class {
1970
2151
  //------------------------------------------------------------------
1971
2152
  _stateRawtextEndTagName(cp) {
1972
2153
  if (this.handleSpecialEndTag(cp)) {
1973
- this._emitChars("</");
2154
+ this._emitChars("</", -1);
1974
2155
  this.state = State.RAWTEXT;
1975
2156
  this._stateRawtext(cp);
1976
2157
  }
@@ -1989,7 +2170,7 @@ var Tokenizer = class {
1989
2170
  break;
1990
2171
  }
1991
2172
  default: {
1992
- this._emitChars("<");
2173
+ this._emitChars("<", -1);
1993
2174
  this.state = State.SCRIPT_DATA;
1994
2175
  this._stateScriptData(cp);
1995
2176
  }
@@ -2002,7 +2183,7 @@ var Tokenizer = class {
2002
2183
  this.state = State.SCRIPT_DATA_END_TAG_NAME;
2003
2184
  this._stateScriptDataEndTagName(cp);
2004
2185
  } else {
2005
- this._emitChars("</");
2186
+ this._emitChars("</", -1);
2006
2187
  this.state = State.SCRIPT_DATA;
2007
2188
  this._stateScriptData(cp);
2008
2189
  }
@@ -2011,7 +2192,7 @@ var Tokenizer = class {
2011
2192
  //------------------------------------------------------------------
2012
2193
  _stateScriptDataEndTagName(cp) {
2013
2194
  if (this.handleSpecialEndTag(cp)) {
2014
- this._emitChars("</");
2195
+ this._emitChars("</", -1);
2015
2196
  this.state = State.SCRIPT_DATA;
2016
2197
  this._stateScriptData(cp);
2017
2198
  }
@@ -2136,11 +2317,11 @@ var Tokenizer = class {
2136
2317
  if (cp === CODE_POINTS.SOLIDUS) {
2137
2318
  this.state = State.SCRIPT_DATA_ESCAPED_END_TAG_OPEN;
2138
2319
  } else if (isAsciiLetter(cp)) {
2139
- this._emitChars("<");
2320
+ this._emitChars("<", -1);
2140
2321
  this.state = State.SCRIPT_DATA_DOUBLE_ESCAPE_START;
2141
2322
  this._stateScriptDataDoubleEscapeStart(cp);
2142
2323
  } else {
2143
- this._emitChars("<");
2324
+ this._emitChars("<", -1);
2144
2325
  this.state = State.SCRIPT_DATA_ESCAPED;
2145
2326
  this._stateScriptDataEscaped(cp);
2146
2327
  }
@@ -2152,7 +2333,7 @@ var Tokenizer = class {
2152
2333
  this.state = State.SCRIPT_DATA_ESCAPED_END_TAG_NAME;
2153
2334
  this._stateScriptDataEscapedEndTagName(cp);
2154
2335
  } else {
2155
- this._emitChars("</");
2336
+ this._emitChars("</", -1);
2156
2337
  this.state = State.SCRIPT_DATA_ESCAPED;
2157
2338
  this._stateScriptDataEscaped(cp);
2158
2339
  }
@@ -2161,7 +2342,7 @@ var Tokenizer = class {
2161
2342
  //------------------------------------------------------------------
2162
2343
  _stateScriptDataEscapedEndTagName(cp) {
2163
2344
  if (this.handleSpecialEndTag(cp)) {
2164
- this._emitChars("</");
2345
+ this._emitChars("</", -1);
2165
2346
  this.state = State.SCRIPT_DATA_ESCAPED;
2166
2347
  this._stateScriptDataEscaped(cp);
2167
2348
  }
@@ -2447,7 +2628,7 @@ var Tokenizer = class {
2447
2628
  }
2448
2629
  case CODE_POINTS.NULL: {
2449
2630
  this._err(ERR.unexpectedNullCharacter);
2450
- this.currentAttr.value += REPLACEMENT_CHARACTER;
2631
+ this._extendRunWith(REPLACEMENT_CHARACTER, 0);
2451
2632
  break;
2452
2633
  }
2453
2634
  case CODE_POINTS.EOF: {
@@ -2456,7 +2637,7 @@ var Tokenizer = class {
2456
2637
  break;
2457
2638
  }
2458
2639
  default: {
2459
- this.currentAttr.value += String.fromCodePoint(cp);
2640
+ this._extendRun(cp);
2460
2641
  }
2461
2642
  }
2462
2643
  }
@@ -2474,7 +2655,7 @@ var Tokenizer = class {
2474
2655
  }
2475
2656
  case CODE_POINTS.NULL: {
2476
2657
  this._err(ERR.unexpectedNullCharacter);
2477
- this.currentAttr.value += REPLACEMENT_CHARACTER;
2658
+ this._extendRunWith(REPLACEMENT_CHARACTER, 0);
2478
2659
  break;
2479
2660
  }
2480
2661
  case CODE_POINTS.EOF: {
@@ -2483,7 +2664,7 @@ var Tokenizer = class {
2483
2664
  break;
2484
2665
  }
2485
2666
  default: {
2486
- this.currentAttr.value += String.fromCodePoint(cp);
2667
+ this._extendRun(cp);
2487
2668
  }
2488
2669
  }
2489
2670
  }
@@ -2511,7 +2692,7 @@ var Tokenizer = class {
2511
2692
  }
2512
2693
  case CODE_POINTS.NULL: {
2513
2694
  this._err(ERR.unexpectedNullCharacter);
2514
- this.currentAttr.value += REPLACEMENT_CHARACTER;
2695
+ this._extendRunWith(REPLACEMENT_CHARACTER, 0);
2515
2696
  break;
2516
2697
  }
2517
2698
  case CODE_POINTS.QUOTATION_MARK:
@@ -2520,7 +2701,7 @@ var Tokenizer = class {
2520
2701
  case CODE_POINTS.EQUALS_SIGN:
2521
2702
  case CODE_POINTS.GRAVE_ACCENT: {
2522
2703
  this._err(ERR.unexpectedCharacterInUnquotedAttributeValue);
2523
- this.currentAttr.value += String.fromCodePoint(cp);
2704
+ this._extendRun(cp);
2524
2705
  break;
2525
2706
  }
2526
2707
  case CODE_POINTS.EOF: {
@@ -2529,7 +2710,7 @@ var Tokenizer = class {
2529
2710
  break;
2530
2711
  }
2531
2712
  default: {
2532
- this.currentAttr.value += String.fromCodePoint(cp);
2713
+ this._extendRun(cp);
2533
2714
  }
2534
2715
  }
2535
2716
  }
@@ -2563,6 +2744,7 @@ var Tokenizer = class {
2563
2744
  }
2564
2745
  default: {
2565
2746
  this._err(ERR.missingWhitespaceBetweenAttributes);
2747
+ this._leaveAttrValue();
2566
2748
  this.state = State.BEFORE_ATTRIBUTE_NAME;
2567
2749
  this._stateBeforeAttributeName(cp);
2568
2750
  }
@@ -2608,11 +2790,11 @@ var Tokenizer = class {
2608
2790
  }
2609
2791
  case CODE_POINTS.NULL: {
2610
2792
  this._err(ERR.unexpectedNullCharacter);
2611
- token.data += REPLACEMENT_CHARACTER;
2793
+ this._extendRunWith(REPLACEMENT_CHARACTER, 0);
2612
2794
  break;
2613
2795
  }
2614
2796
  default: {
2615
- token.data += String.fromCodePoint(cp);
2797
+ this._extendRun(cp);
2616
2798
  }
2617
2799
  }
2618
2800
  }
@@ -2684,7 +2866,7 @@ var Tokenizer = class {
2684
2866
  break;
2685
2867
  }
2686
2868
  default: {
2687
- token.data += "-";
2869
+ this._extendRunWith("-", -1);
2688
2870
  this.state = State.COMMENT;
2689
2871
  this._stateComment(cp);
2690
2872
  }
@@ -2700,13 +2882,13 @@ var Tokenizer = class {
2700
2882
  break;
2701
2883
  }
2702
2884
  case CODE_POINTS.LESS_THAN_SIGN: {
2703
- token.data += "<";
2885
+ this._extendRunWith("<", 0);
2704
2886
  this.state = State.COMMENT_LESS_THAN_SIGN;
2705
2887
  break;
2706
2888
  }
2707
2889
  case CODE_POINTS.NULL: {
2708
2890
  this._err(ERR.unexpectedNullCharacter);
2709
- token.data += REPLACEMENT_CHARACTER;
2891
+ this._extendRunWith(REPLACEMENT_CHARACTER, 0);
2710
2892
  break;
2711
2893
  }
2712
2894
  case CODE_POINTS.EOF: {
@@ -2716,22 +2898,21 @@ var Tokenizer = class {
2716
2898
  break;
2717
2899
  }
2718
2900
  default: {
2719
- token.data += String.fromCodePoint(cp);
2901
+ this._extendRun(cp);
2720
2902
  }
2721
2903
  }
2722
2904
  }
2723
2905
  // Comment less-than sign state
2724
2906
  //------------------------------------------------------------------
2725
2907
  _stateCommentLessThanSign(cp) {
2726
- const token = this.currentToken;
2727
2908
  switch (cp) {
2728
2909
  case CODE_POINTS.EXCLAMATION_MARK: {
2729
- token.data += "!";
2910
+ this._extendRunWith("!", 0);
2730
2911
  this.state = State.COMMENT_LESS_THAN_SIGN_BANG;
2731
2912
  break;
2732
2913
  }
2733
2914
  case CODE_POINTS.LESS_THAN_SIGN: {
2734
- token.data += "<";
2915
+ this._extendRunWith("<", 0);
2735
2916
  break;
2736
2917
  }
2737
2918
  default: {
@@ -2785,7 +2966,7 @@ var Tokenizer = class {
2785
2966
  break;
2786
2967
  }
2787
2968
  default: {
2788
- token.data += "-";
2969
+ this._extendRunWith("-", -1);
2789
2970
  this.state = State.COMMENT;
2790
2971
  this._stateComment(cp);
2791
2972
  }
@@ -2806,7 +2987,7 @@ var Tokenizer = class {
2806
2987
  break;
2807
2988
  }
2808
2989
  case CODE_POINTS.HYPHEN_MINUS: {
2809
- token.data += "-";
2990
+ this._extendRunWith("-", -2);
2810
2991
  break;
2811
2992
  }
2812
2993
  case CODE_POINTS.EOF: {
@@ -2816,7 +2997,7 @@ var Tokenizer = class {
2816
2997
  break;
2817
2998
  }
2818
2999
  default: {
2819
- token.data += "--";
3000
+ this._extendRunWith("--", -1);
2820
3001
  this.state = State.COMMENT;
2821
3002
  this._stateComment(cp);
2822
3003
  }
@@ -2828,7 +3009,7 @@ var Tokenizer = class {
2828
3009
  const token = this.currentToken;
2829
3010
  switch (cp) {
2830
3011
  case CODE_POINTS.HYPHEN_MINUS: {
2831
- token.data += "--!";
3012
+ this._extendRunWith("--!", -1);
2832
3013
  this.state = State.COMMENT_END_DASH;
2833
3014
  break;
2834
3015
  }
@@ -2845,7 +3026,7 @@ var Tokenizer = class {
2845
3026
  break;
2846
3027
  }
2847
3028
  default: {
2848
- token.data += "--!";
3029
+ this._extendRunWith("--!", -1);
2849
3030
  this.state = State.COMMENT;
2850
3031
  this._stateComment(cp);
2851
3032
  }
@@ -3469,7 +3650,7 @@ var Tokenizer = class {
3469
3650
  if (cp === CODE_POINTS.RIGHT_SQUARE_BRACKET) {
3470
3651
  this.state = State.CDATA_SECTION_END;
3471
3652
  } else {
3472
- this._emitChars("]");
3653
+ this._emitChars("]", -1);
3473
3654
  this.state = State.CDATA_SECTION;
3474
3655
  this._stateCdataSection(cp);
3475
3656
  }
@@ -3483,11 +3664,11 @@ var Tokenizer = class {
3483
3664
  break;
3484
3665
  }
3485
3666
  case CODE_POINTS.RIGHT_SQUARE_BRACKET: {
3486
- this._emitChars("]");
3667
+ this._emitChars("]", -2);
3487
3668
  break;
3488
3669
  }
3489
3670
  default: {
3490
- this._emitChars("]]");
3671
+ this._emitChars("]]", -1);
3491
3672
  this.state = State.CDATA_SECTION;
3492
3673
  this._stateCdataSection(cp);
3493
3674
  }
@@ -3531,7 +3712,7 @@ var Tokenizer = class {
3531
3712
  }
3532
3713
  };
3533
3714
 
3534
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/parser/open-element-stack.js
3715
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/parser/open-element-stack.js
3535
3716
  var IMPLICIT_END_TAG_REQUIRED = /* @__PURE__ */ new Set([TAG_ID.DD, TAG_ID.DT, TAG_ID.LI, TAG_ID.OPTGROUP, TAG_ID.OPTION, TAG_ID.P, TAG_ID.RB, TAG_ID.RP, TAG_ID.RT, TAG_ID.RTC]);
3536
3717
  var IMPLICIT_END_TAG_REQUIRED_THOROUGHLY = /* @__PURE__ */ new Set([
3537
3718
  ...IMPLICIT_END_TAG_REQUIRED,
@@ -3848,7 +4029,7 @@ var OpenElementStack = class {
3848
4029
  }
3849
4030
  };
3850
4031
 
3851
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/parser/formatting-element-list.js
4032
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/parser/formatting-element-list.js
3852
4033
  var NOAH_ARK_CAPACITY = 3;
3853
4034
  var EntryType;
3854
4035
  (function(EntryType2) {
@@ -3953,7 +4134,7 @@ var FormattingElementList = class {
3953
4134
  }
3954
4135
  };
3955
4136
 
3956
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/tree-adapters/default.js
4137
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/tree-adapters/default.js
3957
4138
  var defaultTreeAdapter = {
3958
4139
  //Node construction
3959
4140
  createDocument() {
@@ -4125,7 +4306,7 @@ var defaultTreeAdapter = {
4125
4306
  }
4126
4307
  };
4127
4308
 
4128
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/common/doctype.js
4309
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/common/doctype.js
4129
4310
  var VALID_DOCTYPE_NAME = "html";
4130
4311
  var VALID_SYSTEM_ID = "about:legacy-compat";
4131
4312
  var QUIRKS_MODE_SYSTEM_ID = "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd";
@@ -4234,7 +4415,7 @@ function getDocumentMode(token) {
4234
4415
  return DOCUMENT_MODE.NO_QUIRKS;
4235
4416
  }
4236
4417
 
4237
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/common/foreign-content.js
4418
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/common/foreign-content.js
4238
4419
  var foreign_content_exports = {};
4239
4420
  __export(foreign_content_exports, {
4240
4421
  SVG_TAG_NAMES_ADJUSTMENT_MAP: () => SVG_TAG_NAMES_ADJUSTMENT_MAP,
@@ -4464,7 +4645,7 @@ function isIntegrationPoint(tn, ns, attrs, foreignNS) {
4464
4645
  return (!foreignNS || foreignNS === NS.HTML) && isHtmlIntegrationPoint(tn, ns, attrs) || (!foreignNS || foreignNS === NS.MATHML) && isMathMLTextIntegrationPoint(tn, ns);
4465
4646
  }
4466
4647
 
4467
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/parser/index.js
4648
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/parser/index.js
4468
4649
  var HIDDEN_INPUT_TYPE = "hidden";
4469
4650
  var AA_OUTER_LOOP_ITER = 8;
4470
4651
  var AA_INNER_LOOP_ITER = 3;
@@ -4695,7 +4876,7 @@ var Parser = class {
4695
4876
  }
4696
4877
  }
4697
4878
  /** @protected */
4698
- _attachElementToTree(element, location) {
4879
+ _attachElementToTree(element, location, insertionLocation) {
4699
4880
  if (this.options.sourceCodeLocationInfo) {
4700
4881
  const loc = location && {
4701
4882
  ...location,
@@ -4703,50 +4884,75 @@ var Parser = class {
4703
4884
  };
4704
4885
  this.treeAdapter.setNodeSourceCodeLocation(element, loc);
4705
4886
  }
4706
- if (this._shouldFosterParentOnInsertion()) {
4707
- this._fosterParentElement(element);
4887
+ if (insertionLocation.beforeElement) {
4888
+ this.treeAdapter.insertBefore(insertionLocation.parent, element, insertionLocation.beforeElement);
4708
4889
  } else {
4709
- const parent = this.openElements.currentTmplContentOrNode;
4710
- this.treeAdapter.appendChild(parent !== null && parent !== void 0 ? parent : this.document, element);
4890
+ this.treeAdapter.appendChild(insertionLocation.parent, element);
4711
4891
  }
4712
4892
  }
4893
+ /** @protected */
4894
+ _getInsertionLocation() {
4895
+ var _a;
4896
+ if (this._shouldFosterParentOnInsertion()) {
4897
+ return this._findFosterParentingLocation();
4898
+ }
4899
+ return {
4900
+ parent: (_a = this.openElements.currentTmplContentOrNode) !== null && _a !== void 0 ? _a : this.document,
4901
+ beforeElement: null
4902
+ };
4903
+ }
4904
+ /** @protected */
4905
+ _createElement(tagName, namespaceURI, attrs, intendedParent) {
4906
+ var _a, _b;
4907
+ const element = this.treeAdapter.createElement(tagName, namespaceURI, attrs);
4908
+ (_b = (_a = this.treeAdapter).onElementCreated) === null || _b === void 0 ? void 0 : _b.call(_a, element, {
4909
+ intendedParent,
4910
+ formElement: this.formElement,
4911
+ isInTemplate: this.openElements.tmplCount > 0
4912
+ });
4913
+ return element;
4914
+ }
4713
4915
  /**
4714
4916
  * For self-closing tags. Add an element to the tree, but skip adding it
4715
4917
  * to the stack.
4716
4918
  */
4717
4919
  /** @protected */
4718
4920
  _appendElement(token, namespaceURI) {
4719
- const element = this.treeAdapter.createElement(token.tagName, namespaceURI, token.attrs);
4720
- this._attachElementToTree(element, token.location);
4921
+ const insertionLocation = this._getInsertionLocation();
4922
+ const element = this._createElement(token.tagName, namespaceURI, token.attrs, insertionLocation.parent);
4923
+ this._attachElementToTree(element, token.location, insertionLocation);
4721
4924
  }
4722
4925
  /** @protected */
4723
4926
  _insertElement(token, namespaceURI) {
4724
- const element = this.treeAdapter.createElement(token.tagName, namespaceURI, token.attrs);
4725
- this._attachElementToTree(element, token.location);
4927
+ const insertionLocation = this._getInsertionLocation();
4928
+ const element = this._createElement(token.tagName, namespaceURI, token.attrs, insertionLocation.parent);
4929
+ this._attachElementToTree(element, token.location, insertionLocation);
4726
4930
  this.openElements.push(element, token.tagID);
4727
4931
  }
4728
4932
  /** @protected */
4729
4933
  _insertFakeElement(tagName, tagID) {
4730
- const element = this.treeAdapter.createElement(tagName, NS.HTML, []);
4731
- this._attachElementToTree(element, null);
4934
+ const insertionLocation = this._getInsertionLocation();
4935
+ const element = this._createElement(tagName, NS.HTML, [], insertionLocation.parent);
4936
+ this._attachElementToTree(element, null, insertionLocation);
4732
4937
  this.openElements.push(element, tagID);
4733
4938
  }
4734
4939
  /** @protected */
4735
4940
  _insertTemplate(token) {
4736
- const tmpl = this.treeAdapter.createElement(token.tagName, NS.HTML, token.attrs);
4941
+ const insertionLocation = this._getInsertionLocation();
4942
+ const tmpl = this._createElement(token.tagName, NS.HTML, token.attrs, insertionLocation.parent);
4737
4943
  const content = this.treeAdapter.createDocumentFragment();
4738
4944
  this.treeAdapter.setTemplateContent(tmpl, content);
4739
- this._attachElementToTree(tmpl, token.location);
4945
+ this._attachElementToTree(tmpl, token.location, insertionLocation);
4740
4946
  this.openElements.push(tmpl, token.tagID);
4741
4947
  if (this.options.sourceCodeLocationInfo)
4742
4948
  this.treeAdapter.setNodeSourceCodeLocation(content, null);
4743
4949
  }
4744
4950
  /** @protected */
4745
4951
  _insertFakeRootElement() {
4746
- const element = this.treeAdapter.createElement(TAG_NAMES.HTML, NS.HTML, []);
4952
+ const element = this._createElement(TAG_NAMES.HTML, NS.HTML, [], this.document);
4747
4953
  if (this.options.sourceCodeLocationInfo)
4748
4954
  this.treeAdapter.setNodeSourceCodeLocation(element, null);
4749
- this.treeAdapter.appendChild(this.openElements.current, element);
4955
+ this.treeAdapter.appendChild(this.document, element);
4750
4956
  this.openElements.push(element, TAG_ID.HTML);
4751
4957
  }
4752
4958
  /** @protected */
@@ -5603,6 +5809,7 @@ function aaObtainFurthestBlock(p, formattingElementEntry) {
5603
5809
  function aaInnerLoop(p, furthestBlock, formattingElement) {
5604
5810
  let lastElement = furthestBlock;
5605
5811
  let nextElement = p.openElements.getCommonAncestor(furthestBlock);
5812
+ const intendedParent = p.openElements.getCommonAncestor(formattingElement);
5606
5813
  for (let i = 0, element = nextElement; element !== formattingElement; i++, element = nextElement) {
5607
5814
  nextElement = p.openElements.getCommonAncestor(element);
5608
5815
  const elementEntry = p.activeFormattingElements.getElementEntry(element);
@@ -5614,7 +5821,7 @@ function aaInnerLoop(p, furthestBlock, formattingElement) {
5614
5821
  }
5615
5822
  p.openElements.remove(element);
5616
5823
  } else {
5617
- element = aaRecreateElementFromEntry(p, elementEntry);
5824
+ element = aaRecreateElementFromEntry(p, elementEntry, intendedParent);
5618
5825
  if (lastElement === furthestBlock) {
5619
5826
  p.activeFormattingElements.bookmark = elementEntry;
5620
5827
  }
@@ -5625,9 +5832,9 @@ function aaInnerLoop(p, furthestBlock, formattingElement) {
5625
5832
  }
5626
5833
  return lastElement;
5627
5834
  }
5628
- function aaRecreateElementFromEntry(p, elementEntry) {
5835
+ function aaRecreateElementFromEntry(p, elementEntry, intendedParent) {
5629
5836
  const ns = p.treeAdapter.getNamespaceURI(elementEntry.element);
5630
- const newElement = p.treeAdapter.createElement(elementEntry.token.tagName, ns, elementEntry.token.attrs);
5837
+ const newElement = p._createElement(elementEntry.token.tagName, ns, elementEntry.token.attrs, intendedParent);
5631
5838
  p.openElements.replace(elementEntry.element, newElement);
5632
5839
  elementEntry.element = newElement;
5633
5840
  return newElement;
@@ -5648,7 +5855,7 @@ function aaInsertLastNodeInCommonAncestor(p, commonAncestor, lastElement) {
5648
5855
  function aaReplaceFormattingElement(p, furthestBlock, formattingElementEntry) {
5649
5856
  const ns = p.treeAdapter.getNamespaceURI(formattingElementEntry.element);
5650
5857
  const { token } = formattingElementEntry;
5651
- const newElement = p.treeAdapter.createElement(token.tagName, ns, token.attrs);
5858
+ const newElement = p._createElement(token.tagName, ns, token.attrs, furthestBlock);
5652
5859
  p._adoptNodes(furthestBlock, newElement);
5653
5860
  p.treeAdapter.appendChild(furthestBlock, newElement);
5654
5861
  p.activeFormattingElements.insertElementAfterBookmark(newElement, token);
@@ -6556,7 +6763,7 @@ function genericEndTagInBody(p, token) {
6556
6763
  for (let i = p.openElements.stackTop; i > 0; i--) {
6557
6764
  const element = p.openElements.items[i];
6558
6765
  const elementId = p.openElements.tagIDs[i];
6559
- if (tid === elementId && (tid !== TAG_ID.UNKNOWN || p.treeAdapter.getTagName(element) === tn)) {
6766
+ if (tid === elementId && p.treeAdapter.getNamespaceURI(element) === NS.HTML && (tid !== TAG_ID.UNKNOWN || p.treeAdapter.getTagName(element) === tn)) {
6560
6767
  p.openElements.generateImpliedEndTagsWithExclusion(tid);
6561
6768
  if (p.openElements.stackTop >= i)
6562
6769
  p.openElements.shortenToLength(i);
@@ -7489,7 +7696,7 @@ function endTagInForeignContent(p, token) {
7489
7696
  }
7490
7697
  }
7491
7698
 
7492
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/serializer/index.js
7699
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/serializer/index.js
7493
7700
  var import_escape = require("@cjser/entities/escape");
7494
7701
  var VOID_ELEMENTS = /* @__PURE__ */ new Set([
7495
7702
  TAG_NAMES.AREA,
@@ -7602,7 +7809,7 @@ function serializeDocumentTypeNode(node, { treeAdapter }) {
7602
7809
  return `<!DOCTYPE ${treeAdapter.getDocumentTypeNodeName(node)}>`;
7603
7810
  }
7604
7811
 
7605
- // packages/@cjser/parse5.tmp-26-1791908665740/dist/index.js
7812
+ // packages/@cjser/parse5.tmp-24-1793549660003/dist/index.js
7606
7813
  function parse(html, options) {
7607
7814
  return Parser.parse(html, options);
7608
7815
  }
@@ -7619,6 +7826,7 @@ function parseFragment(fragmentContext, html, options) {
7619
7826
  // Annotate the CommonJS export names for ESM import in node:
7620
7827
  0 && (module.exports = {
7621
7828
  ErrorCodes,
7829
+ InsertionMode,
7622
7830
  Parser,
7623
7831
  Token,
7624
7832
  Tokenizer,