tw-framework 2.0.4 → 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.
@@ -228587,7 +228631,7 @@ function parseElement(cursor, errors, state, parseBody) {
228587
228631
  const tag2 = tagToken.value;
228588
228632
  if (tag2 && /^[A-Za-z][A-Za-z0-9-]*$/.test(tag2)) {
228589
228633
  errors.add(new CompilerError(
228590
- "raw HTML is not supported in .tw -- write it in TW syntax: " + tag2 + " { ... }",
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}',
228591
228635
  tagToken.pos.line,
228592
228636
  tagToken.pos.col,
228593
228637
  "TW123",
@@ -237251,7 +237295,7 @@ var init_types4 = __esm({
237251
237295
  var TW_VERSION, TW_GENERATOR_META;
237252
237296
  var init_version = __esm({
237253
237297
  "../../packages/compiler/tw/codegen/version.ts"() {
237254
- TW_VERSION = "2.0.4";
237298
+ TW_VERSION = "2.0.5";
237255
237299
  TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
237256
237300
  }
237257
237301
  });
@@ -238534,6 +238578,39 @@ function validatePlainCss(src, filePath) {
238534
238578
  checkDecl();
238535
238579
  return src;
238536
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
+ }
238537
238614
  function compileDecl(decl) {
238538
238615
  const trimmed = decl.trim();
238539
238616
  if (!trimmed) return "";
@@ -238541,10 +238618,10 @@ function compileDecl(decl) {
238541
238618
  if (cssForm) return trimmed.replace(/^([-\w]+)\s*:\s*/, "$1: ");
238542
238619
  const spaceIdx = trimmed.search(/[\s]/);
238543
238620
  if (spaceIdx === -1) {
238544
- return TSS_SHORTHANDS2[trimmed] ?? trimmed;
238621
+ return "";
238545
238622
  }
238546
238623
  const prop = trimmed.slice(0, spaceIdx);
238547
- const value = trimmed.slice(spaceIdx).trim();
238624
+ const value = collapseWhitespace(trimmed.slice(spaceIdx).trim());
238548
238625
  const full = TSS_SHORTHANDS2[prop] ?? prop;
238549
238626
  return `${full}: ${value}`;
238550
238627
  }
@@ -238702,26 +238779,47 @@ function __twCompileTSSInner(source) {
238702
238779
  if (!changed) break;
238703
238780
  }
238704
238781
  }
238705
- const rules = [];
238782
+ const root = [];
238706
238783
  const stack = [];
238707
- const declsByLevel = [];
238708
238784
  let buf = "";
238709
- const emit4 = (selector, decls, wrapStack) => {
238710
- if (decls.length === 0) return;
238711
- let rule = `${selector} { ${decls.join("; ")} }`;
238712
- for (let i2 = wrapStack.length - 1; i2 >= 0; i2--) {
238713
- if (wrapStack[i2].startsWith("@")) rule = `${wrapStack[i2]} { ${rule} }`;
238714
- }
238715
- rules.push(rule);
238716
- };
238785
+ const current2 = () => stack.length ? stack[stack.length - 1] : null;
238786
+ const statements = [];
238787
+ const isStatementAtRule = (t3) => /^@(import|charset|namespace|layer)\b/.test(t3);
238717
238788
  const pushDecl = (text) => {
238718
- const d = compileDecl(text);
238719
- 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: [] });
238720
238800
  };
238721
- 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);
238722
238802
  let i = 0;
238803
+ let quote = null;
238723
238804
  while (i < src.length) {
238724
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
+ }
238725
238823
  if (ch === "{") {
238726
238824
  let sel = buf.trim();
238727
238825
  buf = "";
@@ -238734,53 +238832,38 @@ function __twCompileTSSInner(source) {
238734
238832
  const last = lines[lines.length - 1];
238735
238833
  const prior = lines.slice(0, -1);
238736
238834
  const priorComplete = !/[(,]\s*$/.test(prior[prior.length - 1] ?? "");
238737
- if (priorComplete && prior.every(isDeclLine) && !last.startsWith("@")) {
238835
+ if (priorComplete && prior.every(isDeclLine)) {
238738
238836
  for (const p of prior) pushDecl(p);
238739
238837
  sel = last;
238740
238838
  }
238741
238839
  }
238742
- const parent = stack.length ? stack[stack.length - 1] : "";
238743
- let full;
238840
+ const parent = current2();
238744
238841
  if (sel.startsWith("@")) {
238745
- full = sel;
238746
- } else if (parent && !parent.startsWith("@")) {
238747
- full = combineSelector(parent, sel);
238842
+ const node = { kind: "at", head: sel, decls: [], children: [] };
238843
+ (parent ? parent.children : root).push(node);
238844
+ stack.push(node);
238748
238845
  } else {
238749
- 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);
238750
238850
  }
238751
- stack.push(full);
238752
- declsByLevel.push([]);
238753
238851
  i++;
238754
238852
  } else if (ch === "}") {
238755
238853
  if (buf.trim()) {
238756
238854
  const blines = buf.split(/\n+/).map((l) => l.trim()).filter(Boolean);
238757
- if (blines.length > 1 && blines.every(isDeclLine)) {
238855
+ const valueContinues = blines.some((l) => /[(,]\s*$/.test(l));
238856
+ if (blines.length > 1 && !valueContinues) {
238758
238857
  for (const l of blines) pushDecl(l);
238759
238858
  } else {
238760
238859
  pushDecl(buf);
238761
238860
  }
238762
238861
  }
238763
238862
  buf = "";
238764
- const level = stack.pop();
238765
- const decls = declsByLevel.pop() ?? [];
238766
- if (level) {
238767
- if (level.startsWith("@") && decls.length > 0) {
238768
- let realSel = null;
238769
- for (let j = stack.length - 1; j >= 0; j--) {
238770
- if (!stack[j].startsWith("@")) {
238771
- realSel = stack[j];
238772
- break;
238773
- }
238774
- }
238775
- if (realSel) emit4(realSel, decls, [...stack, level]);
238776
- else emit4(level, decls, stack);
238777
- } else {
238778
- emit4(level, decls, stack);
238779
- }
238780
- }
238863
+ stack.pop();
238781
238864
  i++;
238782
238865
  } else if (ch === ";") {
238783
- pushDecl(buf);
238866
+ if (buf.trim()) pushDecl(buf);
238784
238867
  buf = "";
238785
238868
  i++;
238786
238869
  } else {
@@ -238788,11 +238871,24 @@ function __twCompileTSSInner(source) {
238788
238871
  i++;
238789
238872
  }
238790
238873
  }
238791
- if (buf.trim()) {
238792
- const d = compileDecl(buf);
238793
- if (d && stack.length === 0) rules.push(`* { ${d} }`);
238794
- }
238795
- 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");
238796
238892
  }
238797
238893
  var TSS_SHORTHANDS2;
238798
238894
  var init_tss = __esm({
@@ -238836,6 +238932,12 @@ var init_tss = __esm({
238836
238932
  "br-t": "border-top-left-radius",
238837
238933
  bxsh: "box-shadow",
238838
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",
238839
238941
  // `box` is the documented box-sizing shorthand (docs/tss-syntax.md).
238840
238942
  box: "box-sizing",
238841
238943
  // typography
@@ -238877,7 +238979,13 @@ var init_tss = __esm({
238877
238979
  tr: "transition",
238878
238980
  tf: "transform",
238879
238981
  us: "user-select",
238880
- 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"
238881
238989
  };
238882
238990
  }
238883
238991
  });
@@ -240017,7 +240125,9 @@ function generateElement(el, ctx) {
240017
240125
  if (el.children.length === 0 && el.selfClosing) {
240018
240126
  return `<${tag2}${attrPrefix}></${tag2}>`;
240019
240127
  }
240020
- 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("");
240021
240131
  return `<${tag2}${attrPrefix}>${childrenHTML}</${tag2}>`;
240022
240132
  }
240023
240133
  function renderAttrs(el, ctx) {
@@ -240148,10 +240258,30 @@ function wrapInterpolations(rendered, raw) {
240148
240258
  }
240149
240259
  return out;
240150
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
+ }
240151
240275
  function generateText(text, ctx) {
240152
240276
  ctx_global_interactive = ctx.interactive === true;
240153
240277
  ctx_global_inhead = ctx.inHead === true;
240154
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
+ }
240155
240285
  if (text.isInterpolated) {
240156
240286
  if (ctx.interactive && ctx.inHead !== true) {
240157
240287
  return `<span data-tw-i="${escapeHTML(text.value)}"${dataTwSFor(text.value)}>${escapeHTML(interpolate2(`{${text.value}}`, ctx.stateVars))}</span>`;
@@ -241452,7 +241582,7 @@ function minifyHTML2(html, options) {
241452
241582
  result = removeComments(result);
241453
241583
  }
241454
241584
  if (opts.collapseWhitespace) {
241455
- result = collapseWhitespace(result);
241585
+ result = collapseWhitespace2(result);
241456
241586
  }
241457
241587
  if (opts.removeRedundantAttrs) {
241458
241588
  result = removeRedundantAttrs(result);
@@ -241475,7 +241605,7 @@ function removeComments(html) {
241475
241605
  if (html.indexOf("<!--") === -1) return html;
241476
241606
  return html.replace(/<!--(?!\[if\s)[\s\S]*?-->/g, "");
241477
241607
  }
241478
- function collapseWhitespace(html) {
241608
+ function collapseWhitespace2(html) {
241479
241609
  const result = [];
241480
241610
  let pos = 0;
241481
241611
  let inPreserved = false;
@@ -244733,7 +244863,7 @@ var init_codes = __esm({
244733
244863
  TW105: { message: "Server blocks in layouts are not supported yet", severity: "error", category: "semantic" },
244734
244864
  TW106: { message: "Request context (headers/cookies/query/params) is not available in a static server block", severity: "error", category: "semantic" },
244735
244865
  TW107: { message: "getSession()/requireUser() are not available in a static page's server block", severity: "error", category: "semantic" },
244736
- 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" },
244737
244867
  TW109: { message: "redirect() target must be a same-origin internal path", severity: "error", category: "semantic" },
244738
244868
  TW110: { message: "A cached fetch must not set an Authorization, Proxy-Authorization or Cookie header", severity: "error", category: "semantic" },
244739
244869
  TW111: { message: "A cached page's server block cannot read headers, cookies, getSession() or requireUser()", severity: "error", category: "semantic" },
@@ -244748,6 +244878,7 @@ var init_codes = __esm({
244748
244878
  TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
244749
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" },
244750
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" },
244751
244882
  // Codes thrown outside the rule engine. TW303 comes from the stylesheet
244752
244883
  // parser (codegen/tss.ts); TW000 is the generic fallback used when an error
244753
244884
  // carries no code of its own.
@@ -244948,8 +245079,17 @@ function checkPerformance(program, filePath, diags) {
244948
245079
  ]));
244949
245080
  }
244950
245081
  if (isElement(node) && node.tag.toLowerCase() === "img") {
245082
+ const attr = (n) => node.attrs.find((a) => a.name === n)?.value;
244951
245083
  const hasLazy = node.attrs.some((a) => a.name === "loading" && a.value === "lazy");
244952
- 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) {
244953
245093
  diags.push(createDiagnostic("TW054", node.line, node.col, filePath, void 0, [
244954
245094
  'Add loading="lazy" for below-fold images'
244955
245095
  ]));
@@ -245464,6 +245604,55 @@ var init_rules = __esm({
245464
245604
  "foreignobject"
245465
245605
  ]);
245466
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",
245467
245656
  "accept",
245468
245657
  "accept-charset",
245469
245658
  "accesskey",
@@ -248667,20 +248856,36 @@ var node_import_exports = {};
248667
248856
  __export(node_import_exports, {
248668
248857
  twImportTs: () => twImportTs
248669
248858
  });
248670
- import { join as join12 } from "node:path";
248859
+ import { join as join12, dirname as dirname7, basename as basename2, extname as extname6 } from "node:path";
248671
248860
  import { tmpdir as tmpdir2 } from "node:os";
248672
248861
  import { pathToFileURL as pathToFileURL2 } from "node:url";
248673
- async function twImportTs(tsPath, bust) {
248862
+ import { writeFileSync as writeFileSync4, rmSync as rmSync2 } from "node:fs";
248863
+ async function twImportTs(tsPath, bust, opts) {
248674
248864
  const q = bust ? "?v=" + bust : "";
248865
+ const override = opts?.source;
248675
248866
  if (!globalThis.__TW_NODE) {
248676
- 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
+ }
248677
248880
  }
248678
248881
  const esbuildMain = globalThis.__TW_ESBUILD_MODULE;
248679
248882
  const esbuild = await (esbuildMain ? import(esbuildMain) : import("esbuild"));
248680
248883
  const safe = tsPath.replace(/[^a-zA-Z0-9]/g, "_").slice(-120);
248681
248884
  const cachePath = join12(tmpdir2(), "tw-" + safe + (bust ? "-" + bust : "") + ".mjs");
248682
248885
  await esbuild.build({
248683
- 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" } },
248684
248889
  bundle: true,
248685
248890
  format: "esm",
248686
248891
  platform: "node",
@@ -248690,12 +248895,15 @@ async function twImportTs(tsPath, bust) {
248690
248895
  });
248691
248896
  return import(pathToFileURL2(cachePath).href + q);
248692
248897
  }
248898
+ var overrideSeq;
248693
248899
  var init_node_import = __esm({
248694
248900
  "../../packages/shared/tw/node-import.ts"() {
248901
+ overrideSeq = 0;
248695
248902
  }
248696
248903
  });
248697
248904
 
248698
248905
  // ../../packages/compiler/tw/server-blocks/index.ts
248906
+ import { readFileSync as readFileSync6, existsSync as existsSync9 } from "node:fs";
248699
248907
  function encodeServerValue(v) {
248700
248908
  if (v === void 0) return "";
248701
248909
  if (v === null) return "null";
@@ -248952,41 +249160,45 @@ function withTimeout2(p, ms, label) {
248952
249160
  });
248953
249161
  });
248954
249162
  }
248955
- function importBindingNames(stmt) {
248956
- const names = [];
248957
- 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();
248958
249166
  const fromIdx = s.lastIndexOf(" from ");
248959
- if (fromIdx < 0) return names;
249167
+ if (fromIdx < 0) return out;
248960
249168
  const clause = s.slice(0, fromIdx).trim();
248961
- if (clause.startsWith("{")) {
248962
- 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(",")) {
248963
249178
  const t3 = part.trim();
248964
249179
  if (!t3) continue;
248965
- const as = t3.split(/\s+as\s+/);
248966
- 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" });
248967
249184
  }
248968
- } else if (clause.startsWith("*")) {
248969
- const as = clause.split(/\s+as\s+/);
248970
- if (as[1]) names.push(as[1].trim());
248971
- } else {
248972
- const first = clause.split(",")[0].trim();
248973
- if (first && /^[A-Za-z_$]/.test(first)) names.push(first);
248974
249185
  }
248975
- return names;
249186
+ return out;
248976
249187
  }
248977
249188
  async function resolveServerImports(block, pageFile, opts = {}) {
248978
249189
  if (!block.imports.length) return {};
248979
249190
  const out = {};
248980
249191
  const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
248981
- const { dirname: dirname9, resolve: resolve4 } = await import("node:path");
249192
+ const { dirname: dirname10, resolve: resolve4 } = await import("node:path");
248982
249193
  const { statSync: statSync6 } = await import("node:fs");
248983
249194
  for (const imp of block.imports) {
248984
249195
  if (!imp.specifier) continue;
248985
249196
  const spec = imp.specifier;
249197
+ if (spec === "@tw/server-only" || spec === "@tw/client-safe") continue;
248986
249198
  let mod;
248987
249199
  if (spec.startsWith("./") || spec.startsWith("../") || spec.startsWith("@./")) {
248988
249200
  const rel = spec.startsWith("@./") ? spec.slice(2) : spec;
248989
- const abs = resolve4(dirname9(pageFile), rel);
249201
+ const abs = resolve4(dirname10(pageFile), rel);
248990
249202
  let bust;
248991
249203
  if (opts.dev) {
248992
249204
  try {
@@ -248994,12 +249206,49 @@ async function resolveServerImports(block, pageFile, opts = {}) {
248994
249206
  } catch {
248995
249207
  }
248996
249208
  }
248997
- 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 });
248998
249228
  } else {
248999
249229
  mod = await import(spec);
249000
249230
  }
249001
- const names = importBindingNames(imp.source);
249002
- 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
+ }
249003
249252
  }
249004
249253
  return out;
249005
249254
  }
@@ -249038,7 +249287,7 @@ function checkServerBlocks(program, opts = {}) {
249038
249287
  }
249039
249288
  const calls = scanRuntimeCalls(b.source);
249040
249289
  if (calls.getSession || calls.requireUser) push("TW107", "getSession()/requireUser() are not available in a static page's server block", b.line, b.col);
249041
- 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);
249042
249291
  }
249043
249292
  }
249044
249293
  for (const b of blocks) {
@@ -249189,7 +249438,7 @@ function parsePageCache(source) {
249189
249438
  const rv = revalidate ?? 60;
249190
249439
  return { revalidate: rv, expire: expire ?? rv, tag: tagM ? tagM[1] : void 0 };
249191
249440
  }
249192
- 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;
249193
249442
  var init_server_blocks = __esm({
249194
249443
  "../../packages/compiler/tw/server-blocks/index.ts"() {
249195
249444
  init_codes();
@@ -249216,6 +249465,19 @@ var init_server_blocks = __esm({
249216
249465
  isServerRedirect = (e) => !!(e && e[SERVER_REDIRECT_BRAND]);
249217
249466
  isServerNotFound = (e) => !!(e && e[SERVER_NOT_FOUND_BRAND]);
249218
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
+ ];
249219
249481
  }
249220
249482
  });
249221
249483
 
@@ -250671,8 +250933,8 @@ var init_memory = __esm({
250671
250933
  });
250672
250934
 
250673
250935
  // ../../packages/compiler/tw/cache/disk.ts
250674
- import { existsSync as existsSync9, readFileSync as readFileSync6, writeFileSync as writeFileSync4, mkdirSync as mkdirSync3, unlinkSync, readdirSync as readdirSync2 } from "node:fs";
250675
- 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";
250676
250938
  var DiskCache;
250677
250939
  var init_disk = __esm({
250678
250940
  "../../packages/compiler/tw/cache/disk.ts"() {
@@ -250680,15 +250942,15 @@ var init_disk = __esm({
250680
250942
  DiskCache = class {
250681
250943
  constructor(cacheDir) {
250682
250944
  this.cacheDir = cacheDir;
250683
- if (!existsSync9(cacheDir)) {
250945
+ if (!existsSync10(cacheDir)) {
250684
250946
  mkdirSync3(cacheDir, { recursive: true });
250685
250947
  }
250686
250948
  }
250687
250949
  get(key2) {
250688
250950
  const path = this.keyToPath(key2);
250689
- if (!existsSync9(path)) return null;
250951
+ if (!existsSync10(path)) return null;
250690
250952
  try {
250691
- const data = JSON.parse(readFileSync6(path, "utf-8"));
250953
+ const data = JSON.parse(readFileSync7(path, "utf-8"));
250692
250954
  return data.value;
250693
250955
  } catch {
250694
250956
  return null;
@@ -250696,12 +250958,12 @@ var init_disk = __esm({
250696
250958
  }
250697
250959
  set(key2, value, hash2) {
250698
250960
  const path = this.keyToPath(key2);
250699
- mkdirSync3(dirname7(path), { recursive: true });
250961
+ mkdirSync3(dirname8(path), { recursive: true });
250700
250962
  const entry = { key: key2, value, hash: hash2, createdAt: Date.now() };
250701
- writeFileSync4(path, JSON.stringify(entry));
250963
+ writeFileSync5(path, JSON.stringify(entry));
250702
250964
  }
250703
250965
  has(key2) {
250704
- return existsSync9(this.keyToPath(key2));
250966
+ return existsSync10(this.keyToPath(key2));
250705
250967
  }
250706
250968
  delete(key2) {
250707
250969
  const path = this.keyToPath(key2);
@@ -251197,7 +251459,7 @@ var init_incremental = __esm({
251197
251459
 
251198
251460
  // ../../packages/compiler/tw/native/child-process.ts
251199
251461
  import { spawn } from "node:child_process";
251200
- import { existsSync as existsSync10 } from "node:fs";
251462
+ import { existsSync as existsSync11 } from "node:fs";
251201
251463
  import { join as join14 } from "node:path";
251202
251464
  function safeJsonParse3(json2, fallback) {
251203
251465
  try {
@@ -251225,7 +251487,7 @@ function findRustBinary() {
251225
251487
  }
251226
251488
  for (const candidate of candidates) {
251227
251489
  if (candidate.includes("/") || candidate.includes("\\")) {
251228
- if (existsSync10(candidate)) {
251490
+ if (existsSync11(candidate)) {
251229
251491
  cachedBinaryPath = candidate;
251230
251492
  return candidate;
251231
251493
  }
@@ -255843,6 +256105,7 @@ __export(tw_exports2, {
255843
256105
  PropParser: () => PropParser,
255844
256106
  RENDER_MODE_ALIASES: () => RENDER_MODE_ALIASES,
255845
256107
  RENDER_MODE_NAMES: () => RENDER_MODE_NAMES,
256108
+ RESERVED_BLOCK_BINDINGS: () => RESERVED_BLOCK_BINDINGS,
255846
256109
  RESERVED_WORDS: () => RESERVED_WORDS,
255847
256110
  RuleEngine: () => RuleEngine,
255848
256111
  RulesEngine: () => RulesEngine,
@@ -256486,6 +256749,7 @@ __export(tw_exports2, {
256486
256749
  secretEnvValues: () => secretEnvValues,
256487
256750
  separateByType: () => separateByType,
256488
256751
  serializeCache: () => serializeCache,
256752
+ serverImportCollisions: () => serverImportCollisions,
256489
256753
  serverRouteParamCollisions: () => serverRouteParamCollisions,
256490
256754
  serverStateCollisions: () => serverStateCollisions,
256491
256755
  setBackend: () => setBackend,
@@ -274092,8 +274356,8 @@ var init_bot_detection = __esm({
274092
274356
 
274093
274357
  // ../../packages/security/tw/content-security/protector.ts
274094
274358
  function sanitizeFilename(filename) {
274095
- const basename3 = filename.replace(/^.*[\\/]/, "");
274096
- let clean = basename3.replace(/\x00/g, "");
274359
+ const basename4 = filename.replace(/^.*[\\/]/, "");
274360
+ let clean = basename4.replace(/\x00/g, "");
274097
274361
  clean = clean.replace(/[<>:"|?*]/g, "_");
274098
274362
  clean = clean.replace(/^\.+/, "");
274099
274363
  if (clean.length > 255) {
@@ -280971,7 +281235,7 @@ __export(twm_loader_exports, {
280971
281235
  stripCommentsSafe: () => stripCommentsSafe,
280972
281236
  validateTWMSyntax: () => validateTWMSyntax
280973
281237
  });
280974
- import { readFileSync as readFileSync7, existsSync as existsSync11 } from "node:fs";
281238
+ import { readFileSync as readFileSync8, existsSync as existsSync12 } from "node:fs";
280975
281239
  import { join as join15 } from "node:path";
280976
281240
  function clearTWMCache() {
280977
281241
  moduleCache.clear();
@@ -280979,7 +281243,7 @@ function clearTWMCache() {
280979
281243
  function validateTWMSyntax(filePath) {
280980
281244
  let source;
280981
281245
  try {
280982
- source = readFileSync7(filePath, "utf-8");
281246
+ source = readFileSync8(filePath, "utf-8");
280983
281247
  } catch (err2) {
280984
281248
  return "cannot read: " + (err2?.message ?? err2);
280985
281249
  }
@@ -281079,7 +281343,7 @@ async function loadLibModule(rootDir, name) {
281079
281343
  const cacheKey = rootDir + "/" + rel;
281080
281344
  if (libCache.has(cacheKey)) return libCache.get(cacheKey);
281081
281345
  const libPath = join15(rootDir, "lib", rel + ".ts");
281082
- if (!existsSync11(libPath)) {
281346
+ if (!existsSync12(libPath)) {
281083
281347
  throw new Error("Module '" + name + "' not found. Create lib/" + name + ".ts");
281084
281348
  }
281085
281349
  try {
@@ -281121,10 +281385,10 @@ async function loadTWMModule(filePath, rootDir) {
281121
281385
  const cacheKey = filePath;
281122
281386
  const cached2 = moduleCache.get(cacheKey);
281123
281387
  if (cached2) return cached2;
281124
- if (!existsSync11(filePath)) {
281388
+ if (!existsSync12(filePath)) {
281125
281389
  throw new Error("TWM module not found: " + filePath);
281126
281390
  }
281127
- const source = readFileSync7(filePath, "utf-8");
281391
+ const source = readFileSync8(filePath, "utf-8");
281128
281392
  const rd = rootDir || process.cwd();
281129
281393
  if (isRuleDsl(source)) {
281130
281394
  try {
@@ -281687,10 +281951,10 @@ var init_twm_loader = __esm({
281687
281951
  });
281688
281952
 
281689
281953
  // ../../packages/server/tw/routing/scanner.ts
281690
- import { existsSync as existsSync12, readdirSync as readdirSync3, statSync as statSync3 } from "node:fs";
281691
- 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";
281692
281956
  function scanRouteTree(opts) {
281693
- if (!existsSync12(opts.homeDir)) return null;
281957
+ if (!existsSync13(opts.homeDir)) return null;
281694
281958
  const root = {
281695
281959
  segment: "",
281696
281960
  relativePath: "",
@@ -281715,7 +281979,7 @@ function scanDirectory(dirPath, urlPath, groups, parentNode, opts) {
281715
281979
  }
281716
281980
  for (const entry of entries) {
281717
281981
  const fullPath = join16(dirPath, entry);
281718
- const ext = extname6(entry);
281982
+ const ext = extname7(entry);
281719
281983
  if (!ROUTE_EXTENSIONS.has(ext)) continue;
281720
281984
  let stat;
281721
281985
  try {
@@ -281724,7 +281988,7 @@ function scanDirectory(dirPath, urlPath, groups, parentNode, opts) {
281724
281988
  continue;
281725
281989
  }
281726
281990
  if (!stat.isFile()) continue;
281727
- const baseName = basename2(entry, ext);
281991
+ const baseName = basename3(entry, ext);
281728
281992
  const fileType = getRouteFileType(baseName);
281729
281993
  if (fileType === null) {
281730
281994
  continue;
@@ -282098,8 +282362,8 @@ var init_helpers = __esm({
282098
282362
  });
282099
282363
 
282100
282364
  // ../../packages/server/tw/routing/render-pipeline.ts
282101
- import { readFileSync as readFileSync8, existsSync as existsSync13 } from "node:fs";
282102
- 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";
282103
282367
  function getCacheProfiles(rootDir) {
282104
282368
  if (__profilesCache && __profilesCache.rootDir === rootDir) return __profilesCache.profiles;
282105
282369
  let profiles = {};
@@ -282137,8 +282401,8 @@ var init_render_pipeline = __esm({
282137
282401
  */
282138
282402
  async isUnenumeratedParam(pageFile, params) {
282139
282403
  if (!/\[[^\]]+\]/.test(pageFile)) return false;
282140
- const paramsTwm = dirname8(pageFile) + "/params.twm";
282141
- if (!existsSync13(paramsTwm)) return false;
282404
+ const paramsTwm = dirname9(pageFile) + "/params.twm";
282405
+ if (!existsSync14(paramsTwm)) return false;
282142
282406
  try {
282143
282407
  const { loadTWMModule: loadTWMModule2 } = await Promise.resolve().then(() => (init_twm_loader(), twm_loader_exports));
282144
282408
  const pmod = await loadTWMModule2(paramsTwm, this.rootDir);
@@ -282229,10 +282493,10 @@ var init_render_pipeline = __esm({
282229
282493
  /** Read a route file, memoised outside dev. See `sourceCache`. */
282230
282494
  readSource(file) {
282231
282495
  const key2 = file.absolutePath;
282232
- if (this.dev) return readFileSync8(key2, "utf-8");
282496
+ if (this.dev) return readFileSync9(key2, "utf-8");
282233
282497
  const hit = this.sourceCache.get(key2);
282234
282498
  if (hit !== void 0) return hit;
282235
- const src = readFileSync8(key2, "utf-8");
282499
+ const src = readFileSync9(key2, "utf-8");
282236
282500
  this.sourceCache.set(key2, src);
282237
282501
  return src;
282238
282502
  }
@@ -282692,9 +282956,9 @@ ${bodyHTML}`;
282692
282956
  try {
282693
282957
  const headCandidates = [];
282694
282958
  const globalHead = join17(this.rootDir, "home", "head.tw");
282695
- if (existsSync13(globalHead)) headCandidates.push(globalHead);
282696
- const siblingHead = join17(dirname8(ctx.page.absolutePath), "head.tw");
282697
- 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);
282698
282962
  for (const hp of headCandidates) {
282699
282963
  const headCompiled = this.compileFile({ absolutePath: hp, type: "head" });
282700
282964
  const m = headCompiled.html.match(/<body>([\s\S]*)<\/body>/);
@@ -282828,7 +283092,7 @@ ${bodyHTML}`;
282828
283092
  }
282829
283093
  };
282830
283094
  }
282831
- if (!existsSync13(file.absolutePath)) {
283095
+ if (!existsSync14(file.absolutePath)) {
282832
283096
  throw new Error(`Route file not found: ${file.absolutePath}`);
282833
283097
  }
282834
283098
  const source = this.readSource(file);
@@ -283222,7 +283486,7 @@ ${devScript}
283222
283486
  */
283223
283487
  async runMiddleware(pathname, request) {
283224
283488
  const middlewarePath = join17(this.rootDir, "middleware.twm");
283225
- if (!existsSync13(middlewarePath)) return;
283489
+ if (!existsSync14(middlewarePath)) return;
283226
283490
  const mod = await loadTWMModule(middlewarePath, this.rootDir);
283227
283491
  if (mod.config?.matcher && !shouldMatchMiddleware(mod.config.matcher, pathname)) {
283228
283492
  return;
@@ -283374,7 +283638,7 @@ var init_fs_compat = __esm({
283374
283638
  });
283375
283639
 
283376
283640
  // ../../packages/server/tw/router/index.ts
283377
- 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";
283378
283642
  import { join as join18 } from "node:path";
283379
283643
  var RouteRegistry;
283380
283644
  var init_router2 = __esm({
@@ -283443,7 +283707,7 @@ var init_router2 = __esm({
283443
283707
  return [...this.routes];
283444
283708
  }
283445
283709
  loadFromDir(pagesDir, basePath = "/") {
283446
- if (!existsSync14(pagesDir)) return;
283710
+ if (!existsSync15(pagesDir)) return;
283447
283711
  const files = [];
283448
283712
  this.collectFiles(pagesDir, ".tw", files, "");
283449
283713
  for (const file of files) {
@@ -285198,8 +285462,8 @@ var init_signal_transports = __esm({
285198
285462
  });
285199
285463
 
285200
285464
  // ../../packages/server/tw/static/index.ts
285201
- import { existsSync as existsSync15, statSync as statSync5 } from "node:fs";
285202
- 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";
285203
285467
  var StaticHandler;
285204
285468
  var init_static = __esm({
285205
285469
  "../../packages/server/tw/static/index.ts"() {
@@ -285239,32 +285503,32 @@ var init_static = __esm({
285239
285503
  return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
285240
285504
  }
285241
285505
  let filePath = join19(this.root, safePath);
285242
- if (existsSync15(filePath) && statSync5(filePath).isDirectory()) {
285506
+ if (existsSync16(filePath) && statSync5(filePath).isDirectory()) {
285243
285507
  filePath = join19(filePath, this.indexFile);
285244
285508
  }
285245
- if (!existsSync15(filePath)) {
285509
+ if (!existsSync16(filePath)) {
285246
285510
  filePath = join19(this.root, safePath + ".html");
285247
285511
  }
285248
285512
  let notFoundFallback = false;
285249
- if (!existsSync15(filePath)) {
285513
+ if (!existsSync16(filePath)) {
285250
285514
  filePath = join19(this.root, safePath, this.indexFile);
285251
285515
  }
285252
- if (!existsSync15(filePath)) {
285516
+ if (!existsSync16(filePath)) {
285253
285517
  if (this.spa) {
285254
285518
  filePath = join19(this.root, this.indexFile);
285255
- if (!existsSync15(filePath)) {
285519
+ if (!existsSync16(filePath)) {
285256
285520
  return new Response("Not Found", { status: 404 });
285257
285521
  }
285258
285522
  } else {
285259
285523
  filePath = join19(this.root, "404.html");
285260
285524
  notFoundFallback = true;
285261
- if (!existsSync15(filePath)) {
285525
+ if (!existsSync16(filePath)) {
285262
285526
  return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
285263
285527
  }
285264
285528
  }
285265
285529
  }
285266
285530
  const stat = statSync5(filePath);
285267
- const ext = extname7(filePath).toLowerCase();
285531
+ const ext = extname8(filePath).toLowerCase();
285268
285532
  const contentType = MIME_TYPES[ext] ?? "application/octet-stream";
285269
285533
  const bytes = await readBytes(filePath);
285270
285534
  let etagValue = "";
@@ -285383,7 +285647,7 @@ var init_static = __esm({
285383
285647
  });
285384
285648
 
285385
285649
  // ../../packages/server/tw/ssr/index.ts
285386
- 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";
285387
285651
  import { createHash as createHash5 } from "node:crypto";
285388
285652
  import { join as join20 } from "node:path";
285389
285653
  import { existsSync as existsSyncSync } from "node:fs";
@@ -285397,7 +285661,7 @@ function getCachedSSR(pathname) {
285397
285661
  }
285398
285662
  const diskPath = join20(_diskCacheDir, pathname.replace(/[\/]/g, "_") + ".html");
285399
285663
  if (existsSyncSync(diskPath)) {
285400
- const content = readFileSync9(diskPath, "utf-8");
285664
+ const content = readFileSync10(diskPath, "utf-8");
285401
285665
  const etag = createHash5("sha256").update(content).digest("hex").slice(0, 16);
285402
285666
  _ssrCache.set(pathname, { html: content, etag, expires: Date.now() + 6e4 });
285403
285667
  return { html: content, etag };
@@ -285410,7 +285674,7 @@ function setCachedSSR(pathname, html) {
285410
285674
  try {
285411
285675
  if (!existsSyncSync(_diskCacheDir)) mkdirSync4(_diskCacheDir, { recursive: true });
285412
285676
  const diskPath = join20(_diskCacheDir, pathname.replace(/[\/]/g, "_") + ".html");
285413
- writeFileSync5(diskPath, html);
285677
+ writeFileSync6(diskPath, html);
285414
285678
  } catch {
285415
285679
  }
285416
285680
  return etag;
@@ -285513,9 +285777,9 @@ var init_ssr = __esm({
285513
285777
  }
285514
285778
  }
285515
285779
  const filePath = this.resolveRoute(pathname);
285516
- if (!filePath || !existsSync16(filePath)) return null;
285780
+ if (!filePath || !existsSync17(filePath)) return null;
285517
285781
  try {
285518
- const source = readFileSync9(filePath, "utf-8");
285782
+ const source = readFileSync10(filePath, "utf-8");
285519
285783
  return {
285520
285784
  html: `<html><body>SSR sync not available</body></html>`,
285521
285785
  css: "",
@@ -285550,35 +285814,35 @@ var init_ssr = __esm({
285550
285814
  let currentDir = this.pagesDir;
285551
285815
  if (segments.length === 0) {
285552
285816
  const pagePath = join20(this.pagesDir, "page.tw");
285553
- if (existsSync16(pagePath)) return pagePath;
285817
+ if (existsSync17(pagePath)) return pagePath;
285554
285818
  const indexPath = join20(this.pagesDir, "index.tw");
285555
- if (existsSync16(indexPath)) return indexPath;
285819
+ if (existsSync17(indexPath)) return indexPath;
285556
285820
  return null;
285557
285821
  }
285558
285822
  for (let i = 0; i < segments.length; i++) {
285559
285823
  const seg = segments[i];
285560
285824
  const isLast = i === segments.length - 1;
285561
- const entries = existsSync16(currentDir) ? __require("node:fs").readdirSync(currentDir) : [];
285825
+ const entries = existsSync17(currentDir) ? __require("node:fs").readdirSync(currentDir) : [];
285562
285826
  if (isLast) {
285563
285827
  const exactPath = join20(currentDir, seg + ".tw");
285564
- if (existsSync16(exactPath)) return exactPath;
285828
+ if (existsSync17(exactPath)) return exactPath;
285565
285829
  const dirPage = join20(currentDir, seg, "page.tw");
285566
- if (existsSync16(dirPage)) return dirPage;
285830
+ if (existsSync17(dirPage)) return dirPage;
285567
285831
  const paramFile = entries.find((e) => e.match(/^\[([^\]]+)\]\.tw$/));
285568
285832
  if (paramFile) return join20(currentDir, paramFile);
285569
285833
  const paramDir = entries.find((e) => e.match(/^\[([^\]]+)\]$/));
285570
285834
  if (paramDir) {
285571
285835
  const p = join20(currentDir, paramDir, "page.tw");
285572
- if (existsSync16(p)) return p;
285836
+ if (existsSync17(p)) return p;
285573
285837
  const pIdx = join20(currentDir, paramDir, "index.tw");
285574
- if (existsSync16(pIdx)) return pIdx;
285838
+ if (existsSync17(pIdx)) return pIdx;
285575
285839
  }
285576
285840
  const idx = join20(currentDir, seg, "index.tw");
285577
- if (existsSync16(idx)) return idx;
285841
+ if (existsSync17(idx)) return idx;
285578
285842
  return null;
285579
285843
  }
285580
285844
  const dirPath = join20(currentDir, seg);
285581
- if (existsSync16(dirPath) && __require("node:fs").statSync(dirPath).isDirectory()) {
285845
+ if (existsSync17(dirPath) && __require("node:fs").statSync(dirPath).isDirectory()) {
285582
285846
  currentDir = dirPath;
285583
285847
  } else {
285584
285848
  const paramDir = entries.find((e) => e.match(/^\[([^\]]+)\]$/));
@@ -286967,7 +287231,7 @@ __export(tw_exports5, {
286967
287231
  wwwRedirect: () => wwwRedirect
286968
287232
  });
286969
287233
  import { join as join21 } from "node:path";
286970
- import { existsSync as existsSync17, readFileSync as readFileSync10 } from "node:fs";
287234
+ import { existsSync as existsSync18, readFileSync as readFileSync11 } from "node:fs";
286971
287235
  function normalizePathname(p) {
286972
287236
  return p.replace(/\/{2,}/g, "/");
286973
287237
  }
@@ -287258,11 +287522,11 @@ var init_tw10 = __esm({
287258
287522
  }
287259
287523
  }
287260
287524
  const staticDir = this.options.staticDir ?? join21(options.rootDir, ".tw");
287261
- if (existsSync17(staticDir)) {
287525
+ if (existsSync18(staticDir)) {
287262
287526
  try {
287263
287527
  const manifestPath = join21(staticDir, "routes.json");
287264
- if (existsSync17(manifestPath)) {
287265
- const manifest = JSON.parse(readFileSync10(manifestPath, "utf-8"));
287528
+ if (existsSync18(manifestPath)) {
287529
+ const manifest = JSON.parse(readFileSync11(manifestPath, "utf-8"));
287266
287530
  for (const [route, secs] of Object.entries(manifest)) {
287267
287531
  this.isrRoutes.set(route, secs);
287268
287532
  }
@@ -287280,7 +287544,7 @@ var init_tw10 = __esm({
287280
287544
  });
287281
287545
  }
287282
287546
  const homeDir = this.options.pagesDir ?? join21(options.rootDir, "home");
287283
- if (existsSync17(homeDir)) {
287547
+ if (existsSync18(homeDir)) {
287284
287548
  this.ssr = new SSRRenderer({ pagesDir: homeDir, enableCache: true, cacheTTL: 6e4 });
287285
287549
  }
287286
287550
  }
@@ -287327,11 +287591,11 @@ var init_tw10 = __esm({
287327
287591
  middlewarePath = null;
287328
287592
  loadMiddleware() {
287329
287593
  const middlewarePath = join21(this.options.rootDir, "middleware.twm");
287330
- if (existsSync17(middlewarePath)) {
287594
+ if (existsSync18(middlewarePath)) {
287331
287595
  this.middlewarePath = middlewarePath;
287332
287596
  console.log(" Middleware: middleware.twm loaded");
287333
287597
  try {
287334
- const src = readFileSync10(middlewarePath, "utf-8");
287598
+ const src = readFileSync11(middlewarePath, "utf-8");
287335
287599
  const rules = parseRules(src, "middleware.twm");
287336
287600
  for (const r of rules) {
287337
287601
  const conds = [];
@@ -287822,7 +288086,7 @@ var init_tw10 = __esm({
287822
288086
  return new Response("Bad Request", { status: 400 });
287823
288087
  }
287824
288088
  const homeDir = join21(this.options.rootDir, "home");
287825
- if (!existsSync17(homeDir)) return new Response("Not Found", { status: 404 });
288089
+ if (!existsSync18(homeDir)) return new Response("Not Found", { status: 404 });
287826
288090
  try {
287827
288091
  const { createRenderPipeline: createRenderPipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
287828
288092
  if (!this.renderPipeline) {
@@ -287971,7 +288235,7 @@ var init_tw10 = __esm({
287971
288235
  try {
287972
288236
  const { createRenderPipeline: createRenderPipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
287973
288237
  const homeDir = join21(this.options.rootDir, "home");
287974
- if (existsSync17(homeDir)) {
288238
+ if (existsSync18(homeDir)) {
287975
288239
  const pipeline = createRenderPipeline2({
287976
288240
  rootDir: this.options.rootDir,
287977
288241
  homeDir,
@@ -288031,7 +288295,7 @@ ${err2.stack ?? ""}`);
288031
288295
  try {
288032
288296
  const { createRenderPipeline: createRenderPipeline2, setActivePipeline: setActivePipeline2 } = await Promise.resolve().then(() => (init_routing2(), routing_exports));
288033
288297
  const homeDir = join21(this.options.rootDir, "home");
288034
- if (existsSync17(homeDir)) {
288298
+ if (existsSync18(homeDir)) {
288035
288299
  if (!this.renderPipeline) {
288036
288300
  this.renderPipeline = createRenderPipeline2({
288037
288301
  rootDir: this.options.rootDir,