tw-framework 2.0.3 → 2.0.5

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.
@@ -152786,9 +152786,9 @@ ${lanes.join("\n")}
152786
152786
  /*ignoreCase*/
152787
152787
  false
152788
152788
  )) {
152789
- const basename3 = getBaseFileName(a.fileName);
152790
- if (basename3 === "lib.d.ts" || basename3 === "lib.es6.d.ts") return 0;
152791
- const name = removeSuffix(removePrefix(basename3, "lib."), ".d.ts");
152789
+ const basename4 = getBaseFileName(a.fileName);
152790
+ if (basename4 === "lib.d.ts" || basename4 === "lib.es6.d.ts") return 0;
152791
+ const name = removeSuffix(removePrefix(basename4, "lib."), ".d.ts");
152792
152792
  const index = libs.indexOf(name);
152793
152793
  if (index !== -1) return index + 1;
152794
152794
  }
@@ -216384,8 +216384,8 @@ ${options.prefix}` : "\n" : options.prefix
216384
216384
  }
216385
216385
  };
216386
216386
  for (const file of files) {
216387
- const basename3 = getBaseFileName(file);
216388
- if (basename3 === "package.json" || basename3 === "bower.json") {
216387
+ const basename4 = getBaseFileName(file);
216388
+ if (basename4 === "package.json" || basename4 === "bower.json") {
216389
216389
  createProjectWatcher(
216390
216390
  file,
216391
216391
  "FileWatcher"
@@ -220053,8 +220053,8 @@ All files are: ${JSON.stringify(names)}`,
220053
220053
  var _a;
220054
220054
  const fileOrDirectoryPath = removeIgnoredPath(this.toPath(fileOrDirectory));
220055
220055
  if (!fileOrDirectoryPath) return;
220056
- const basename3 = getBaseFileName(fileOrDirectoryPath);
220057
- if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename3 === "package.json" || basename3 === "node_modules")) {
220056
+ const basename4 = getBaseFileName(fileOrDirectoryPath);
220057
+ if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename4 === "package.json" || basename4 === "node_modules")) {
220058
220058
  result.affectedModuleSpecifierCacheProjects.forEach((project) => {
220059
220059
  var _a2;
220060
220060
  (_a2 = project.getModuleSpecifierCache()) == null ? void 0 : _a2.clear();
@@ -228018,7 +228018,51 @@ function parseStatements(cursor, errors, opts) {
228018
228018
  "cols",
228019
228019
  "rows",
228020
228020
  "wrap",
228021
- "datetime"
228021
+ "datetime",
228022
+ // SVG attributes. `path d "M4 7h16"` was read as text "path" plus a
228023
+ // <d> element, because `d` was not a known attribute name -- so an
228024
+ // inline icon could not be written at all.
228025
+ "d",
228026
+ "cx",
228027
+ "cy",
228028
+ "r",
228029
+ "rx",
228030
+ "ry",
228031
+ "x",
228032
+ "y",
228033
+ "x1",
228034
+ "y1",
228035
+ "x2",
228036
+ "y2",
228037
+ "points",
228038
+ "viewBox",
228039
+ "fill",
228040
+ "stroke",
228041
+ "stroke-width",
228042
+ "stroke-linecap",
228043
+ "stroke-linejoin",
228044
+ "stroke-dasharray",
228045
+ "stroke-dashoffset",
228046
+ "fill-rule",
228047
+ "clip-rule",
228048
+ "clip-path",
228049
+ "transform",
228050
+ "opacity",
228051
+ "fill-opacity",
228052
+ "stroke-opacity",
228053
+ "stop-color",
228054
+ "offset",
228055
+ "gradientUnits",
228056
+ "gradientTransform",
228057
+ "preserveAspectRatio",
228058
+ "text-anchor",
228059
+ "dominant-baseline",
228060
+ "font-size",
228061
+ "font-family",
228062
+ "marker-end",
228063
+ "marker-start",
228064
+ "mask",
228065
+ "xmlns"
228022
228066
  ]);
228023
228067
  const isSelector = nextTok && (nextTok.type === "DOT" || nextTok.type === "HASH" || nextTok.type === "LBRACE" || nextTok.type === "STRING" || // `width 800` — a bare IDENT followed by a NUMBER is a prop/value
228024
228068
  // pair (builtin component props accept numbers), not text content.
@@ -228585,6 +228629,15 @@ function parseElement(cursor, errors, state, parseBody) {
228585
228629
  const tagToken = cursor.advance();
228586
228630
  if (!tagToken) return null;
228587
228631
  const tag2 = tagToken.value;
228632
+ if (tag2 && /^[A-Za-z][A-Za-z0-9-]*$/.test(tag2)) {
228633
+ errors.add(new CompilerError(
228634
+ "raw HTML is not supported in .tw -- write it in TW syntax: " + tag2 + ' { ... }. For an inline icon use svg/path/circle with attributes on the tag line; for a script body use script type "..." { ... }; for markup that comes from data use {@html expr}',
228635
+ tagToken.pos.line,
228636
+ tagToken.pos.col,
228637
+ "TW123",
228638
+ "error"
228639
+ ));
228640
+ }
228588
228641
  const controlFlowTags = {
228589
228642
  "if": "if",
228590
228643
  "for": "for",
@@ -237242,7 +237295,7 @@ var init_types4 = __esm({
237242
237295
  var TW_VERSION, TW_GENERATOR_META;
237243
237296
  var init_version = __esm({
237244
237297
  "../../packages/compiler/tw/codegen/version.ts"() {
237245
- TW_VERSION = "2.0.3";
237298
+ TW_VERSION = "2.0.5";
237246
237299
  TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
237247
237300
  }
237248
237301
  });
@@ -238525,6 +238578,39 @@ function validatePlainCss(src, filePath) {
238525
238578
  checkDecl();
238526
238579
  return src;
238527
238580
  }
238581
+ function collapseWhitespace(text) {
238582
+ let out = "";
238583
+ let quote = null;
238584
+ let pendingSpace = false;
238585
+ for (let i = 0; i < text.length; i++) {
238586
+ const ch = text[i];
238587
+ if (quote) {
238588
+ out += ch;
238589
+ if (ch === "\\" && i + 1 < text.length) {
238590
+ out += text[i + 1];
238591
+ i++;
238592
+ continue;
238593
+ }
238594
+ if (ch === quote) quote = null;
238595
+ continue;
238596
+ }
238597
+ if (ch === '"' || ch === "'") {
238598
+ if (pendingSpace && out) out += " ";
238599
+ pendingSpace = false;
238600
+ quote = ch;
238601
+ out += ch;
238602
+ continue;
238603
+ }
238604
+ if (/\s/.test(ch)) {
238605
+ pendingSpace = true;
238606
+ continue;
238607
+ }
238608
+ if (pendingSpace && out) out += " ";
238609
+ pendingSpace = false;
238610
+ out += ch;
238611
+ }
238612
+ return out;
238613
+ }
238528
238614
  function compileDecl(decl) {
238529
238615
  const trimmed = decl.trim();
238530
238616
  if (!trimmed) return "";
@@ -238532,10 +238618,10 @@ function compileDecl(decl) {
238532
238618
  if (cssForm) return trimmed.replace(/^([-\w]+)\s*:\s*/, "$1: ");
238533
238619
  const spaceIdx = trimmed.search(/[\s]/);
238534
238620
  if (spaceIdx === -1) {
238535
- return TSS_SHORTHANDS2[trimmed] ?? trimmed;
238621
+ return "";
238536
238622
  }
238537
238623
  const prop = trimmed.slice(0, spaceIdx);
238538
- const value = trimmed.slice(spaceIdx).trim();
238624
+ const value = collapseWhitespace(trimmed.slice(spaceIdx).trim());
238539
238625
  const full = TSS_SHORTHANDS2[prop] ?? prop;
238540
238626
  return `${full}: ${value}`;
238541
238627
  }
@@ -238693,26 +238779,47 @@ function __twCompileTSSInner(source) {
238693
238779
  if (!changed) break;
238694
238780
  }
238695
238781
  }
238696
- const rules = [];
238782
+ const root = [];
238697
238783
  const stack = [];
238698
- const declsByLevel = [];
238699
238784
  let buf = "";
238700
- const emit4 = (selector, decls, wrapStack) => {
238701
- if (decls.length === 0) return;
238702
- let rule = `${selector} { ${decls.join("; ")} }`;
238703
- for (let i2 = wrapStack.length - 1; i2 >= 0; i2--) {
238704
- if (wrapStack[i2].startsWith("@")) rule = `${wrapStack[i2]} { ${rule} }`;
238705
- }
238706
- rules.push(rule);
238707
- };
238785
+ const current2 = () => stack.length ? stack[stack.length - 1] : null;
238786
+ const statements = [];
238787
+ const isStatementAtRule = (t3) => /^@(import|charset|namespace|layer)\b/.test(t3);
238708
238788
  const pushDecl = (text) => {
238709
- const d = compileDecl(text);
238710
- if (d) (declsByLevel[declsByLevel.length - 1] ??= []).push(d);
238789
+ const raw = text.trim();
238790
+ if (!raw) return;
238791
+ if (isStatementAtRule(raw)) {
238792
+ statements.push(raw.endsWith(";") ? raw : raw + ";");
238793
+ return;
238794
+ }
238795
+ const d = compileDecl(raw);
238796
+ if (!d) return;
238797
+ const node = current2();
238798
+ if (node) node.decls.push(d);
238799
+ else root.push({ kind: "rule", selector: "*", decls: [d], children: [] });
238711
238800
  };
238712
- const isDeclLine = (l) => /^[a-zA-Z][\w-]*(\s|:)/.test(l) && !/^[>+~]/.test(l);
238801
+ const isDeclLine = (l) => /^(--[A-Za-z][\w-]*|-?[A-Za-z][\w-]*)(\s|:)/.test(l) && !/^[>+~]/.test(l);
238713
238802
  let i = 0;
238803
+ let quote = null;
238714
238804
  while (i < src.length) {
238715
238805
  const ch = src[i];
238806
+ if (quote) {
238807
+ buf += ch;
238808
+ if (ch === "\\" && i + 1 < src.length) {
238809
+ buf += src[i + 1];
238810
+ i += 2;
238811
+ continue;
238812
+ }
238813
+ if (ch === quote) quote = null;
238814
+ i++;
238815
+ continue;
238816
+ }
238817
+ if (ch === '"' || ch === "'") {
238818
+ quote = ch;
238819
+ buf += ch;
238820
+ i++;
238821
+ continue;
238822
+ }
238716
238823
  if (ch === "{") {
238717
238824
  let sel = buf.trim();
238718
238825
  buf = "";
@@ -238725,53 +238832,38 @@ function __twCompileTSSInner(source) {
238725
238832
  const last = lines[lines.length - 1];
238726
238833
  const prior = lines.slice(0, -1);
238727
238834
  const priorComplete = !/[(,]\s*$/.test(prior[prior.length - 1] ?? "");
238728
- if (priorComplete && prior.every(isDeclLine) && !last.startsWith("@")) {
238835
+ if (priorComplete && prior.every(isDeclLine)) {
238729
238836
  for (const p of prior) pushDecl(p);
238730
238837
  sel = last;
238731
238838
  }
238732
238839
  }
238733
- const parent = stack.length ? stack[stack.length - 1] : "";
238734
- let full;
238840
+ const parent = current2();
238735
238841
  if (sel.startsWith("@")) {
238736
- full = sel;
238737
- } else if (parent && !parent.startsWith("@")) {
238738
- full = combineSelector(parent, sel);
238842
+ const node = { kind: "at", head: sel, decls: [], children: [] };
238843
+ (parent ? parent.children : root).push(node);
238844
+ stack.push(node);
238739
238845
  } else {
238740
- full = sel;
238846
+ const full = parent && parent.kind === "rule" ? combineSelector(parent.selector, sel) : sel;
238847
+ const node = { kind: "rule", selector: full, decls: [], children: [] };
238848
+ (parent ? parent.children : root).push(node);
238849
+ stack.push(node);
238741
238850
  }
238742
- stack.push(full);
238743
- declsByLevel.push([]);
238744
238851
  i++;
238745
238852
  } else if (ch === "}") {
238746
238853
  if (buf.trim()) {
238747
238854
  const blines = buf.split(/\n+/).map((l) => l.trim()).filter(Boolean);
238748
- if (blines.length > 1 && blines.every(isDeclLine)) {
238855
+ const valueContinues = blines.some((l) => /[(,]\s*$/.test(l));
238856
+ if (blines.length > 1 && !valueContinues) {
238749
238857
  for (const l of blines) pushDecl(l);
238750
238858
  } else {
238751
238859
  pushDecl(buf);
238752
238860
  }
238753
238861
  }
238754
238862
  buf = "";
238755
- const level = stack.pop();
238756
- const decls = declsByLevel.pop() ?? [];
238757
- if (level) {
238758
- if (level.startsWith("@") && decls.length > 0) {
238759
- let realSel = null;
238760
- for (let j = stack.length - 1; j >= 0; j--) {
238761
- if (!stack[j].startsWith("@")) {
238762
- realSel = stack[j];
238763
- break;
238764
- }
238765
- }
238766
- if (realSel) emit4(realSel, decls, [...stack, level]);
238767
- else emit4(level, decls, stack);
238768
- } else {
238769
- emit4(level, decls, stack);
238770
- }
238771
- }
238863
+ stack.pop();
238772
238864
  i++;
238773
238865
  } else if (ch === ";") {
238774
- pushDecl(buf);
238866
+ if (buf.trim()) pushDecl(buf);
238775
238867
  buf = "";
238776
238868
  i++;
238777
238869
  } else {
@@ -238779,11 +238871,24 @@ function __twCompileTSSInner(source) {
238779
238871
  i++;
238780
238872
  }
238781
238873
  }
238782
- if (buf.trim()) {
238783
- const d = compileDecl(buf);
238784
- if (d && stack.length === 0) rules.push(`* { ${d} }`);
238785
- }
238786
- return rules.join("\n");
238874
+ if (buf.trim()) pushDecl(buf);
238875
+ const ser = (node, parentSel) => {
238876
+ if (node.kind === "rule") {
238877
+ const lines = [];
238878
+ if (node.decls.length) lines.push(node.selector + " { " + node.decls.join("; ") + " }");
238879
+ for (const c of node.children) lines.push(...ser(c, node.selector));
238880
+ return lines;
238881
+ }
238882
+ const inner = [];
238883
+ if (node.decls.length) {
238884
+ inner.push(parentSel ? parentSel + " { " + node.decls.join("; ") + " }" : node.decls.join("; "));
238885
+ }
238886
+ for (const c of node.children) inner.push(...ser(c, parentSel));
238887
+ return [node.head + " { " + inner.join(" ") + " }"];
238888
+ };
238889
+ const out = [...statements];
238890
+ for (const node of root) out.push(...ser(node, ""));
238891
+ return out.join("\n");
238787
238892
  }
238788
238893
  var TSS_SHORTHANDS2;
238789
238894
  var init_tss = __esm({
@@ -238827,6 +238932,12 @@ var init_tss = __esm({
238827
238932
  "br-t": "border-top-left-radius",
238828
238933
  bxsh: "box-shadow",
238829
238934
  bxz: "box-sizing",
238935
+ // Documented in docs/tss-syntax.md but never implemented, so `br-tl 4px`
238936
+ // emitted the literal property name `br-tl` and the corner stayed square.
238937
+ "br-tl": "border-top-left-radius",
238938
+ "br-tr": "border-top-right-radius",
238939
+ "br-bl": "border-bottom-left-radius",
238940
+ "br-br": "border-bottom-right-radius",
238830
238941
  // `box` is the documented box-sizing shorthand (docs/tss-syntax.md).
238831
238942
  box: "box-sizing",
238832
238943
  // typography
@@ -238868,7 +238979,13 @@ var init_tss = __esm({
238868
238979
  tr: "transition",
238869
238980
  tf: "transform",
238870
238981
  us: "user-select",
238871
- pe: "pointer-events"
238982
+ pe: "pointer-events",
238983
+ // Also documented, also missing.
238984
+ fl: "float",
238985
+ cl: "clear",
238986
+ dir: "direction",
238987
+ ww: "word-wrap",
238988
+ va: "vertical-align"
238872
238989
  };
238873
238990
  }
238874
238991
  });
@@ -240008,7 +240125,9 @@ function generateElement(el, ctx) {
240008
240125
  if (el.children.length === 0 && el.selfClosing) {
240009
240126
  return `<${tag2}${attrPrefix}></${tag2}>`;
240010
240127
  }
240011
- const childrenHTML = el.children.map((c) => generateNode(c, ctx)).join("");
240128
+ const isRawText = tag2 === "script" || tag2 === "style";
240129
+ const childCtx = isRawText ? { ...ctx, rawText: true } : ctx;
240130
+ const childrenHTML = el.children.map((c) => generateNode(c, childCtx)).join("");
240012
240131
  return `<${tag2}${attrPrefix}>${childrenHTML}</${tag2}>`;
240013
240132
  }
240014
240133
  function renderAttrs(el, ctx) {
@@ -240139,10 +240258,30 @@ function wrapInterpolations(rendered, raw) {
240139
240258
  }
240140
240259
  return out;
240141
240260
  }
240261
+ function generateTrustedHtml(text, ctx) {
240262
+ const src = text.isInterpolated ? `{${text.value}}` : String(text.value ?? "");
240263
+ let out = "";
240264
+ let i = 0;
240265
+ const re = /\{@html\s+([^}]*)\}/g;
240266
+ let m;
240267
+ while (m = re.exec(src)) {
240268
+ out += escapeHTML(interpolate2(src.slice(i, m.index), ctx.stateVars));
240269
+ out += String(interpolate2(`{${m[1]}}`, ctx.stateVars));
240270
+ i = m.index + m[0].length;
240271
+ }
240272
+ out += escapeHTML(interpolate2(src.slice(i), ctx.stateVars));
240273
+ return out;
240274
+ }
240142
240275
  function generateText(text, ctx) {
240143
240276
  ctx_global_interactive = ctx.interactive === true;
240144
240277
  ctx_global_inhead = ctx.inHead === true;
240145
240278
  lastStateVars = ctx.stateVars;
240279
+ if (text.value && String(text.value).includes("@html")) return generateTrustedHtml(text, ctx);
240280
+ if (ctx.rawText) {
240281
+ if (text.isInterpolated) return String(interpolate2(`{${text.value}}`, ctx.stateVars));
240282
+ if (text.value && /\{[^}]+\}/.test(text.value)) return String(interpolate2(text.value, ctx.stateVars));
240283
+ return text.value ?? "";
240284
+ }
240146
240285
  if (text.isInterpolated) {
240147
240286
  if (ctx.interactive && ctx.inHead !== true) {
240148
240287
  return `<span data-tw-i="${escapeHTML(text.value)}"${dataTwSFor(text.value)}>${escapeHTML(interpolate2(`{${text.value}}`, ctx.stateVars))}</span>`;
@@ -241443,7 +241582,7 @@ function minifyHTML2(html, options) {
241443
241582
  result = removeComments(result);
241444
241583
  }
241445
241584
  if (opts.collapseWhitespace) {
241446
- result = collapseWhitespace(result);
241585
+ result = collapseWhitespace2(result);
241447
241586
  }
241448
241587
  if (opts.removeRedundantAttrs) {
241449
241588
  result = removeRedundantAttrs(result);
@@ -241466,7 +241605,7 @@ function removeComments(html) {
241466
241605
  if (html.indexOf("<!--") === -1) return html;
241467
241606
  return html.replace(/<!--(?!\[if\s)[\s\S]*?-->/g, "");
241468
241607
  }
241469
- function collapseWhitespace(html) {
241608
+ function collapseWhitespace2(html) {
241470
241609
  const result = [];
241471
241610
  let pos = 0;
241472
241611
  let inPreserved = false;
@@ -244094,6 +244233,15 @@ function generateWithLayout(layoutProgram, pageProgram, stateVars) {
244094
244233
  function generateWithLayoutChain(layoutPrograms, pageProgram, stateVars) {
244095
244234
  const seedCtx = (ctx2) => {
244096
244235
  if (stateVars) ctx2.stateVars = { ...stateVars };
244236
+ for (const lp of layoutPrograms ?? []) {
244237
+ for (const dir of lp.directives || []) {
244238
+ if (dir.type === "StateDirective") {
244239
+ for (const decl of dir.declarations || []) {
244240
+ ctx2.stateVars[decl.name] = stateLiteralForRender(decl.value);
244241
+ }
244242
+ }
244243
+ }
244244
+ }
244097
244245
  for (const dir of pageProgram.directives || []) {
244098
244246
  if (dir.type === "StateDirective") {
244099
244247
  for (const decl of dir.declarations || []) {
@@ -244715,7 +244863,7 @@ var init_codes = __esm({
244715
244863
  TW105: { message: "Server blocks in layouts are not supported yet", severity: "error", category: "semantic" },
244716
244864
  TW106: { message: "Request context (headers/cookies/query/params) is not available in a static server block", severity: "error", category: "semantic" },
244717
244865
  TW107: { message: "getSession()/requireUser() are not available in a static page's server block", severity: "error", category: "semantic" },
244718
- TW108: { message: "redirect()/notFound() are not available in a static page's server block", severity: "error", category: "semantic" },
244866
+ TW108: { message: "redirect() is not available in a static page's server block", severity: "error", category: "semantic" },
244719
244867
  TW109: { message: "redirect() target must be a same-origin internal path", severity: "error", category: "semantic" },
244720
244868
  TW110: { message: "A cached fetch must not set an Authorization, Proxy-Authorization or Cookie header", severity: "error", category: "semantic" },
244721
244869
  TW111: { message: "A cached page's server block cannot read headers, cookies, getSession() or requireUser()", severity: "error", category: "semantic" },
@@ -244729,6 +244877,8 @@ var init_codes = __esm({
244729
244877
  TW119: { message: "A deferred server block cannot be used on a cached page -- cache { } serves one HTML to every request", severity: "error", category: "semantic" },
244730
244878
  TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
244731
244879
  TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
244880
+ TW123: { message: "Raw HTML is not supported in .tw -- write the element in TW syntax", severity: "error", category: "syntax" },
244881
+ TW125: { message: "An import's local name is also a server-block built-in, so the import would be silently overwritten", severity: "error", category: "semantic" },
244732
244882
  // Codes thrown outside the rule engine. TW303 comes from the stylesheet
244733
244883
  // parser (codegen/tss.ts); TW000 is the generic fallback used when an error
244734
244884
  // carries no code of its own.
@@ -244929,8 +245079,17 @@ function checkPerformance(program, filePath, diags) {
244929
245079
  ]));
244930
245080
  }
244931
245081
  if (isElement(node) && node.tag.toLowerCase() === "img") {
245082
+ const attr = (n) => node.attrs.find((a) => a.name === n)?.value;
244932
245083
  const hasLazy = node.attrs.some((a) => a.name === "loading" && a.value === "lazy");
244933
- if (!hasLazy) {
245084
+ const isEager = String(attr("loading") ?? "") === "eager" || String(attr("fetchpriority") ?? "") === "high";
245085
+ const px = (v) => {
245086
+ const n = parseFloat(String(v ?? ""));
245087
+ return Number.isFinite(n) ? n : null;
245088
+ };
245089
+ const w = px(attr("width"));
245090
+ const h3 = px(attr("height"));
245091
+ const isSmallIcon = w !== null && h3 !== null && w <= 32 && h3 <= 32;
245092
+ if (!hasLazy && !isEager && !isSmallIcon) {
244934
245093
  diags.push(createDiagnostic("TW054", node.line, node.col, filePath, void 0, [
244935
245094
  'Add loading="lazy" for below-fold images'
244936
245095
  ]));
@@ -245403,9 +245562,97 @@ var init_rules = __esm({
245403
245562
  "noframes",
245404
245563
  "area",
245405
245564
  "map",
245406
- "marquee"
245565
+ "marquee",
245566
+ // Inline text tags. `b` and `i` were missing, so breadcrumbs and emphasis
245567
+ // collected a TW003 per tag on markup that renders perfectly well.
245568
+ "b",
245569
+ "i",
245570
+ "em",
245571
+ "strong",
245572
+ "small",
245573
+ "u",
245574
+ "s",
245575
+ "ins",
245576
+ "del",
245577
+ "sub",
245578
+ "sup",
245579
+ "nobr",
245580
+ "big",
245581
+ "tt",
245582
+ // SVG children -- the same warning fired on inline icons.
245583
+ "circle",
245584
+ "path",
245585
+ "rect",
245586
+ "line",
245587
+ "polyline",
245588
+ "polygon",
245589
+ "g",
245590
+ "defs",
245591
+ "use",
245592
+ "text",
245593
+ "ellipse",
245594
+ "tspan",
245595
+ "clippath",
245596
+ "lineargradient",
245597
+ "radialgradient",
245598
+ "stop",
245599
+ "mask",
245600
+ "pattern",
245601
+ "symbol",
245602
+ "marker",
245603
+ "filter",
245604
+ "foreignobject"
245407
245605
  ]);
245408
245606
  HTML_ATTRIBUTES2 = /* @__PURE__ */ new Set([
245607
+ // SVG attributes. This rule keeps its own copy of the list, and it was missing
245608
+ // every SVG name, so an inline icon raised a TW006 per attribute.
245609
+ "d",
245610
+ "cx",
245611
+ "cy",
245612
+ "r",
245613
+ "rx",
245614
+ "ry",
245615
+ "x",
245616
+ "y",
245617
+ "x1",
245618
+ "y1",
245619
+ "x2",
245620
+ "y2",
245621
+ "points",
245622
+ "viewBox",
245623
+ "fill",
245624
+ "stroke",
245625
+ "stroke-width",
245626
+ "stroke-linecap",
245627
+ "stroke-linejoin",
245628
+ "stroke-dasharray",
245629
+ "stroke-dashoffset",
245630
+ "stroke-opacity",
245631
+ "fill-opacity",
245632
+ "fill-rule",
245633
+ "clip-rule",
245634
+ "clip-path",
245635
+ "opacity",
245636
+ "transform",
245637
+ "preserveAspectRatio",
245638
+ "xmlns",
245639
+ "gradientUnits",
245640
+ "gradientTransform",
245641
+ "offset",
245642
+ "stop-color",
245643
+ "stop-opacity",
245644
+ "text-anchor",
245645
+ "dominant-baseline",
245646
+ "font-family",
245647
+ "font-size",
245648
+ "font-weight",
245649
+ "font-style",
245650
+ "letter-spacing",
245651
+ "marker-start",
245652
+ "marker-mid",
245653
+ "marker-end",
245654
+ "mask",
245655
+ "pathLength",
245409
245656
  "accept",
245410
245657
  "accept-charset",
245411
245658
  "accesskey",
@@ -248609,20 +248856,36 @@ var node_import_exports = {};
248609
248856
  __export(node_import_exports, {
248610
248857
  twImportTs: () => twImportTs
248611
248858
  });
248612
- import { join as join12 } from "node:path";
248859
+ import { join as join12, dirname as dirname7, basename as basename2, extname as extname6 } from "node:path";
248613
248860
  import { tmpdir as tmpdir2 } from "node:os";
248614
248861
  import { pathToFileURL as pathToFileURL2 } from "node:url";
248615
- async function twImportTs(tsPath, bust) {
248862
+ import { writeFileSync as writeFileSync4, rmSync as rmSync2 } from "node:fs";
248863
+ async function twImportTs(tsPath, bust, opts) {
248616
248864
  const q = bust ? "?v=" + bust : "";
248865
+ const override = opts?.source;
248617
248866
  if (!globalThis.__TW_NODE) {
248618
- return import(tsPath + q);
248867
+ if (override === void 0) return import(tsPath + q);
248868
+ const ext = extname6(tsPath) || ".ts";
248869
+ const unique = process.pid + "-" + (overrideSeq++).toString(36) + "-" + Math.random().toString(36).slice(2, 8);
248870
+ const tmpPath = join12(dirname7(tsPath), "." + basename2(tsPath, ext) + ".tw-override-" + unique + ext);
248871
+ writeFileSync4(tmpPath, override, "utf-8");
248872
+ try {
248873
+ return await import(tmpPath + q);
248874
+ } finally {
248875
+ try {
248876
+ rmSync2(tmpPath, { force: true });
248877
+ } catch {
248878
+ }
248879
+ }
248619
248880
  }
248620
248881
  const esbuildMain = globalThis.__TW_ESBUILD_MODULE;
248621
248882
  const esbuild = await (esbuildMain ? import(esbuildMain) : import("esbuild"));
248622
248883
  const safe = tsPath.replace(/[^a-zA-Z0-9]/g, "_").slice(-120);
248623
248884
  const cachePath = join12(tmpdir2(), "tw-" + safe + (bust ? "-" + bust : "") + ".mjs");
248624
248885
  await esbuild.build({
248625
- entryPoints: [tsPath],
248886
+ // stdin + resolveDir keeps relative imports resolving from the original
248887
+ // file's directory, and sourcefile keeps error locations on the real file.
248888
+ ...override === void 0 ? { entryPoints: [tsPath] } : { stdin: { contents: override, resolveDir: dirname7(tsPath), sourcefile: tsPath, loader: extname6(tsPath) === ".js" ? "js" : "ts" } },
248626
248889
  bundle: true,
248627
248890
  format: "esm",
248628
248891
  platform: "node",
@@ -248632,12 +248895,15 @@ async function twImportTs(tsPath, bust) {
248632
248895
  });
248633
248896
  return import(pathToFileURL2(cachePath).href + q);
248634
248897
  }
248898
+ var overrideSeq;
248635
248899
  var init_node_import = __esm({
248636
248900
  "../../packages/shared/tw/node-import.ts"() {
248901
+ overrideSeq = 0;
248637
248902
  }
248638
248903
  });
248639
248904
 
248640
248905
  // ../../packages/compiler/tw/server-blocks/index.ts
248906
+ import { readFileSync as readFileSync6, existsSync as existsSync9 } from "node:fs";
248641
248907
  function encodeServerValue(v) {
248642
248908
  if (v === void 0) return "";
248643
248909
  if (v === null) return "null";
@@ -248894,41 +249160,45 @@ function withTimeout2(p, ms, label) {
248894
249160
  });
248895
249161
  });
248896
249162
  }
248897
- function importBindingNames(stmt) {
248898
- const names = [];
248899
- const s = stmt.replace(/^import\s+(type\s+)?/, "");
249163
+ function importBindings(stmt) {
249164
+ const out = [];
249165
+ const s = stmt.replace(/^import\s+(type\s+)?/, "").trim();
248900
249166
  const fromIdx = s.lastIndexOf(" from ");
248901
- if (fromIdx < 0) return names;
249167
+ if (fromIdx < 0) return out;
248902
249168
  const clause = s.slice(0, fromIdx).trim();
248903
- if (clause.startsWith("{")) {
248904
- for (const part of clause.slice(1, -1).split(",")) {
249169
+ if (!clause.startsWith("{") && !clause.startsWith("*")) {
249170
+ const first = clause.split(",")[0].trim();
249171
+ if (first && /^[A-Za-z_$]/.test(first)) out.push({ local: first, imported: "default", kind: "default" });
249172
+ }
249173
+ const ns = clause.match(/\*\s+as\s+([A-Za-z_$][\w$]*)/);
249174
+ if (ns) out.push({ local: ns[1], imported: "*", kind: "namespace" });
249175
+ const braces = clause.match(/\{([\s\S]*)\}/);
249176
+ if (braces) {
249177
+ for (const part of braces[1].split(",")) {
248905
249178
  const t3 = part.trim();
248906
249179
  if (!t3) continue;
248907
- const as = t3.split(/\s+as\s+/);
248908
- names.push((as[1] ?? as[0]).trim());
249180
+ const parts = t3.split(/\s+as\s+/);
249181
+ const imported = parts[0].trim();
249182
+ const local = (parts[1] ?? parts[0]).trim();
249183
+ if (local) out.push({ local, imported, kind: "named" });
248909
249184
  }
248910
- } else if (clause.startsWith("*")) {
248911
- const as = clause.split(/\s+as\s+/);
248912
- if (as[1]) names.push(as[1].trim());
248913
- } else {
248914
- const first = clause.split(",")[0].trim();
248915
- if (first && /^[A-Za-z_$]/.test(first)) names.push(first);
248916
249185
  }
248917
- return names;
249186
+ return out;
248918
249187
  }
248919
249188
  async function resolveServerImports(block, pageFile, opts = {}) {
248920
249189
  if (!block.imports.length) return {};
248921
249190
  const out = {};
248922
249191
  const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
248923
- const { dirname: dirname9, resolve: resolve4 } = await import("node:path");
249192
+ const { dirname: dirname10, resolve: resolve4 } = await import("node:path");
248924
249193
  const { statSync: statSync6 } = await import("node:fs");
248925
249194
  for (const imp of block.imports) {
248926
249195
  if (!imp.specifier) continue;
248927
249196
  const spec = imp.specifier;
249197
+ if (spec === "@tw/server-only" || spec === "@tw/client-safe") continue;
248928
249198
  let mod;
248929
249199
  if (spec.startsWith("./") || spec.startsWith("../") || spec.startsWith("@./")) {
248930
249200
  const rel = spec.startsWith("@./") ? spec.slice(2) : spec;
248931
- const abs = resolve4(dirname9(pageFile), rel);
249201
+ const abs = resolve4(dirname10(pageFile), rel);
248932
249202
  let bust;
248933
249203
  if (opts.dev) {
248934
249204
  try {
@@ -248936,12 +249206,49 @@ async function resolveServerImports(block, pageFile, opts = {}) {
248936
249206
  } catch {
248937
249207
  }
248938
249208
  }
248939
- mod = await twImportTs2(abs, bust);
249209
+ let override;
249210
+ try {
249211
+ let realAbs = abs;
249212
+ if (!existsSync9(realAbs)) {
249213
+ for (const ext of [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"]) {
249214
+ if (existsSync9(realAbs + ext)) {
249215
+ realAbs = realAbs + ext;
249216
+ break;
249217
+ }
249218
+ }
249219
+ }
249220
+ const raw = readFileSync6(realAbs, "utf-8");
249221
+ if (MARKER_IMPORT_RE.test(raw)) {
249222
+ MARKER_IMPORT_RE.lastIndex = 0;
249223
+ override = raw.replace(MARKER_IMPORT_RE, "");
249224
+ }
249225
+ } catch {
249226
+ }
249227
+ mod = override === void 0 ? await twImportTs2(abs, bust) : await twImportTs2(abs, bust, { source: override });
248940
249228
  } else {
248941
249229
  mod = await import(spec);
248942
249230
  }
248943
- const names = importBindingNames(imp.source);
248944
- for (const n of names) out[n] = mod?.[n] ?? mod?.default;
249231
+ for (const bind of importBindings(imp.source)) {
249232
+ if (bind.kind === "namespace") out[bind.local] = mod;
249233
+ else if (bind.kind === "default") out[bind.local] = mod?.default ?? mod?.[bind.imported];
249234
+ else out[bind.local] = mod?.[bind.imported] ?? mod?.default;
249235
+ }
249236
+ }
249237
+ return out;
249238
+ }
249239
+ function serverImportCollisions(source) {
249240
+ const out = [];
249241
+ const re = /^[ \t]*import\s+([\s\S]*?)\s+from\s+["']([^"']+)["'][ \t]*;?/gm;
249242
+ let m;
249243
+ while (m = re.exec(source)) {
249244
+ const stmt = m[0];
249245
+ const specifier = m[2];
249246
+ const line = source.slice(0, m.index).split("\n").length;
249247
+ for (const b of importBindings(stmt)) {
249248
+ if (RESERVED_BLOCK_BINDINGS.includes(b.local)) {
249249
+ out.push({ name: b.local, specifier, line, col: 1 });
249250
+ }
249251
+ }
248945
249252
  }
248946
249253
  return out;
248947
249254
  }
@@ -248980,7 +249287,7 @@ function checkServerBlocks(program, opts = {}) {
248980
249287
  }
248981
249288
  const calls = scanRuntimeCalls(b.source);
248982
249289
  if (calls.getSession || calls.requireUser) push("TW107", "getSession()/requireUser() are not available in a static page's server block", b.line, b.col);
248983
- if (calls.redirect || calls.notFound) push("TW108", "redirect()/notFound() are not available in a static page's server block", b.line, b.col);
249290
+ if (calls.redirect) push("TW108", "redirect() is not available in a static page's server block -- a static page is built before the request, so there is nothing to redirect", b.line, b.col);
248984
249291
  }
248985
249292
  }
248986
249293
  for (const b of blocks) {
@@ -249131,7 +249438,7 @@ function parsePageCache(source) {
249131
249438
  const rv = revalidate ?? 60;
249132
249439
  return { revalidate: rv, expire: expire ?? rv, tag: tagM ? tagM[1] : void 0 };
249133
249440
  }
249134
- var ts3, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS;
249441
+ var ts3, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS, MARKER_IMPORT_RE, RESERVED_BLOCK_BINDINGS;
249135
249442
  var init_server_blocks = __esm({
249136
249443
  "../../packages/compiler/tw/server-blocks/index.ts"() {
249137
249444
  init_codes();
@@ -249158,6 +249465,19 @@ var init_server_blocks = __esm({
249158
249465
  isServerRedirect = (e) => !!(e && e[SERVER_REDIRECT_BRAND]);
249159
249466
  isServerNotFound = (e) => !!(e && e[SERVER_NOT_FOUND_BRAND]);
249160
249467
  DEFAULT_SERVER_BLOCK_TIMEOUT_MS = 1e4;
249468
+ MARKER_IMPORT_RE = /^[ \t]*import\s*["']@tw\/(?:server-only|client-safe)["'][ \t]*;?[ \t]*\r?\n?/gm;
249469
+ RESERVED_BLOCK_BINDINGS = [
249470
+ "params",
249471
+ "query",
249472
+ "headers",
249473
+ "cookies",
249474
+ "env",
249475
+ "fetch",
249476
+ "getSession",
249477
+ "requireUser",
249478
+ "redirect",
249479
+ "notFound"
249480
+ ];
249161
249481
  }
249162
249482
  });
249163
249483
 
@@ -250613,8 +250933,8 @@ var init_memory = __esm({
250613
250933
  });
250614
250934
 
250615
250935
  // ../../packages/compiler/tw/cache/disk.ts
250616
- import { existsSync as existsSync9, readFileSync as readFileSync6, writeFileSync as writeFileSync4, mkdirSync as mkdirSync3, unlinkSync, readdirSync as readdirSync2 } from "node:fs";
250617
- import { join as join13, dirname as dirname7 } from "node:path";
250936
+ import { existsSync as existsSync10, readFileSync as readFileSync7, writeFileSync as writeFileSync5, mkdirSync as mkdirSync3, unlinkSync, readdirSync as readdirSync2 } from "node:fs";
250937
+ import { join as join13, dirname as dirname8 } from "node:path";
250618
250938
  var DiskCache;
250619
250939
  var init_disk = __esm({
250620
250940
  "../../packages/compiler/tw/cache/disk.ts"() {
@@ -250622,15 +250942,15 @@ var init_disk = __esm({
250622
250942
  DiskCache = class {
250623
250943
  constructor(cacheDir) {
250624
250944
  this.cacheDir = cacheDir;
250625
- if (!existsSync9(cacheDir)) {
250945
+ if (!existsSync10(cacheDir)) {
250626
250946
  mkdirSync3(cacheDir, { recursive: true });
250627
250947
  }
250628
250948
  }
250629
250949
  get(key2) {
250630
250950
  const path = this.keyToPath(key2);
250631
- if (!existsSync9(path)) return null;
250951
+ if (!existsSync10(path)) return null;
250632
250952
  try {
250633
- const data = JSON.parse(readFileSync6(path, "utf-8"));
250953
+ const data = JSON.parse(readFileSync7(path, "utf-8"));
250634
250954
  return data.value;
250635
250955
  } catch {
250636
250956
  return null;
@@ -250638,12 +250958,12 @@ var init_disk = __esm({
250638
250958
  }
250639
250959
  set(key2, value, hash2) {
250640
250960
  const path = this.keyToPath(key2);
250641
- mkdirSync3(dirname7(path), { recursive: true });
250961
+ mkdirSync3(dirname8(path), { recursive: true });
250642
250962
  const entry = { key: key2, value, hash: hash2, createdAt: Date.now() };
250643
- writeFileSync4(path, JSON.stringify(entry));
250963
+ writeFileSync5(path, JSON.stringify(entry));
250644
250964
  }
250645
250965
  has(key2) {
250646
- return existsSync9(this.keyToPath(key2));
250966
+ return existsSync10(this.keyToPath(key2));
250647
250967
  }
250648
250968
  delete(key2) {
250649
250969
  const path = this.keyToPath(key2);
@@ -251139,7 +251459,7 @@ var init_incremental = __esm({
251139
251459
 
251140
251460
  // ../../packages/compiler/tw/native/child-process.ts
251141
251461
  import { spawn } from "node:child_process";
251142
- import { existsSync as existsSync10 } from "node:fs";
251462
+ import { existsSync as existsSync11 } from "node:fs";
251143
251463
  import { join as join14 } from "node:path";
251144
251464
  function safeJsonParse3(json2, fallback) {
251145
251465
  try {
@@ -251167,7 +251487,7 @@ function findRustBinary() {
251167
251487
  }
251168
251488
  for (const candidate of candidates) {
251169
251489
  if (candidate.includes("/") || candidate.includes("\\")) {
251170
- if (existsSync10(candidate)) {
251490
+ if (existsSync11(candidate)) {
251171
251491
  cachedBinaryPath = candidate;
251172
251492
  return candidate;
251173
251493
  }
@@ -255785,6 +256105,7 @@ __export(tw_exports2, {
255785
256105
  PropParser: () => PropParser,
255786
256106
  RENDER_MODE_ALIASES: () => RENDER_MODE_ALIASES,
255787
256107
  RENDER_MODE_NAMES: () => RENDER_MODE_NAMES,
256108
+ RESERVED_BLOCK_BINDINGS: () => RESERVED_BLOCK_BINDINGS,
255788
256109
  RESERVED_WORDS: () => RESERVED_WORDS,
255789
256110
  RuleEngine: () => RuleEngine,
255790
256111
  RulesEngine: () => RulesEngine,
@@ -256428,6 +256749,7 @@ __export(tw_exports2, {
256428
256749
  secretEnvValues: () => secretEnvValues,
256429
256750
  separateByType: () => separateByType,
256430
256751
  serializeCache: () => serializeCache,
256752
+ serverImportCollisions: () => serverImportCollisions,
256431
256753
  serverRouteParamCollisions: () => serverRouteParamCollisions,
256432
256754
  serverStateCollisions: () => serverStateCollisions,
256433
256755
  setBackend: () => setBackend,
@@ -274034,8 +274356,8 @@ var init_bot_detection = __esm({
274034
274356
 
274035
274357
  // ../../packages/security/tw/content-security/protector.ts
274036
274358
  function sanitizeFilename(filename) {
274037
- const basename3 = filename.replace(/^.*[\\/]/, "");
274038
- let clean = basename3.replace(/\x00/g, "");
274359
+ const basename4 = filename.replace(/^.*[\\/]/, "");
274360
+ let clean = basename4.replace(/\x00/g, "");
274039
274361
  clean = clean.replace(/[<>:"|?*]/g, "_");
274040
274362
  clean = clean.replace(/^\.+/, "");
274041
274363
  if (clean.length > 255) {
@@ -280913,7 +281235,7 @@ __export(twm_loader_exports, {
280913
281235
  stripCommentsSafe: () => stripCommentsSafe,
280914
281236
  validateTWMSyntax: () => validateTWMSyntax
280915
281237
  });
280916
- import { readFileSync as readFileSync7, existsSync as existsSync11 } from "node:fs";
281238
+ import { readFileSync as readFileSync8, existsSync as existsSync12 } from "node:fs";
280917
281239
  import { join as join15 } from "node:path";
280918
281240
  function clearTWMCache() {
280919
281241
  moduleCache.clear();
@@ -280921,7 +281243,7 @@ function clearTWMCache() {
280921
281243
  function validateTWMSyntax(filePath) {
280922
281244
  let source;
280923
281245
  try {
280924
- source = readFileSync7(filePath, "utf-8");
281246
+ source = readFileSync8(filePath, "utf-8");
280925
281247
  } catch (err2) {
280926
281248
  return "cannot read: " + (err2?.message ?? err2);
280927
281249
  }
@@ -281021,7 +281343,7 @@ async function loadLibModule(rootDir, name) {
281021
281343
  const cacheKey = rootDir + "/" + rel;
281022
281344
  if (libCache.has(cacheKey)) return libCache.get(cacheKey);
281023
281345
  const libPath = join15(rootDir, "lib", rel + ".ts");
281024
- if (!existsSync11(libPath)) {
281346
+ if (!existsSync12(libPath)) {
281025
281347
  throw new Error("Module '" + name + "' not found. Create lib/" + name + ".ts");
281026
281348
  }
281027
281349
  try {
@@ -281063,10 +281385,10 @@ async function loadTWMModule(filePath, rootDir) {
281063
281385
  const cacheKey = filePath;
281064
281386
  const cached2 = moduleCache.get(cacheKey);
281065
281387
  if (cached2) return cached2;
281066
- if (!existsSync11(filePath)) {
281388
+ if (!existsSync12(filePath)) {
281067
281389
  throw new Error("TWM module not found: " + filePath);
281068
281390
  }
281069
- const source = readFileSync7(filePath, "utf-8");
281391
+ const source = readFileSync8(filePath, "utf-8");
281070
281392
  const rd = rootDir || process.cwd();
281071
281393
  if (isRuleDsl(source)) {
281072
281394
  try {
@@ -281629,10 +281951,10 @@ var init_twm_loader = __esm({
281629
281951
  });
281630
281952
 
281631
281953
  // ../../packages/server/tw/routing/scanner.ts
281632
- import { existsSync as existsSync12, readdirSync as readdirSync3, statSync as statSync3 } from "node:fs";
281633
- import { join as join16, relative, basename as basename2, extname as extname6 } from "node:path";
281954
+ import { existsSync as existsSync13, readdirSync as readdirSync3, statSync as statSync3 } from "node:fs";
281955
+ import { join as join16, relative, basename as basename3, extname as extname7 } from "node:path";
281634
281956
  function scanRouteTree(opts) {
281635
- if (!existsSync12(opts.homeDir)) return null;
281957
+ if (!existsSync13(opts.homeDir)) return null;
281636
281958
  const root = {
281637
281959
  segment: "",
281638
281960
  relativePath: "",
@@ -281657,7 +281979,7 @@ function scanDirectory(dirPath, urlPath, groups, parentNode, opts) {
281657
281979
  }
281658
281980
  for (const entry of entries) {
281659
281981
  const fullPath = join16(dirPath, entry);
281660
- const ext = extname6(entry);
281982
+ const ext = extname7(entry);
281661
281983
  if (!ROUTE_EXTENSIONS.has(ext)) continue;
281662
281984
  let stat;
281663
281985
  try {
@@ -281666,7 +281988,7 @@ function scanDirectory(dirPath, urlPath, groups, parentNode, opts) {
281666
281988
  continue;
281667
281989
  }
281668
281990
  if (!stat.isFile()) continue;
281669
- const baseName = basename2(entry, ext);
281991
+ const baseName = basename3(entry, ext);
281670
281992
  const fileType = getRouteFileType(baseName);
281671
281993
  if (fileType === null) {
281672
281994
  continue;
@@ -282040,8 +282362,8 @@ var init_helpers = __esm({
282040
282362
  });
282041
282363
 
282042
282364
  // ../../packages/server/tw/routing/render-pipeline.ts
282043
- import { readFileSync as readFileSync8, existsSync as existsSync13 } from "node:fs";
282044
- import { dirname as dirname8 } from "node:path";
282365
+ import { readFileSync as readFileSync9, existsSync as existsSync14 } from "node:fs";
282366
+ import { dirname as dirname9 } from "node:path";
282045
282367
  function getCacheProfiles(rootDir) {
282046
282368
  if (__profilesCache && __profilesCache.rootDir === rootDir) return __profilesCache.profiles;
282047
282369
  let profiles = {};
@@ -282070,6 +282392,32 @@ var init_render_pipeline = __esm({
282070
282392
  init_tw10();
282071
282393
  __profilesCache = null;
282072
282394
  RenderPipeline = class {
282395
+ /**
282396
+ * A dynamic route with a sibling `params.twm` is an enumerated route: the
282397
+ * static build only writes the generated slugs, so a static host 404s an
282398
+ * unknown one. The server matched `[slug]` for anything and rendered the
282399
+ * page's fallback branch with status 200, so search engines indexed those as
282400
+ * real pages. Return true when the requested params are not in `generate()`.
282401
+ */
282402
+ async isUnenumeratedParam(pageFile, params) {
282403
+ if (!/\[[^\]]+\]/.test(pageFile)) return false;
282404
+ const paramsTwm = dirname9(pageFile) + "/params.twm";
282405
+ if (!existsSync14(paramsTwm)) return false;
282406
+ try {
282407
+ const { loadTWMModule: loadTWMModule2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
282408
+ const pmod = await loadTWMModule2(paramsTwm, this.rootDir);
282409
+ if (typeof pmod?.generate !== "function") return false;
282410
+ const arr2 = await pmod.generate();
282411
+ if (!Array.isArray(arr2) || arr2.length === 0) return false;
282412
+ const keys = Object.keys(params);
282413
+ if (keys.length === 0) return false;
282414
+ const sets = arr2.map((x) => x && typeof x === "object" ? x : { [keys[0]]: String(x) });
282415
+ const found = sets.some((set) => keys.every((k) => String(set[k] ?? "") === String(params[k] ?? "")));
282416
+ return !found;
282417
+ } catch {
282418
+ return false;
282419
+ }
282420
+ }
282073
282421
  rootDir;
282074
282422
  homeDir;
282075
282423
  enableCache;
@@ -282145,10 +282493,10 @@ var init_render_pipeline = __esm({
282145
282493
  /** Read a route file, memoised outside dev. See `sourceCache`. */
282146
282494
  readSource(file) {
282147
282495
  const key2 = file.absolutePath;
282148
- if (this.dev) return readFileSync8(key2, "utf-8");
282496
+ if (this.dev) return readFileSync9(key2, "utf-8");
282149
282497
  const hit = this.sourceCache.get(key2);
282150
282498
  if (hit !== void 0) return hit;
282151
- const src = readFileSync8(key2, "utf-8");
282499
+ const src = readFileSync9(key2, "utf-8");
282152
282500
  this.sourceCache.set(key2, src);
282153
282501
  return src;
282154
282502
  }
@@ -282173,6 +282521,17 @@ var init_render_pipeline = __esm({
282173
282521
  const ctx = match ? resolveLayoutChain(match) : null;
282174
282522
  const pageFile = ctx?.page?.absolutePath;
282175
282523
  if (!pageFile) return this.render(pathname);
282524
+ try {
282525
+ if (await this.isUnenumeratedParam(pageFile, match?.params ?? {})) {
282526
+ this.__forceNotFound = true;
282527
+ try {
282528
+ return this.render(pathname);
282529
+ } finally {
282530
+ this.__forceNotFound = false;
282531
+ }
282532
+ }
282533
+ } catch {
282534
+ }
282176
282535
  let blocks = [];
282177
282536
  let src = "";
282178
282537
  try {
@@ -282448,7 +282807,7 @@ var init_render_pipeline = __esm({
282448
282807
  if (!tree) {
282449
282808
  return this.renderError("home/ directory not found", 500, startTime);
282450
282809
  }
282451
- const match = matchRoute2(tree, pathname);
282810
+ const match = this.__forceNotFound ? null : matchRoute2(tree, pathname);
282452
282811
  if (!match) {
282453
282812
  const rootNotFound = findNearestNotFound(tree, pathname.split("/").filter(Boolean));
282454
282813
  if (rootNotFound) {
@@ -282597,9 +282956,9 @@ ${bodyHTML}`;
282597
282956
  try {
282598
282957
  const headCandidates = [];
282599
282958
  const globalHead = join17(this.rootDir, "home", "head.tw");
282600
- if (existsSync13(globalHead)) headCandidates.push(globalHead);
282601
- const siblingHead = join17(dirname8(ctx.page.absolutePath), "head.tw");
282602
- if (siblingHead !== globalHead && existsSync13(siblingHead)) headCandidates.push(siblingHead);
282959
+ if (existsSync14(globalHead)) headCandidates.push(globalHead);
282960
+ const siblingHead = join17(dirname9(ctx.page.absolutePath), "head.tw");
282961
+ if (siblingHead !== globalHead && existsSync14(siblingHead)) headCandidates.push(siblingHead);
282603
282962
  for (const hp of headCandidates) {
282604
282963
  const headCompiled = this.compileFile({ absolutePath: hp, type: "head" });
282605
282964
  const m = headCompiled.html.match(/<body>([\s\S]*)<\/body>/);
@@ -282733,7 +283092,7 @@ ${bodyHTML}`;
282733
283092
  }
282734
283093
  };
282735
283094
  }
282736
- if (!existsSync13(file.absolutePath)) {
283095
+ if (!existsSync14(file.absolutePath)) {
282737
283096
  throw new Error(`Route file not found: ${file.absolutePath}`);
282738
283097
  }
282739
283098
  const source = this.readSource(file);
@@ -283127,7 +283486,7 @@ ${devScript}
283127
283486
  */
283128
283487
  async runMiddleware(pathname, request) {
283129
283488
  const middlewarePath = join17(this.rootDir, "middleware.twm");
283130
- if (!existsSync13(middlewarePath)) return;
283489
+ if (!existsSync14(middlewarePath)) return;
283131
283490
  const mod = await loadTWMModule(middlewarePath, this.rootDir);
283132
283491
  if (mod.config?.matcher && !shouldMatchMiddleware(mod.config.matcher, pathname)) {
283133
283492
  return;
@@ -283279,7 +283638,7 @@ var init_fs_compat = __esm({
283279
283638
  });
283280
283639
 
283281
283640
  // ../../packages/server/tw/router/index.ts
283282
- import { existsSync as existsSync14, readdirSync as readdirSync4, statSync as statSync4 } from "node:fs";
283641
+ import { existsSync as existsSync15, readdirSync as readdirSync4, statSync as statSync4 } from "node:fs";
283283
283642
  import { join as join18 } from "node:path";
283284
283643
  var RouteRegistry;
283285
283644
  var init_router2 = __esm({
@@ -283348,7 +283707,7 @@ var init_router2 = __esm({
283348
283707
  return [...this.routes];
283349
283708
  }
283350
283709
  loadFromDir(pagesDir, basePath = "/") {
283351
- if (!existsSync14(pagesDir)) return;
283710
+ if (!existsSync15(pagesDir)) return;
283352
283711
  const files = [];
283353
283712
  this.collectFiles(pagesDir, ".tw", files, "");
283354
283713
  for (const file of files) {
@@ -285103,8 +285462,8 @@ var init_signal_transports = __esm({
285103
285462
  });
285104
285463
 
285105
285464
  // ../../packages/server/tw/static/index.ts
285106
- import { existsSync as existsSync15, statSync as statSync5 } from "node:fs";
285107
- import { join as join19, extname as extname7, normalize as normalize2, resolve as resolve3, sep } from "node:path";
285465
+ import { existsSync as existsSync16, statSync as statSync5 } from "node:fs";
285466
+ import { join as join19, extname as extname8, normalize as normalize2, resolve as resolve3, sep } from "node:path";
285108
285467
  var StaticHandler;
285109
285468
  var init_static = __esm({
285110
285469
  "../../packages/server/tw/static/index.ts"() {
@@ -285144,32 +285503,32 @@ var init_static = __esm({
285144
285503
  return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
285145
285504
  }
285146
285505
  let filePath = join19(this.root, safePath);
285147
- if (existsSync15(filePath) && statSync5(filePath).isDirectory()) {
285506
+ if (existsSync16(filePath) && statSync5(filePath).isDirectory()) {
285148
285507
  filePath = join19(filePath, this.indexFile);
285149
285508
  }
285150
- if (!existsSync15(filePath)) {
285509
+ if (!existsSync16(filePath)) {
285151
285510
  filePath = join19(this.root, safePath + ".html");
285152
285511
  }
285153
285512
  let notFoundFallback = false;
285154
- if (!existsSync15(filePath)) {
285513
+ if (!existsSync16(filePath)) {
285155
285514
  filePath = join19(this.root, safePath, this.indexFile);
285156
285515
  }
285157
- if (!existsSync15(filePath)) {
285516
+ if (!existsSync16(filePath)) {
285158
285517
  if (this.spa) {
285159
285518
  filePath = join19(this.root, this.indexFile);
285160
- if (!existsSync15(filePath)) {
285519
+ if (!existsSync16(filePath)) {
285161
285520
  return new Response("Not Found", { status: 404 });
285162
285521
  }
285163
285522
  } else {
285164
285523
  filePath = join19(this.root, "404.html");
285165
285524
  notFoundFallback = true;
285166
- if (!existsSync15(filePath)) {
285525
+ if (!existsSync16(filePath)) {
285167
285526
  return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
285168
285527
  }
285169
285528
  }
285170
285529
  }
285171
285530
  const stat = statSync5(filePath);
285172
- const ext = extname7(filePath).toLowerCase();
285531
+ const ext = extname8(filePath).toLowerCase();
285173
285532
  const contentType = MIME_TYPES[ext] ?? "application/octet-stream";
285174
285533
  const bytes = await readBytes(filePath);
285175
285534
  let etagValue = "";
@@ -285288,7 +285647,7 @@ var init_static = __esm({
285288
285647
  });
285289
285648
 
285290
285649
  // ../../packages/server/tw/ssr/index.ts
285291
- import { readFileSync as readFileSync9, writeFileSync as writeFileSync5, existsSync as existsSync16, mkdirSync as mkdirSync4 } from "node:fs";
285650
+ import { readFileSync as readFileSync10, writeFileSync as writeFileSync6, existsSync as existsSync17, mkdirSync as mkdirSync4 } from "node:fs";
285292
285651
  import { createHash as createHash5 } from "node:crypto";
285293
285652
  import { join as join20 } from "node:path";
285294
285653
  import { existsSync as existsSyncSync } from "node:fs";
@@ -285302,7 +285661,7 @@ function getCachedSSR(pathname) {
285302
285661
  }
285303
285662
  const diskPath = join20(_diskCacheDir, pathname.replace(/[\/]/g, "_") + ".html");
285304
285663
  if (existsSyncSync(diskPath)) {
285305
- const content = readFileSync9(diskPath, "utf-8");
285664
+ const content = readFileSync10(diskPath, "utf-8");
285306
285665
  const etag = createHash5("sha256").update(content).digest("hex").slice(0, 16);
285307
285666
  _ssrCache.set(pathname, { html: content, etag, expires: Date.now() + 6e4 });
285308
285667
  return { html: content, etag };
@@ -285315,7 +285674,7 @@ function setCachedSSR(pathname, html) {
285315
285674
  try {
285316
285675
  if (!existsSyncSync(_diskCacheDir)) mkdirSync4(_diskCacheDir, { recursive: true });
285317
285676
  const diskPath = join20(_diskCacheDir, pathname.replace(/[\/]/g, "_") + ".html");
285318
- writeFileSync5(diskPath, html);
285677
+ writeFileSync6(diskPath, html);
285319
285678
  } catch {
285320
285679
  }
285321
285680
  return etag;
@@ -285418,9 +285777,9 @@ var init_ssr = __esm({
285418
285777
  }
285419
285778
  }
285420
285779
  const filePath = this.resolveRoute(pathname);
285421
- if (!filePath || !existsSync16(filePath)) return null;
285780
+ if (!filePath || !existsSync17(filePath)) return null;
285422
285781
  try {
285423
- const source = readFileSync9(filePath, "utf-8");
285782
+ const source = readFileSync10(filePath, "utf-8");
285424
285783
  return {
285425
285784
  html: `<html><body>SSR sync not available</body></html>`,
285426
285785
  css: "",
@@ -285455,35 +285814,35 @@ var init_ssr = __esm({
285455
285814
  let currentDir = this.pagesDir;
285456
285815
  if (segments.length === 0) {
285457
285816
  const pagePath = join20(this.pagesDir, "page.tw");
285458
- if (existsSync16(pagePath)) return pagePath;
285817
+ if (existsSync17(pagePath)) return pagePath;
285459
285818
  const indexPath = join20(this.pagesDir, "index.tw");
285460
- if (existsSync16(indexPath)) return indexPath;
285819
+ if (existsSync17(indexPath)) return indexPath;
285461
285820
  return null;
285462
285821
  }
285463
285822
  for (let i = 0; i < segments.length; i++) {
285464
285823
  const seg = segments[i];
285465
285824
  const isLast = i === segments.length - 1;
285466
- const entries = existsSync16(currentDir) ? __require("node:fs").readdirSync(currentDir) : [];
285825
+ const entries = existsSync17(currentDir) ? __require("node:fs").readdirSync(currentDir) : [];
285467
285826
  if (isLast) {
285468
285827
  const exactPath = join20(currentDir, seg + ".tw");
285469
- if (existsSync16(exactPath)) return exactPath;
285828
+ if (existsSync17(exactPath)) return exactPath;
285470
285829
  const dirPage = join20(currentDir, seg, "page.tw");
285471
- if (existsSync16(dirPage)) return dirPage;
285830
+ if (existsSync17(dirPage)) return dirPage;
285472
285831
  const paramFile = entries.find((e) => e.match(/^\[([^\]]+)\]\.tw$/));
285473
285832
  if (paramFile) return join20(currentDir, paramFile);
285474
285833
  const paramDir = entries.find((e) => e.match(/^\[([^\]]+)\]$/));
285475
285834
  if (paramDir) {
285476
285835
  const p = join20(currentDir, paramDir, "page.tw");
285477
- if (existsSync16(p)) return p;
285836
+ if (existsSync17(p)) return p;
285478
285837
  const pIdx = join20(currentDir, paramDir, "index.tw");
285479
- if (existsSync16(pIdx)) return pIdx;
285838
+ if (existsSync17(pIdx)) return pIdx;
285480
285839
  }
285481
285840
  const idx = join20(currentDir, seg, "index.tw");
285482
- if (existsSync16(idx)) return idx;
285841
+ if (existsSync17(idx)) return idx;
285483
285842
  return null;
285484
285843
  }
285485
285844
  const dirPath = join20(currentDir, seg);
285486
- if (existsSync16(dirPath) && __require("node:fs").statSync(dirPath).isDirectory()) {
285845
+ if (existsSync17(dirPath) && __require("node:fs").statSync(dirPath).isDirectory()) {
285487
285846
  currentDir = dirPath;
285488
285847
  } else {
285489
285848
  const paramDir = entries.find((e) => e.match(/^\[([^\]]+)\]$/));
@@ -286872,7 +287231,7 @@ __export(tw_exports5, {
286872
287231
  wwwRedirect: () => wwwRedirect
286873
287232
  });
286874
287233
  import { join as join21 } from "node:path";
286875
- import { existsSync as existsSync17, readFileSync as readFileSync10 } from "node:fs";
287234
+ import { existsSync as existsSync18, readFileSync as readFileSync11 } from "node:fs";
286876
287235
  function normalizePathname(p) {
286877
287236
  return p.replace(/\/{2,}/g, "/");
286878
287237
  }
@@ -287073,6 +287432,19 @@ var init_tw10 = __esm({
287073
287432
  const entries = Object.entries(cfgIn.rewrites);
287074
287433
  cfgIn.rewrites = entries.map(([from, to]) => typeof to === "string" ? { from, to } : { from, ...to });
287075
287434
  }
287435
+ if (Array.isArray(cfgIn.headers)) {
287436
+ const HEADER_ENTRY_KEYS = /* @__PURE__ */ new Set(["source", "headers"]);
287437
+ for (const h3 of cfgIn.headers) {
287438
+ if (!h3 || typeof h3 !== "object") continue;
287439
+ const unknown = Object.keys(h3).filter((k) => !HEADER_ENTRY_KEYS.has(k));
287440
+ if (unknown.length > 0) {
287441
+ console.warn("[tw] headers: unrecognized key" + (unknown.length > 1 ? "s" : "") + " " + unknown.join(", ") + " in entry -- accepted keys are source and headers" + (unknown.includes("path") ? " (did you mean 'source'?)" : ""));
287442
+ }
287443
+ if (h3.source === void 0 && h3.path !== void 0) {
287444
+ console.warn("[tw] headers: entry uses 'path' instead of 'source' -- it will not be applied");
287445
+ }
287446
+ }
287447
+ }
287076
287448
  for (const h3 of cfgIn.headers ?? []) {
287077
287449
  if (h3?.headers && typeof h3.headers === "object") {
287078
287450
  for (const k of Object.keys(h3.headers)) {
@@ -287150,11 +287522,11 @@ var init_tw10 = __esm({
287150
287522
  }
287151
287523
  }
287152
287524
  const staticDir = this.options.staticDir ?? join21(options.rootDir, ".tw");
287153
- if (existsSync17(staticDir)) {
287525
+ if (existsSync18(staticDir)) {
287154
287526
  try {
287155
287527
  const manifestPath = join21(staticDir, "routes.json");
287156
- if (existsSync17(manifestPath)) {
287157
- const manifest = JSON.parse(readFileSync10(manifestPath, "utf-8"));
287528
+ if (existsSync18(manifestPath)) {
287529
+ const manifest = JSON.parse(readFileSync11(manifestPath, "utf-8"));
287158
287530
  for (const [route, secs] of Object.entries(manifest)) {
287159
287531
  this.isrRoutes.set(route, secs);
287160
287532
  }
@@ -287172,7 +287544,7 @@ var init_tw10 = __esm({
287172
287544
  });
287173
287545
  }
287174
287546
  const homeDir = this.options.pagesDir ?? join21(options.rootDir, "home");
287175
- if (existsSync17(homeDir)) {
287547
+ if (existsSync18(homeDir)) {
287176
287548
  this.ssr = new SSRRenderer({ pagesDir: homeDir, enableCache: true, cacheTTL: 6e4 });
287177
287549
  }
287178
287550
  }
@@ -287219,11 +287591,11 @@ var init_tw10 = __esm({
287219
287591
  middlewarePath = null;
287220
287592
  loadMiddleware() {
287221
287593
  const middlewarePath = join21(this.options.rootDir, "middleware.twm");
287222
- if (existsSync17(middlewarePath)) {
287594
+ if (existsSync18(middlewarePath)) {
287223
287595
  this.middlewarePath = middlewarePath;
287224
287596
  console.log(" Middleware: middleware.twm loaded");
287225
287597
  try {
287226
- const src = readFileSync10(middlewarePath, "utf-8");
287598
+ const src = readFileSync11(middlewarePath, "utf-8");
287227
287599
  const rules = parseRules(src, "middleware.twm");
287228
287600
  for (const r of rules) {
287229
287601
  const conds = [];
@@ -287714,7 +288086,7 @@ var init_tw10 = __esm({
287714
288086
  return new Response("Bad Request", { status: 400 });
287715
288087
  }
287716
288088
  const homeDir = join21(this.options.rootDir, "home");
287717
- if (!existsSync17(homeDir)) return new Response("Not Found", { status: 404 });
288089
+ if (!existsSync18(homeDir)) return new Response("Not Found", { status: 404 });
287718
288090
  try {
287719
288091
  const { createRenderPipeline: createRenderPipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
287720
288092
  if (!this.renderPipeline) {
@@ -287863,7 +288235,7 @@ var init_tw10 = __esm({
287863
288235
  try {
287864
288236
  const { createRenderPipeline: createRenderPipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
287865
288237
  const homeDir = join21(this.options.rootDir, "home");
287866
- if (existsSync17(homeDir)) {
288238
+ if (existsSync18(homeDir)) {
287867
288239
  const pipeline = createRenderPipeline2({
287868
288240
  rootDir: this.options.rootDir,
287869
288241
  homeDir,
@@ -287923,7 +288295,7 @@ ${err2.stack ?? ""}`);
287923
288295
  try {
287924
288296
  const { createRenderPipeline: createRenderPipeline2, setActivePipeline: setActivePipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
287925
288297
  const homeDir = join21(this.options.rootDir, "home");
287926
- if (existsSync17(homeDir)) {
288298
+ if (existsSync18(homeDir)) {
287927
288299
  if (!this.renderPipeline) {
287928
288300
  this.renderPipeline = createRenderPipeline2({
287929
288301
  rootDir: this.options.rootDir,