regor 1.6.6 → 1.6.7

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.
@@ -6241,19 +6241,50 @@ var Regor = (() => {
6241
6241
  while (i < tagText.length && (tagText[i] === " " || tagText[i] === "\n")) ++i;
6242
6242
  if (i >= tagText.length || !isNameChar(tagText[i])) return null;
6243
6243
  const start = i;
6244
- while (i < tagText.length && isNameChar(tagText[i])) ++i;
6245
- return { start, end: i };
6246
- };
6247
- var tableScopeTags = /* @__PURE__ */ new Set(["table", "thead", "tbody", "tfoot"]);
6248
- var rowParentTags = /* @__PURE__ */ new Set(["thead", "tbody", "tfoot"]);
6249
- var tableDirectAllowed = /* @__PURE__ */ new Set([
6250
- "caption",
6251
- "colgroup",
6252
- "thead",
6253
- "tbody",
6254
- "tfoot",
6255
- "tr"
6256
- ]);
6244
+ let hasUppercase = false;
6245
+ while (i < tagText.length && isNameChar(tagText[i])) {
6246
+ const c = tagText.charCodeAt(i);
6247
+ if (c >= 65 && c <= 90) {
6248
+ hasUppercase = true;
6249
+ }
6250
+ ++i;
6251
+ }
6252
+ return { start, end: i, hasUppercase };
6253
+ };
6254
+ var isTableScopeTag = (tagName) => {
6255
+ switch (tagName) {
6256
+ case "table":
6257
+ case "thead":
6258
+ case "tbody":
6259
+ case "tfoot":
6260
+ return true;
6261
+ default:
6262
+ return false;
6263
+ }
6264
+ };
6265
+ var isRowParentTag = (tagName) => {
6266
+ switch (tagName) {
6267
+ case "thead":
6268
+ case "tbody":
6269
+ case "tfoot":
6270
+ return true;
6271
+ default:
6272
+ return false;
6273
+ }
6274
+ };
6275
+ var isTableDirectAllowed = (tagName) => {
6276
+ switch (tagName) {
6277
+ case "caption":
6278
+ case "colgroup":
6279
+ case "thead":
6280
+ case "tbody":
6281
+ case "tfoot":
6282
+ case "tr":
6283
+ return true;
6284
+ default:
6285
+ return false;
6286
+ }
6287
+ };
6257
6288
  var voidElements = /* @__PURE__ */ new Set([
6258
6289
  "area",
6259
6290
  "base",
@@ -6270,12 +6301,62 @@ var Regor = (() => {
6270
6301
  "track",
6271
6302
  "wbr"
6272
6303
  ]);
6304
+ var getTableAliasHost = (tagName) => {
6305
+ switch (tagName) {
6306
+ case "caption":
6307
+ return "captionx";
6308
+ case "thead":
6309
+ return "theadx";
6310
+ case "tbody":
6311
+ return "tbodyx";
6312
+ case "tfoot":
6313
+ return "tfootx";
6314
+ case "tr":
6315
+ return "trx";
6316
+ case "td":
6317
+ return "tdx";
6318
+ case "th":
6319
+ return "thx";
6320
+ case "colgroup":
6321
+ return "colgroupx";
6322
+ case "col":
6323
+ return "colx";
6324
+ default:
6325
+ return null;
6326
+ }
6327
+ };
6328
+ var getTableAliasTag = (host) => {
6329
+ switch (host) {
6330
+ case "captionx":
6331
+ return "caption";
6332
+ case "theadx":
6333
+ return "thead";
6334
+ case "tbodyx":
6335
+ return "tbody";
6336
+ case "tfootx":
6337
+ return "tfoot";
6338
+ case "trx":
6339
+ return "tr";
6340
+ case "tdx":
6341
+ return "td";
6342
+ case "thx":
6343
+ return "th";
6344
+ case "colgroupx":
6345
+ return "colgroup";
6346
+ case "colx":
6347
+ return "col";
6348
+ default:
6349
+ return void 0;
6350
+ }
6351
+ };
6352
+ var closeTag = (tagText, tagName) => `${tagText}</${tagName}>`;
6273
6353
  var expandSelfClosingTag = (tagText, tagName) => `${tagText.slice(0, tagText.length - 2)}></${tagName}>`;
6274
6354
  var preprocess = (template) => {
6275
- var _a;
6355
+ var _a, _b;
6276
6356
  let i = 0;
6277
6357
  const out = [];
6278
6358
  const stack = [];
6359
+ const ignoredClosingTags = [];
6279
6360
  let tableScopeDepth = 0;
6280
6361
  while (i < template.length) {
6281
6362
  const lt = template.indexOf("<", i);
@@ -6314,12 +6395,21 @@ var Regor = (() => {
6314
6395
  continue;
6315
6396
  }
6316
6397
  const tagName = rawTag.slice(range.start, range.end);
6398
+ const nativeTagName = range.hasUppercase ? "" : tagName;
6317
6399
  if (isClosing) {
6400
+ const ignoredClosing = ignoredClosingTags[ignoredClosingTags.length - 1];
6401
+ if ((ignoredClosing == null ? void 0 : ignoredClosing.tagName) === tagName) {
6402
+ ignoredClosingTags.pop();
6403
+ if (ignoredClosing.emit) out.push(rawTag);
6404
+ i = tagEnd + 1;
6405
+ continue;
6406
+ }
6318
6407
  const top = stack[stack.length - 1];
6319
6408
  if (top) {
6320
6409
  stack.pop();
6321
6410
  out.push(top.replacementHost ? `</${top.replacementHost}>` : rawTag);
6322
- if (tableScopeTags.has(top.effectiveTag)) --tableScopeDepth;
6411
+ if (!top.isTableAlias && isTableScopeTag(top.effectiveTag))
6412
+ --tableScopeDepth;
6323
6413
  } else {
6324
6414
  out.push(rawTag);
6325
6415
  }
@@ -6330,35 +6420,47 @@ var Regor = (() => {
6330
6420
  const parent = stack[stack.length - 1];
6331
6421
  let replacementHost = null;
6332
6422
  if (tableScopeDepth === 0) {
6333
- if (tagName === "tr") replacementHost = "trx";
6334
- else if (tagName === "td") replacementHost = "tdx";
6335
- else if (tagName === "th") replacementHost = "thx";
6336
- } else if (rowParentTags.has((_a = parent == null ? void 0 : parent.effectiveTag) != null ? _a : "")) {
6337
- replacementHost = tagName === "tr" ? null : "tr";
6423
+ replacementHost = getTableAliasHost(nativeTagName);
6424
+ } else if (isRowParentTag((_a = parent == null ? void 0 : parent.effectiveTag) != null ? _a : "")) {
6425
+ replacementHost = nativeTagName === "tr" ? null : "tr";
6338
6426
  } else if ((parent == null ? void 0 : parent.effectiveTag) === "table") {
6339
- replacementHost = tableDirectAllowed.has(tagName) ? null : "tr";
6427
+ replacementHost = isTableDirectAllowed(nativeTagName) ? null : "tr";
6340
6428
  } else if ((parent == null ? void 0 : parent.effectiveTag) === "tr") {
6341
- replacementHost = tagName === "td" || tagName === "th" ? null : "td";
6342
- }
6343
- const shouldExpandSelfClosing = selfClosing && !voidElements.has(replacementHost || tagName);
6429
+ replacementHost = nativeTagName === "td" || nativeTagName === "th" ? null : "td";
6430
+ } else if ((parent == null ? void 0 : parent.effectiveTag) === "colgroup") {
6431
+ replacementHost = nativeTagName === "col" ? null : "col";
6432
+ }
6433
+ const aliasTag = getTableAliasTag(replacementHost);
6434
+ const isTableAlias = aliasTag !== void 0;
6435
+ const shouldExpandSelfClosing = selfClosing && !voidElements.has(replacementHost || nativeTagName);
6436
+ const shouldCloseVoidAlias = !!replacementHost && aliasTag === nativeTagName && voidElements.has(nativeTagName);
6437
+ const shouldIgnoreClosingTag = !selfClosing && !!replacementHost && voidElements.has(replacementHost) && !shouldCloseVoidAlias;
6438
+ const shouldIgnoreNativeVoidClosingTag = !selfClosing && !replacementHost && voidElements.has(nativeTagName);
6344
6439
  if (replacementHost) {
6345
- const isAlias = replacementHost === "trx" || replacementHost === "tdx" || replacementHost === "thx";
6346
- const rewrittenTag = `${rawTag.slice(0, range.start)}${replacementHost} is="${isAlias ? `r-${tagName}` : `regor:${tagName}`}"${rawTag.slice(range.end)}`;
6440
+ const rewrittenTag = `${rawTag.slice(0, range.start)}${replacementHost} is="${aliasTag ? `r-${aliasTag}` : `regor:${tagName}`}"${rawTag.slice(range.end)}`;
6347
6441
  out.push(
6348
- shouldExpandSelfClosing ? expandSelfClosingTag(rewrittenTag, replacementHost) : rewrittenTag
6442
+ shouldExpandSelfClosing ? expandSelfClosingTag(rewrittenTag, replacementHost) : shouldCloseVoidAlias ? closeTag(rewrittenTag, replacementHost) : rewrittenTag
6349
6443
  );
6350
6444
  } else {
6351
6445
  out.push(
6352
6446
  shouldExpandSelfClosing ? expandSelfClosingTag(rawTag, tagName) : rawTag
6353
6447
  );
6354
6448
  }
6355
- if (!selfClosing) {
6356
- const effectiveTag = replacementHost === "trx" ? "tr" : replacementHost === "tdx" ? "td" : replacementHost === "thx" ? "th" : replacementHost || tagName;
6449
+ if (shouldIgnoreClosingTag) {
6450
+ ignoredClosingTags.push({ tagName, emit: false });
6451
+ } else if (shouldCloseVoidAlias && !selfClosing) {
6452
+ ignoredClosingTags.push({ tagName, emit: false });
6453
+ } else if (shouldIgnoreNativeVoidClosingTag) {
6454
+ ignoredClosingTags.push({ tagName, emit: true });
6455
+ }
6456
+ if (!selfClosing && !shouldCloseVoidAlias && !shouldIgnoreClosingTag && !shouldIgnoreNativeVoidClosingTag && !voidElements.has(replacementHost != null ? replacementHost : nativeTagName)) {
6457
+ const effectiveTag = (_b = aliasTag != null ? aliasTag : replacementHost) != null ? _b : nativeTagName || tagName;
6357
6458
  stack.push({
6358
6459
  replacementHost,
6359
- effectiveTag
6460
+ effectiveTag,
6461
+ isTableAlias
6360
6462
  });
6361
- if (tableScopeTags.has(effectiveTag)) ++tableScopeDepth;
6463
+ if (!isTableAlias && isTableScopeTag(effectiveTag)) ++tableScopeDepth;
6362
6464
  }
6363
6465
  i = tagEnd + 1;
6364
6466
  }