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.
@@ -6211,19 +6211,50 @@ var parseTagNameRange = (tagText, isClosing) => {
6211
6211
  while (i < tagText.length && (tagText[i] === " " || tagText[i] === "\n")) ++i;
6212
6212
  if (i >= tagText.length || !isNameChar(tagText[i])) return null;
6213
6213
  const start = i;
6214
- while (i < tagText.length && isNameChar(tagText[i])) ++i;
6215
- return { start, end: i };
6216
- };
6217
- var tableScopeTags = /* @__PURE__ */ new Set(["table", "thead", "tbody", "tfoot"]);
6218
- var rowParentTags = /* @__PURE__ */ new Set(["thead", "tbody", "tfoot"]);
6219
- var tableDirectAllowed = /* @__PURE__ */ new Set([
6220
- "caption",
6221
- "colgroup",
6222
- "thead",
6223
- "tbody",
6224
- "tfoot",
6225
- "tr"
6226
- ]);
6214
+ let hasUppercase = false;
6215
+ while (i < tagText.length && isNameChar(tagText[i])) {
6216
+ const c = tagText.charCodeAt(i);
6217
+ if (c >= 65 && c <= 90) {
6218
+ hasUppercase = true;
6219
+ }
6220
+ ++i;
6221
+ }
6222
+ return { start, end: i, hasUppercase };
6223
+ };
6224
+ var isTableScopeTag = (tagName) => {
6225
+ switch (tagName) {
6226
+ case "table":
6227
+ case "thead":
6228
+ case "tbody":
6229
+ case "tfoot":
6230
+ return true;
6231
+ default:
6232
+ return false;
6233
+ }
6234
+ };
6235
+ var isRowParentTag = (tagName) => {
6236
+ switch (tagName) {
6237
+ case "thead":
6238
+ case "tbody":
6239
+ case "tfoot":
6240
+ return true;
6241
+ default:
6242
+ return false;
6243
+ }
6244
+ };
6245
+ var isTableDirectAllowed = (tagName) => {
6246
+ switch (tagName) {
6247
+ case "caption":
6248
+ case "colgroup":
6249
+ case "thead":
6250
+ case "tbody":
6251
+ case "tfoot":
6252
+ case "tr":
6253
+ return true;
6254
+ default:
6255
+ return false;
6256
+ }
6257
+ };
6227
6258
  var voidElements = /* @__PURE__ */ new Set([
6228
6259
  "area",
6229
6260
  "base",
@@ -6240,12 +6271,62 @@ var voidElements = /* @__PURE__ */ new Set([
6240
6271
  "track",
6241
6272
  "wbr"
6242
6273
  ]);
6274
+ var getTableAliasHost = (tagName) => {
6275
+ switch (tagName) {
6276
+ case "caption":
6277
+ return "captionx";
6278
+ case "thead":
6279
+ return "theadx";
6280
+ case "tbody":
6281
+ return "tbodyx";
6282
+ case "tfoot":
6283
+ return "tfootx";
6284
+ case "tr":
6285
+ return "trx";
6286
+ case "td":
6287
+ return "tdx";
6288
+ case "th":
6289
+ return "thx";
6290
+ case "colgroup":
6291
+ return "colgroupx";
6292
+ case "col":
6293
+ return "colx";
6294
+ default:
6295
+ return null;
6296
+ }
6297
+ };
6298
+ var getTableAliasTag = (host) => {
6299
+ switch (host) {
6300
+ case "captionx":
6301
+ return "caption";
6302
+ case "theadx":
6303
+ return "thead";
6304
+ case "tbodyx":
6305
+ return "tbody";
6306
+ case "tfootx":
6307
+ return "tfoot";
6308
+ case "trx":
6309
+ return "tr";
6310
+ case "tdx":
6311
+ return "td";
6312
+ case "thx":
6313
+ return "th";
6314
+ case "colgroupx":
6315
+ return "colgroup";
6316
+ case "colx":
6317
+ return "col";
6318
+ default:
6319
+ return void 0;
6320
+ }
6321
+ };
6322
+ var closeTag = (tagText, tagName) => `${tagText}</${tagName}>`;
6243
6323
  var expandSelfClosingTag = (tagText, tagName) => `${tagText.slice(0, tagText.length - 2)}></${tagName}>`;
6244
6324
  var preprocess = (template) => {
6245
- var _a;
6325
+ var _a, _b;
6246
6326
  let i = 0;
6247
6327
  const out = [];
6248
6328
  const stack = [];
6329
+ const ignoredClosingTags = [];
6249
6330
  let tableScopeDepth = 0;
6250
6331
  while (i < template.length) {
6251
6332
  const lt = template.indexOf("<", i);
@@ -6284,12 +6365,21 @@ var preprocess = (template) => {
6284
6365
  continue;
6285
6366
  }
6286
6367
  const tagName = rawTag.slice(range.start, range.end);
6368
+ const nativeTagName = range.hasUppercase ? "" : tagName;
6287
6369
  if (isClosing) {
6370
+ const ignoredClosing = ignoredClosingTags[ignoredClosingTags.length - 1];
6371
+ if ((ignoredClosing == null ? void 0 : ignoredClosing.tagName) === tagName) {
6372
+ ignoredClosingTags.pop();
6373
+ if (ignoredClosing.emit) out.push(rawTag);
6374
+ i = tagEnd + 1;
6375
+ continue;
6376
+ }
6288
6377
  const top = stack[stack.length - 1];
6289
6378
  if (top) {
6290
6379
  stack.pop();
6291
6380
  out.push(top.replacementHost ? `</${top.replacementHost}>` : rawTag);
6292
- if (tableScopeTags.has(top.effectiveTag)) --tableScopeDepth;
6381
+ if (!top.isTableAlias && isTableScopeTag(top.effectiveTag))
6382
+ --tableScopeDepth;
6293
6383
  } else {
6294
6384
  out.push(rawTag);
6295
6385
  }
@@ -6300,35 +6390,47 @@ var preprocess = (template) => {
6300
6390
  const parent = stack[stack.length - 1];
6301
6391
  let replacementHost = null;
6302
6392
  if (tableScopeDepth === 0) {
6303
- if (tagName === "tr") replacementHost = "trx";
6304
- else if (tagName === "td") replacementHost = "tdx";
6305
- else if (tagName === "th") replacementHost = "thx";
6306
- } else if (rowParentTags.has((_a = parent == null ? void 0 : parent.effectiveTag) != null ? _a : "")) {
6307
- replacementHost = tagName === "tr" ? null : "tr";
6393
+ replacementHost = getTableAliasHost(nativeTagName);
6394
+ } else if (isRowParentTag((_a = parent == null ? void 0 : parent.effectiveTag) != null ? _a : "")) {
6395
+ replacementHost = nativeTagName === "tr" ? null : "tr";
6308
6396
  } else if ((parent == null ? void 0 : parent.effectiveTag) === "table") {
6309
- replacementHost = tableDirectAllowed.has(tagName) ? null : "tr";
6397
+ replacementHost = isTableDirectAllowed(nativeTagName) ? null : "tr";
6310
6398
  } else if ((parent == null ? void 0 : parent.effectiveTag) === "tr") {
6311
- replacementHost = tagName === "td" || tagName === "th" ? null : "td";
6312
- }
6313
- const shouldExpandSelfClosing = selfClosing && !voidElements.has(replacementHost || tagName);
6399
+ replacementHost = nativeTagName === "td" || nativeTagName === "th" ? null : "td";
6400
+ } else if ((parent == null ? void 0 : parent.effectiveTag) === "colgroup") {
6401
+ replacementHost = nativeTagName === "col" ? null : "col";
6402
+ }
6403
+ const aliasTag = getTableAliasTag(replacementHost);
6404
+ const isTableAlias = aliasTag !== void 0;
6405
+ const shouldExpandSelfClosing = selfClosing && !voidElements.has(replacementHost || nativeTagName);
6406
+ const shouldCloseVoidAlias = !!replacementHost && aliasTag === nativeTagName && voidElements.has(nativeTagName);
6407
+ const shouldIgnoreClosingTag = !selfClosing && !!replacementHost && voidElements.has(replacementHost) && !shouldCloseVoidAlias;
6408
+ const shouldIgnoreNativeVoidClosingTag = !selfClosing && !replacementHost && voidElements.has(nativeTagName);
6314
6409
  if (replacementHost) {
6315
- const isAlias = replacementHost === "trx" || replacementHost === "tdx" || replacementHost === "thx";
6316
- const rewrittenTag = `${rawTag.slice(0, range.start)}${replacementHost} is="${isAlias ? `r-${tagName}` : `regor:${tagName}`}"${rawTag.slice(range.end)}`;
6410
+ const rewrittenTag = `${rawTag.slice(0, range.start)}${replacementHost} is="${aliasTag ? `r-${aliasTag}` : `regor:${tagName}`}"${rawTag.slice(range.end)}`;
6317
6411
  out.push(
6318
- shouldExpandSelfClosing ? expandSelfClosingTag(rewrittenTag, replacementHost) : rewrittenTag
6412
+ shouldExpandSelfClosing ? expandSelfClosingTag(rewrittenTag, replacementHost) : shouldCloseVoidAlias ? closeTag(rewrittenTag, replacementHost) : rewrittenTag
6319
6413
  );
6320
6414
  } else {
6321
6415
  out.push(
6322
6416
  shouldExpandSelfClosing ? expandSelfClosingTag(rawTag, tagName) : rawTag
6323
6417
  );
6324
6418
  }
6325
- if (!selfClosing) {
6326
- const effectiveTag = replacementHost === "trx" ? "tr" : replacementHost === "tdx" ? "td" : replacementHost === "thx" ? "th" : replacementHost || tagName;
6419
+ if (shouldIgnoreClosingTag) {
6420
+ ignoredClosingTags.push({ tagName, emit: false });
6421
+ } else if (shouldCloseVoidAlias && !selfClosing) {
6422
+ ignoredClosingTags.push({ tagName, emit: false });
6423
+ } else if (shouldIgnoreNativeVoidClosingTag) {
6424
+ ignoredClosingTags.push({ tagName, emit: true });
6425
+ }
6426
+ if (!selfClosing && !shouldCloseVoidAlias && !shouldIgnoreClosingTag && !shouldIgnoreNativeVoidClosingTag && !voidElements.has(replacementHost != null ? replacementHost : nativeTagName)) {
6427
+ const effectiveTag = (_b = aliasTag != null ? aliasTag : replacementHost) != null ? _b : nativeTagName || tagName;
6327
6428
  stack.push({
6328
6429
  replacementHost,
6329
- effectiveTag
6430
+ effectiveTag,
6431
+ isTableAlias
6330
6432
  });
6331
- if (tableScopeTags.has(effectiveTag)) ++tableScopeDepth;
6433
+ if (!isTableAlias && isTableScopeTag(effectiveTag)) ++tableScopeDepth;
6332
6434
  }
6333
6435
  i = tagEnd + 1;
6334
6436
  }