tw-framework 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +89 -0
- package/dist/hydration-runtime.js +21 -3
- package/dist/testing.cjs +856 -152
- package/dist/tw-runtime-client.mjs +118 -39
- package/dist/tw-server.mjs +838 -134
- package/dist/tw.mjs +975 -169
- package/package.json +1 -1
package/dist/tw.mjs
CHANGED
|
@@ -1542,10 +1542,10 @@ var init_request_context = __esm({
|
|
|
1542
1542
|
throw new Error(`Environment variable ${name} is not valid JSON`);
|
|
1543
1543
|
}
|
|
1544
1544
|
}
|
|
1545
|
-
list(name,
|
|
1545
|
+
list(name, sep3 = ",") {
|
|
1546
1546
|
const v = this.source[name];
|
|
1547
1547
|
if (!v) return [];
|
|
1548
|
-
return v.split(
|
|
1548
|
+
return v.split(sep3).map((s) => s.trim()).filter(Boolean);
|
|
1549
1549
|
}
|
|
1550
1550
|
/**
|
|
1551
1551
|
* Validate a whole set at once -- call it at startup and every problem is
|
|
@@ -3332,10 +3332,10 @@ function printTable(headers, rows) {
|
|
|
3332
3332
|
return Math.max(h3.length, maxRowLen);
|
|
3333
3333
|
});
|
|
3334
3334
|
const formatRow = (cells) => " " + cells.map((cell, i) => String(cell).padEnd(widths[i])).join(" ") + " ";
|
|
3335
|
-
const
|
|
3335
|
+
const sep3 = "-".repeat(widths.reduce((a, b) => a + b + 2, 0) + 1);
|
|
3336
3336
|
process.stderr.write(`${ANSI.bold}${formatRow(headers)}${ANSI.reset}
|
|
3337
3337
|
`);
|
|
3338
|
-
process.stderr.write(`${ANSI.dim}${
|
|
3338
|
+
process.stderr.write(`${ANSI.dim}${sep3}${ANSI.reset}
|
|
3339
3339
|
`);
|
|
3340
3340
|
for (const row of rows) {
|
|
3341
3341
|
process.stderr.write(formatRow(row.map(String)) + "\n");
|
|
@@ -6915,20 +6915,39 @@ function sha12(data) {
|
|
|
6915
6915
|
async function md52(data) {
|
|
6916
6916
|
return hashWithWebCrypto("md5", data);
|
|
6917
6917
|
}
|
|
6918
|
+
function webcryptoHashName(algorithm) {
|
|
6919
|
+
const key2 = String(algorithm).toLowerCase().replace(/[-_]/g, "");
|
|
6920
|
+
const map2 = {
|
|
6921
|
+
md5: "MD5",
|
|
6922
|
+
sha1: "SHA-1",
|
|
6923
|
+
sha224: "SHA-224",
|
|
6924
|
+
sha256: "SHA-256",
|
|
6925
|
+
sha384: "SHA-384",
|
|
6926
|
+
sha512: "SHA-512"
|
|
6927
|
+
};
|
|
6928
|
+
return map2[key2] ?? algorithm;
|
|
6929
|
+
}
|
|
6918
6930
|
async function hmac2(data, key2, algorithm = "sha256") {
|
|
6919
6931
|
const encoder2 = new TextEncoder();
|
|
6920
6932
|
const keyData = encoder2.encode(key2);
|
|
6921
6933
|
const messageData = encoder2.encode(data);
|
|
6922
|
-
const cryptoKey = await crypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: algorithm }, false, ["sign"]);
|
|
6934
|
+
const cryptoKey = await crypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: webcryptoHashName(algorithm) }, false, ["sign"]);
|
|
6923
6935
|
const signature = await crypto.subtle.sign("HMAC", cryptoKey, messageData);
|
|
6924
6936
|
const hashArray = Array.from(new Uint8Array(signature));
|
|
6925
6937
|
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
6926
6938
|
}
|
|
6939
|
+
async function verifyHmac(data, key2, signature, algorithm = "sha256") {
|
|
6940
|
+
const expected = await hmac2(data, key2, algorithm);
|
|
6941
|
+
if (expected.length !== signature.length) return false;
|
|
6942
|
+
let diff2 = 0;
|
|
6943
|
+
for (let i = 0; i < expected.length; i++) diff2 |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
|
|
6944
|
+
return diff2 === 0;
|
|
6945
|
+
}
|
|
6927
6946
|
async function pbkdf2(password, salt, iterations = 1e5, keyLength = 256) {
|
|
6928
6947
|
const encoder2 = new TextEncoder();
|
|
6929
6948
|
const keyMaterial = await crypto.subtle.importKey("raw", encoder2.encode(password), "PBKDF2", false, ["deriveBits"]);
|
|
6930
6949
|
const derivedBits = await crypto.subtle.deriveBits(
|
|
6931
|
-
{ name: "PBKDF2", salt: encoder2.encode(salt), iterations, hash: "
|
|
6950
|
+
{ name: "PBKDF2", salt: encoder2.encode(salt), iterations, hash: "SHA-256" },
|
|
6932
6951
|
keyMaterial,
|
|
6933
6952
|
keyLength
|
|
6934
6953
|
);
|
|
@@ -6973,9 +6992,16 @@ async function decryptString(encryptedData, password, salt) {
|
|
|
6973
6992
|
const key2 = await deriveKey(password, salt);
|
|
6974
6993
|
return decryptAES(encrypted, key2, iv);
|
|
6975
6994
|
}
|
|
6995
|
+
async function generateRSASigningKeyPair(bits = 2048) {
|
|
6996
|
+
return crypto.subtle.generateKey(
|
|
6997
|
+
{ name: "RSASSA-PKCS1-v1_5", modulusLength: bits, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" },
|
|
6998
|
+
true,
|
|
6999
|
+
["sign", "verify"]
|
|
7000
|
+
);
|
|
7001
|
+
}
|
|
6976
7002
|
async function generateRSAKeyPair(bits = 2048) {
|
|
6977
7003
|
return crypto.subtle.generateKey(
|
|
6978
|
-
{ name: "RSA-OAEP", modulusLength: bits, publicExponent: new Uint8Array([1, 0, 1]), hash: "
|
|
7004
|
+
{ name: "RSA-OAEP", modulusLength: bits, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" },
|
|
6979
7005
|
true,
|
|
6980
7006
|
["encrypt", "decrypt"]
|
|
6981
7007
|
);
|
|
@@ -8423,36 +8449,6 @@ var init_etag = __esm({
|
|
|
8423
8449
|
});
|
|
8424
8450
|
|
|
8425
8451
|
// ../../packages/shared/tw/hashing/hmac.ts
|
|
8426
|
-
function bufferToHex2(buffer) {
|
|
8427
|
-
const bytes = new Uint8Array(buffer);
|
|
8428
|
-
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
8429
|
-
}
|
|
8430
|
-
function timingSafeEqual2(a, b) {
|
|
8431
|
-
if (a.length !== b.length) return false;
|
|
8432
|
-
let result = 0;
|
|
8433
|
-
for (let i = 0; i < a.length; i++) {
|
|
8434
|
-
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
8435
|
-
}
|
|
8436
|
-
return result === 0;
|
|
8437
|
-
}
|
|
8438
|
-
async function hmac3(key2, message, algorithm = "SHA-256") {
|
|
8439
|
-
const encoder2 = new TextEncoder();
|
|
8440
|
-
const keyData = encoder2.encode(key2);
|
|
8441
|
-
const messageData = encoder2.encode(message);
|
|
8442
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
8443
|
-
"raw",
|
|
8444
|
-
keyData,
|
|
8445
|
-
{ name: "HMAC", hash: algorithm },
|
|
8446
|
-
false,
|
|
8447
|
-
["sign"]
|
|
8448
|
-
);
|
|
8449
|
-
const signature = await crypto.subtle.sign("HMAC", cryptoKey, messageData);
|
|
8450
|
-
return bufferToHex2(signature);
|
|
8451
|
-
}
|
|
8452
|
-
async function verifyHmac(key2, message, signature, algorithm = "SHA-256") {
|
|
8453
|
-
const computed6 = await hmac3(key2, message, algorithm);
|
|
8454
|
-
return timingSafeEqual2(computed6, signature);
|
|
8455
|
-
}
|
|
8456
8452
|
var init_hmac = __esm({
|
|
8457
8453
|
"../../packages/shared/tw/hashing/hmac.ts"() {
|
|
8458
8454
|
}
|
|
@@ -9117,6 +9113,7 @@ __export(tw_exports, {
|
|
|
9117
9113
|
generatePIN: () => generatePIN,
|
|
9118
9114
|
generateProofOfKnowledge: () => generateProofOfKnowledge,
|
|
9119
9115
|
generateRSAKeyPair: () => generateRSAKeyPair,
|
|
9116
|
+
generateRSASigningKeyPair: () => generateRSASigningKeyPair,
|
|
9120
9117
|
generateSecret: () => generateSecret,
|
|
9121
9118
|
generateTOTP: () => generateTOTP,
|
|
9122
9119
|
geolocation: () => geolocation,
|
|
@@ -9622,6 +9619,7 @@ __export(tw_exports, {
|
|
|
9622
9619
|
zip: () => zip,
|
|
9623
9620
|
zipWith: () => zipWith
|
|
9624
9621
|
});
|
|
9622
|
+
import { createHmac } from "node:crypto";
|
|
9625
9623
|
function generateETag(data) {
|
|
9626
9624
|
let hash3 = 0;
|
|
9627
9625
|
for (let i = 0; i < data.length; i++) {
|
|
@@ -9647,19 +9645,14 @@ function merkleRoot(hashes) {
|
|
|
9647
9645
|
return level[0];
|
|
9648
9646
|
}
|
|
9649
9647
|
function hmacSign(data, key2) {
|
|
9650
|
-
|
|
9651
|
-
for (let i = 0; i < data.length; i++) {
|
|
9652
|
-
h1 = (h1 << 5) - h1 + data.charCodeAt(i);
|
|
9653
|
-
h1 |= 0;
|
|
9654
|
-
}
|
|
9655
|
-
for (let i = 0; i < key2.length; i++) {
|
|
9656
|
-
h22 = (h22 << 5) - h22 + key2.charCodeAt(i);
|
|
9657
|
-
h22 |= 0;
|
|
9658
|
-
}
|
|
9659
|
-
return (h1 ^ h22).toString(16);
|
|
9648
|
+
return createHmac("sha256", key2).update(data).digest("hex");
|
|
9660
9649
|
}
|
|
9661
9650
|
function hmacVerify(data, key2, signature) {
|
|
9662
|
-
|
|
9651
|
+
const expected = hmacSign(data, key2);
|
|
9652
|
+
if (expected.length !== signature.length) return false;
|
|
9653
|
+
let diff2 = 0;
|
|
9654
|
+
for (let i = 0; i < expected.length; i++) diff2 |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
|
|
9655
|
+
return diff2 === 0;
|
|
9663
9656
|
}
|
|
9664
9657
|
var HTML_TAGS;
|
|
9665
9658
|
var init_tw = __esm({
|
|
@@ -63421,11 +63414,11 @@ ${lanes.join("\n")}
|
|
|
63421
63414
|
if (i < rootLength) {
|
|
63422
63415
|
return void 0;
|
|
63423
63416
|
}
|
|
63424
|
-
const
|
|
63425
|
-
if (
|
|
63417
|
+
const sep3 = directory.lastIndexOf(directorySeparator, i - 1);
|
|
63418
|
+
if (sep3 === -1) {
|
|
63426
63419
|
return void 0;
|
|
63427
63420
|
}
|
|
63428
|
-
return directory.substr(0, Math.max(
|
|
63421
|
+
return directory.substr(0, Math.max(sep3, rootLength));
|
|
63429
63422
|
}
|
|
63430
63423
|
}
|
|
63431
63424
|
}
|
|
@@ -227229,7 +227222,7 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
227229
227222
|
const after2 = cursor.peek(1);
|
|
227230
227223
|
if (after2 && after2.type === "COLON") break;
|
|
227231
227224
|
}
|
|
227232
|
-
if (ct.type === "IDENT" && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227225
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227233
227226
|
break;
|
|
227234
227227
|
}
|
|
227235
227228
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -227257,7 +227250,11 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
227257
227250
|
while (!cursor.done) {
|
|
227258
227251
|
const ct = cursor.peek();
|
|
227259
227252
|
if (!ct) break;
|
|
227260
|
-
if (ct.type === "IDENT" &&
|
|
227253
|
+
if (ct.type === "IDENT" && ct.value === "on") {
|
|
227254
|
+
const after2 = cursor.peek(1);
|
|
227255
|
+
if (after2 && after2.type === "COLON") break;
|
|
227256
|
+
}
|
|
227257
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !nextPrevMinus && nextClass.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
227261
227258
|
break;
|
|
227262
227259
|
}
|
|
227263
227260
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -227547,7 +227544,9 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
227547
227544
|
const first = cursor.peek();
|
|
227548
227545
|
const second = cursor.peek(1);
|
|
227549
227546
|
const CONTROL_FLOW = /* @__PURE__ */ new Set(["for", "if", "while", "switch", "else", "try", "catch"]);
|
|
227550
|
-
const
|
|
227547
|
+
const third = cursor.peek(2);
|
|
227548
|
+
const isPropBlock = second && second.type === "ASSIGN" && third && third.type === "LBRACE";
|
|
227549
|
+
const isAttrBlock = first && (first.type === "IDENT" || first.type === "KEYWORD") && !CONTROL_FLOW.has(first.value) && (HTML_ATTRS_ONLY.has(first.value) || isPropBlock) && second && (second.type === "STRING" || second.type === "NUMBER" || second.type === "IDENT" || second.type === "KEYWORD" || second.type === "ASSIGN");
|
|
227551
227550
|
if (isAttrBlock) {
|
|
227552
227551
|
while (!cursor.done) {
|
|
227553
227552
|
const t3 = cursor.peek();
|
|
@@ -227555,6 +227554,34 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
227555
227554
|
if (t3.type === "IDENT" || t3.type === "KEYWORD") {
|
|
227556
227555
|
const attrName = t3.value;
|
|
227557
227556
|
cursor.advance();
|
|
227557
|
+
if (cursor.peek() && (cursor.peek().type === "ASSIGN" || cursor.peek().type === "EQUALS")) {
|
|
227558
|
+
cursor.advance();
|
|
227559
|
+
cursor.skipWhitespace();
|
|
227560
|
+
if (cursor.peek() && cursor.peek().type === "LBRACE") {
|
|
227561
|
+
cursor.advance();
|
|
227562
|
+
let expr = "";
|
|
227563
|
+
let depth = 1;
|
|
227564
|
+
let prevWS = false;
|
|
227565
|
+
while (!cursor.done) {
|
|
227566
|
+
const tk = cursor.peek();
|
|
227567
|
+
if (!tk || tk.type === "EOF") break;
|
|
227568
|
+
if (tk.type === "LBRACE") depth++;
|
|
227569
|
+
else if (tk.type === "RBRACE") {
|
|
227570
|
+
depth--;
|
|
227571
|
+
if (depth === 0) {
|
|
227572
|
+
cursor.advance();
|
|
227573
|
+
break;
|
|
227574
|
+
}
|
|
227575
|
+
}
|
|
227576
|
+
if (expr && prevWS) expr += " ";
|
|
227577
|
+
expr += tk.raw ?? tk.value;
|
|
227578
|
+
prevWS = !!tk.followedByWhitespace;
|
|
227579
|
+
cursor.advance();
|
|
227580
|
+
}
|
|
227581
|
+
el.attrs.push(createAttribute(attrName, expr.trim(), t3.pos.line, t3.pos.col, true));
|
|
227582
|
+
continue;
|
|
227583
|
+
}
|
|
227584
|
+
}
|
|
227558
227585
|
const vToken = cursor.peek();
|
|
227559
227586
|
if (vToken && (vToken.type === "STRING" || vToken.type === "NUMBER")) {
|
|
227560
227587
|
cursor.advance();
|
|
@@ -233625,8 +233652,8 @@ var init_constant_folding = __esm({
|
|
|
233625
233652
|
return { type: "string", value: str2.substring(start, end) };
|
|
233626
233653
|
}
|
|
233627
233654
|
case "split": {
|
|
233628
|
-
const
|
|
233629
|
-
const parts =
|
|
233655
|
+
const sep3 = args[0]?.type === "string" ? args[0].value : "";
|
|
233656
|
+
const parts = sep3 ? str2.split(sep3) : [str2];
|
|
233630
233657
|
return { type: "array", elements: parts.map((p) => ({ type: "string", value: p })) };
|
|
233631
233658
|
}
|
|
233632
233659
|
case "replace": {
|
|
@@ -233694,8 +233721,8 @@ var init_constant_folding = __esm({
|
|
|
233694
233721
|
case "length":
|
|
233695
233722
|
return { type: "number", value: elements.length };
|
|
233696
233723
|
case "join": {
|
|
233697
|
-
const
|
|
233698
|
-
return { type: "string", value: elements.map((e) => this.constToJSString(e)).join(
|
|
233724
|
+
const sep3 = args[0]?.type === "string" ? args[0].value : ",";
|
|
233725
|
+
return { type: "string", value: elements.map((e) => this.constToJSString(e)).join(sep3) };
|
|
233699
233726
|
}
|
|
233700
233727
|
case "indexOf": {
|
|
233701
233728
|
if (!args[0]) return null;
|
|
@@ -236300,7 +236327,7 @@ var init_types4 = __esm({
|
|
|
236300
236327
|
var TW_VERSION, TW_GENERATOR_META;
|
|
236301
236328
|
var init_version = __esm({
|
|
236302
236329
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
236303
|
-
TW_VERSION = "2.0.
|
|
236330
|
+
TW_VERSION = "2.0.2";
|
|
236304
236331
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
236305
236332
|
}
|
|
236306
236333
|
});
|
|
@@ -236324,6 +236351,9 @@ function optimizedImageUrl(src, opts = {}) {
|
|
|
236324
236351
|
if (opts.quality) p.set("q", String(opts.quality));
|
|
236325
236352
|
p.set("f", opts.format ?? "auto");
|
|
236326
236353
|
const qs = p.toString();
|
|
236354
|
+
if (/^https?:\/\//i.test(src)) {
|
|
236355
|
+
return `/_tw/img/_remote?src=${encodeURIComponent(src)}&${qs}`;
|
|
236356
|
+
}
|
|
236327
236357
|
return `/_tw/img${src.startsWith("/") ? src : "/" + src}?${qs}`;
|
|
236328
236358
|
}
|
|
236329
236359
|
function imageAttributesFor(opts, config = DEFAULT_IMAGE_CONFIG) {
|
|
@@ -236331,7 +236361,7 @@ function imageAttributesFor(opts, config = DEFAULT_IMAGE_CONFIG) {
|
|
|
236331
236361
|
const quality = opts.quality ?? config.quality;
|
|
236332
236362
|
const format = config.formats[0] ?? "webp";
|
|
236333
236363
|
const isRemote = /^https?:\/\//i.test(opts.src);
|
|
236334
|
-
const src = isRemote ? `/_tw/img/_remote?src=${encodeURIComponent(opts.src)}
|
|
236364
|
+
const src = isRemote ? `/_tw/img/_remote?src=${encodeURIComponent(opts.src)}${opts.width ? `&w=${opts.width}` : ""}${opts.height ? `&h=${opts.height}` : ""}&q=${quality}&f=auto` : optimizedImageUrl(opts.src, { width: opts.width, height: opts.height, quality });
|
|
236335
236365
|
const widths = config.breakpoints.filter((bp) => width === 0 || bp <= width * 2);
|
|
236336
236366
|
const srcset = widths.map(
|
|
236337
236367
|
(bp) => isRemote ? `/_tw/img/_remote?src=${encodeURIComponent(opts.src)}&w=${bp}&q=${quality}&f=auto ${bp}w` : `${optimizedImageUrl(opts.src, { width: bp, quality })} ${bp}w`
|
|
@@ -236511,7 +236541,7 @@ function createImageHandler(options) {
|
|
|
236511
236541
|
}
|
|
236512
236542
|
if (!warnedNoSharp) {
|
|
236513
236543
|
warnedNoSharp = true;
|
|
236514
|
-
console.warn(" [tw/image] sharp not installed \u2014
|
|
236544
|
+
console.warn(" [tw/image] sharp not installed \u2014 using the built-in converter (WebP/AVIF); install sharp for faster resizing");
|
|
236515
236545
|
}
|
|
236516
236546
|
return { data, contentType: "", viaSharp: false };
|
|
236517
236547
|
}
|
|
@@ -236626,7 +236656,11 @@ var init_tw2 = __esm({
|
|
|
236626
236656
|
});
|
|
236627
236657
|
|
|
236628
236658
|
// ../../packages/link/tw/index.ts
|
|
236659
|
+
function isDangerousHref(href) {
|
|
236660
|
+
return DANGEROUS_SCHEME.test(href.replace(/[\u0000-\u0020]/g, ""));
|
|
236661
|
+
}
|
|
236629
236662
|
function isExternalHref(href) {
|
|
236663
|
+
if (isDangerousHref(href)) return false;
|
|
236630
236664
|
return /^[a-z][a-z0-9+.-]*:/i.test(href) || // any scheme: http(s), mailto, tel, ...
|
|
236631
236665
|
href.startsWith("//");
|
|
236632
236666
|
}
|
|
@@ -236635,7 +236669,8 @@ function isWebExternal(href) {
|
|
|
236635
236669
|
return true;
|
|
236636
236670
|
}
|
|
236637
236671
|
function linkAttributesFor(opts) {
|
|
236638
|
-
const
|
|
236672
|
+
const rawHref = (opts.href ?? "").trim();
|
|
236673
|
+
const href = isDangerousHref(rawHref) ? "#" : rawHref;
|
|
236639
236674
|
const external = opts.external === true || isExternalHref(href);
|
|
236640
236675
|
const attrs = {};
|
|
236641
236676
|
if (external) {
|
|
@@ -236664,8 +236699,10 @@ function linkAttributesFor(opts) {
|
|
|
236664
236699
|
if (opts.id) attrs["id"] = opts.id;
|
|
236665
236700
|
return { href, external, attrs };
|
|
236666
236701
|
}
|
|
236702
|
+
var DANGEROUS_SCHEME;
|
|
236667
236703
|
var init_tw3 = __esm({
|
|
236668
236704
|
"../../packages/link/tw/index.ts"() {
|
|
236705
|
+
DANGEROUS_SCHEME = /^(javascript|data|vbscript):/i;
|
|
236669
236706
|
}
|
|
236670
236707
|
});
|
|
236671
236708
|
|
|
@@ -237178,12 +237215,31 @@ var init_interpolate = __esm({
|
|
|
237178
237215
|
});
|
|
237179
237216
|
|
|
237180
237217
|
// ../../packages/compiler/tw/eval/evaluate.ts
|
|
237218
|
+
function setEvalBindings(bindings) {
|
|
237219
|
+
extraBindings = bindings ?? {};
|
|
237220
|
+
}
|
|
237181
237221
|
function evaluate(expr, vars, sandbox) {
|
|
237182
237222
|
if (!expr) return "";
|
|
237183
237223
|
const sb = sandbox ?? defaultSandbox;
|
|
237184
237224
|
if (vars[expr] !== void 0) {
|
|
237185
237225
|
return vars[expr];
|
|
237186
237226
|
}
|
|
237227
|
+
if (expr.startsWith("(") && expr.endsWith(")")) {
|
|
237228
|
+
let d = 0;
|
|
237229
|
+
let wraps = true;
|
|
237230
|
+
for (let i = 0; i < expr.length; i++) {
|
|
237231
|
+
const ch = expr[i];
|
|
237232
|
+
if (ch === "(") d++;
|
|
237233
|
+
else if (ch === ")") {
|
|
237234
|
+
d--;
|
|
237235
|
+
if (d === 0 && i < expr.length - 1) {
|
|
237236
|
+
wraps = false;
|
|
237237
|
+
break;
|
|
237238
|
+
}
|
|
237239
|
+
}
|
|
237240
|
+
}
|
|
237241
|
+
if (wraps && d === 0) return evaluate(expr.slice(1, -1).trim(), vars, sb);
|
|
237242
|
+
}
|
|
237187
237243
|
if (/^-?\d+(\.\d+)?$/.test(expr)) return expr;
|
|
237188
237244
|
if (expr.startsWith('"') && expr.endsWith('"') || expr.startsWith("'") && expr.endsWith("'")) {
|
|
237189
237245
|
return expr.slice(1, -1);
|
|
@@ -237191,11 +237247,54 @@ function evaluate(expr, vars, sandbox) {
|
|
|
237191
237247
|
if (expr === "true") return "true";
|
|
237192
237248
|
if (expr === "false") return "false";
|
|
237193
237249
|
if (expr === "null" || expr === "undefined") return "";
|
|
237194
|
-
|
|
237195
|
-
|
|
237196
|
-
|
|
237197
|
-
|
|
237250
|
+
{
|
|
237251
|
+
let depth = 0;
|
|
237252
|
+
let pending2 = 0;
|
|
237253
|
+
let q = -1;
|
|
237254
|
+
let quote = "";
|
|
237255
|
+
for (let i = 0; i < expr.length; i++) {
|
|
237256
|
+
const ch = expr[i];
|
|
237257
|
+
if (quote) {
|
|
237258
|
+
if (ch === "\\") {
|
|
237259
|
+
i++;
|
|
237260
|
+
continue;
|
|
237261
|
+
}
|
|
237262
|
+
if (ch === quote) quote = "";
|
|
237263
|
+
continue;
|
|
237264
|
+
}
|
|
237265
|
+
if (ch === "'" || ch === '"' || ch === "`") {
|
|
237266
|
+
quote = ch;
|
|
237267
|
+
continue;
|
|
237268
|
+
}
|
|
237269
|
+
if (ch === "(" || ch === "[" || ch === "{") {
|
|
237270
|
+
depth++;
|
|
237271
|
+
continue;
|
|
237272
|
+
}
|
|
237273
|
+
if (ch === ")" || ch === "]" || ch === "}") {
|
|
237274
|
+
depth--;
|
|
237275
|
+
continue;
|
|
237276
|
+
}
|
|
237277
|
+
if (depth !== 0) continue;
|
|
237278
|
+
if (ch === "?") {
|
|
237279
|
+
if (pending2 === 0) q = i;
|
|
237280
|
+
pending2++;
|
|
237281
|
+
continue;
|
|
237282
|
+
}
|
|
237283
|
+
if (ch === ":" && pending2 > 0) {
|
|
237284
|
+
pending2--;
|
|
237285
|
+
if (pending2 > 0) continue;
|
|
237286
|
+
const cond = expr.slice(0, q).trim();
|
|
237287
|
+
const cons = expr.slice(q + 1, i).trim();
|
|
237288
|
+
const alt = expr.slice(i + 1).trim();
|
|
237289
|
+
if (cond && cons && alt) {
|
|
237290
|
+
return isTruthy(resolve3(cond, vars, sb)) ? resolve3(cons, vars, sb) : resolve3(alt, vars, sb);
|
|
237291
|
+
}
|
|
237292
|
+
break;
|
|
237293
|
+
}
|
|
237294
|
+
}
|
|
237198
237295
|
}
|
|
237296
|
+
const dyn = evalWithVars(expr, vars);
|
|
237297
|
+
if (dyn !== null) return dyn;
|
|
237199
237298
|
const orParts = splitLogical(expr, "||");
|
|
237200
237299
|
if (orParts.length > 1) {
|
|
237201
237300
|
for (const part of orParts) {
|
|
@@ -237272,7 +237371,7 @@ function evaluate(expr, vars, sandbox) {
|
|
|
237272
237371
|
return current2 !== void 0 && current2 !== null ? String(current2) : "";
|
|
237273
237372
|
}
|
|
237274
237373
|
const fnMatch = expr.match(/^(\w+)\((.*)\)$/);
|
|
237275
|
-
if (fnMatch) {
|
|
237374
|
+
if (fnMatch && isBuiltinName(fnMatch[1])) {
|
|
237276
237375
|
const fn = fnMatch[1];
|
|
237277
237376
|
const arg = resolve3(fnMatch[2].trim(), vars, sb);
|
|
237278
237377
|
return callBuiltin(fn, arg, sb);
|
|
@@ -237291,6 +237390,38 @@ function evaluate(expr, vars, sandbox) {
|
|
|
237291
237390
|
}
|
|
237292
237391
|
return expr;
|
|
237293
237392
|
}
|
|
237393
|
+
function evalWithVars(expr, vars) {
|
|
237394
|
+
if (!expr || /[`\\]/.test(expr)) return null;
|
|
237395
|
+
if (!/^[\w\s.$[\]{}()'"`,+\-*/%?:<>=!&|]*$/.test(expr)) return null;
|
|
237396
|
+
for (const m of expr.matchAll(/\.([A-Za-z_$][\w$]*)\s*\(/g)) {
|
|
237397
|
+
if (!SAFE_MEMBERS.has(m[1])) return null;
|
|
237398
|
+
}
|
|
237399
|
+
const names = [];
|
|
237400
|
+
const vals = [];
|
|
237401
|
+
for (const k of Object.keys(vars)) {
|
|
237402
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(k)) continue;
|
|
237403
|
+
if (k in extraBindings) continue;
|
|
237404
|
+
names.push(k);
|
|
237405
|
+
try {
|
|
237406
|
+
vals.push(JSON.parse(vars[k]));
|
|
237407
|
+
} catch {
|
|
237408
|
+
vals.push(vars[k]);
|
|
237409
|
+
}
|
|
237410
|
+
}
|
|
237411
|
+
for (const k of Object.keys(extraBindings)) {
|
|
237412
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(k)) continue;
|
|
237413
|
+
names.push(k);
|
|
237414
|
+
vals.push(extraBindings[k]);
|
|
237415
|
+
}
|
|
237416
|
+
try {
|
|
237417
|
+
const fn = new Function(...names, `"use strict"; return (${expr});`);
|
|
237418
|
+
const out = fn(...vals);
|
|
237419
|
+
if (out === void 0 || out === null) return null;
|
|
237420
|
+
return typeof out === "object" ? JSON.stringify(out) : String(out);
|
|
237421
|
+
} catch {
|
|
237422
|
+
return null;
|
|
237423
|
+
}
|
|
237424
|
+
}
|
|
237294
237425
|
function resolve3(token, vars, sandbox) {
|
|
237295
237426
|
const trimmed = token.trim();
|
|
237296
237427
|
if (!trimmed) return "";
|
|
@@ -237459,7 +237590,7 @@ function coerce(value, targetType) {
|
|
|
237459
237590
|
return value;
|
|
237460
237591
|
}
|
|
237461
237592
|
}
|
|
237462
|
-
var defaultSandbox;
|
|
237593
|
+
var defaultSandbox, extraBindings, SAFE_MEMBERS;
|
|
237463
237594
|
var init_evaluate = __esm({
|
|
237464
237595
|
"../../packages/compiler/tw/eval/evaluate.ts"() {
|
|
237465
237596
|
init_sandbox();
|
|
@@ -237467,6 +237598,64 @@ var init_evaluate = __esm({
|
|
|
237467
237598
|
init_builtins();
|
|
237468
237599
|
init_interpolate();
|
|
237469
237600
|
defaultSandbox = new Sandbox();
|
|
237601
|
+
extraBindings = {};
|
|
237602
|
+
SAFE_MEMBERS = /* @__PURE__ */ new Set([
|
|
237603
|
+
"length",
|
|
237604
|
+
"toUpperCase",
|
|
237605
|
+
"toLowerCase",
|
|
237606
|
+
"trim",
|
|
237607
|
+
"trimStart",
|
|
237608
|
+
"trimEnd",
|
|
237609
|
+
"slice",
|
|
237610
|
+
"substring",
|
|
237611
|
+
"substr",
|
|
237612
|
+
"charAt",
|
|
237613
|
+
"at",
|
|
237614
|
+
"includes",
|
|
237615
|
+
"indexOf",
|
|
237616
|
+
"lastIndexOf",
|
|
237617
|
+
"startsWith",
|
|
237618
|
+
"endsWith",
|
|
237619
|
+
"replace",
|
|
237620
|
+
"replaceAll",
|
|
237621
|
+
"split",
|
|
237622
|
+
"join",
|
|
237623
|
+
"concat",
|
|
237624
|
+
"repeat",
|
|
237625
|
+
"padStart",
|
|
237626
|
+
"padEnd",
|
|
237627
|
+
"toString",
|
|
237628
|
+
"toFixed",
|
|
237629
|
+
"map",
|
|
237630
|
+
"filter",
|
|
237631
|
+
"find",
|
|
237632
|
+
"some",
|
|
237633
|
+
"every",
|
|
237634
|
+
"reduce",
|
|
237635
|
+
"sort",
|
|
237636
|
+
"reverse",
|
|
237637
|
+
// Static helpers on the built-ins (JSON.stringify, Object.keys, Math.round).
|
|
237638
|
+
"stringify",
|
|
237639
|
+
"parse",
|
|
237640
|
+
"keys",
|
|
237641
|
+
"values",
|
|
237642
|
+
"entries",
|
|
237643
|
+
"from",
|
|
237644
|
+
"isArray",
|
|
237645
|
+
"isInteger",
|
|
237646
|
+
"isFinite",
|
|
237647
|
+
"abs",
|
|
237648
|
+
"ceil",
|
|
237649
|
+
"floor",
|
|
237650
|
+
"round",
|
|
237651
|
+
"max",
|
|
237652
|
+
"min",
|
|
237653
|
+
"pow",
|
|
237654
|
+
"sqrt",
|
|
237655
|
+
"random",
|
|
237656
|
+
"now",
|
|
237657
|
+
"toISOString"
|
|
237658
|
+
]);
|
|
237470
237659
|
}
|
|
237471
237660
|
});
|
|
237472
237661
|
|
|
@@ -237621,9 +237810,78 @@ function callBuiltin(fn, arg, sandbox) {
|
|
|
237621
237810
|
function applyFilter(value, filter, args, vars, sandbox) {
|
|
237622
237811
|
return callBuiltin(filter, value, sandbox);
|
|
237623
237812
|
}
|
|
237813
|
+
function isBuiltinName(fn) {
|
|
237814
|
+
return BUILTIN_NAMES.has(fn);
|
|
237815
|
+
}
|
|
237816
|
+
var BUILTIN_NAMES;
|
|
237624
237817
|
var init_builtins = __esm({
|
|
237625
237818
|
"../../packages/compiler/tw/eval/builtins.ts"() {
|
|
237626
237819
|
init_evaluate();
|
|
237820
|
+
BUILTIN_NAMES = /* @__PURE__ */ new Set([
|
|
237821
|
+
"Boolean",
|
|
237822
|
+
"Number",
|
|
237823
|
+
"String",
|
|
237824
|
+
"abs",
|
|
237825
|
+
"base64decode",
|
|
237826
|
+
"base64encode",
|
|
237827
|
+
"bool",
|
|
237828
|
+
"camelCase",
|
|
237829
|
+
"capitalize",
|
|
237830
|
+
"ceil",
|
|
237831
|
+
"cos",
|
|
237832
|
+
"date",
|
|
237833
|
+
"decodeURI",
|
|
237834
|
+
"encodeURI",
|
|
237835
|
+
"endsWith",
|
|
237836
|
+
"exp",
|
|
237837
|
+
"first",
|
|
237838
|
+
"float",
|
|
237839
|
+
"floor",
|
|
237840
|
+
"includes",
|
|
237841
|
+
"indexOf",
|
|
237842
|
+
"int",
|
|
237843
|
+
"join",
|
|
237844
|
+
"json",
|
|
237845
|
+
"kebabCase",
|
|
237846
|
+
"last",
|
|
237847
|
+
"len",
|
|
237848
|
+
"length",
|
|
237849
|
+
"log",
|
|
237850
|
+
"lower",
|
|
237851
|
+
"lowercase",
|
|
237852
|
+
"match",
|
|
237853
|
+
"max",
|
|
237854
|
+
"min",
|
|
237855
|
+
"now",
|
|
237856
|
+
"num",
|
|
237857
|
+
"padEnd",
|
|
237858
|
+
"padStart",
|
|
237859
|
+
"parseFloat",
|
|
237860
|
+
"parseInt",
|
|
237861
|
+
"parseJSON",
|
|
237862
|
+
"pow",
|
|
237863
|
+
"random",
|
|
237864
|
+
"repeat",
|
|
237865
|
+
"replace",
|
|
237866
|
+
"reverse",
|
|
237867
|
+
"round",
|
|
237868
|
+
"sin",
|
|
237869
|
+
"size",
|
|
237870
|
+
"slice",
|
|
237871
|
+
"snakeCase",
|
|
237872
|
+
"split",
|
|
237873
|
+
"sqrt",
|
|
237874
|
+
"startsWith",
|
|
237875
|
+
"str",
|
|
237876
|
+
"stringify",
|
|
237877
|
+
"tan",
|
|
237878
|
+
"test",
|
|
237879
|
+
"time",
|
|
237880
|
+
"title",
|
|
237881
|
+
"trim",
|
|
237882
|
+
"upper",
|
|
237883
|
+
"uppercase"
|
|
237884
|
+
]);
|
|
237627
237885
|
}
|
|
237628
237886
|
});
|
|
237629
237887
|
|
|
@@ -238672,16 +238930,61 @@ function addScope(css, scopeId) {
|
|
|
238672
238930
|
out += prelude;
|
|
238673
238931
|
return out;
|
|
238674
238932
|
}
|
|
238675
|
-
function
|
|
238676
|
-
|
|
238677
|
-
|
|
238678
|
-
|
|
238933
|
+
function interpolateBraces(input, vars) {
|
|
238934
|
+
let out = "";
|
|
238935
|
+
let i = 0;
|
|
238936
|
+
while (i < input.length) {
|
|
238937
|
+
const ch = input[i];
|
|
238938
|
+
if (ch !== "{") {
|
|
238939
|
+
out += ch;
|
|
238940
|
+
i++;
|
|
238941
|
+
continue;
|
|
238942
|
+
}
|
|
238943
|
+
let depth = 1;
|
|
238944
|
+
let j = i + 1;
|
|
238945
|
+
let quote = "";
|
|
238946
|
+
while (j < input.length && depth > 0) {
|
|
238947
|
+
const c = input[j];
|
|
238948
|
+
if (quote) {
|
|
238949
|
+
if (c === "\\") {
|
|
238950
|
+
j += 2;
|
|
238951
|
+
continue;
|
|
238952
|
+
}
|
|
238953
|
+
if (c === quote) quote = "";
|
|
238954
|
+
j++;
|
|
238955
|
+
continue;
|
|
238956
|
+
}
|
|
238957
|
+
if (c === "'" || c === '"' || c === "`") {
|
|
238958
|
+
quote = c;
|
|
238959
|
+
j++;
|
|
238960
|
+
continue;
|
|
238961
|
+
}
|
|
238962
|
+
if (c === "{") depth++;
|
|
238963
|
+
else if (c === "}") {
|
|
238964
|
+
depth--;
|
|
238965
|
+
if (depth === 0) break;
|
|
238966
|
+
}
|
|
238967
|
+
j++;
|
|
238968
|
+
}
|
|
238969
|
+
if (depth !== 0) {
|
|
238970
|
+
out += ch;
|
|
238971
|
+
i++;
|
|
238972
|
+
continue;
|
|
238973
|
+
}
|
|
238974
|
+
const key2 = input.slice(i + 1, j).trim();
|
|
238679
238975
|
if (/^[a-zA-Z_$][\w$]*$/.test(key2)) {
|
|
238680
|
-
|
|
238976
|
+
out += vars[key2] ?? "";
|
|
238977
|
+
} else {
|
|
238978
|
+
const val = evaluate(key2, vars);
|
|
238979
|
+
out += val === null ? "" : val;
|
|
238681
238980
|
}
|
|
238682
|
-
|
|
238683
|
-
|
|
238684
|
-
|
|
238981
|
+
i = j + 1;
|
|
238982
|
+
}
|
|
238983
|
+
return out;
|
|
238984
|
+
}
|
|
238985
|
+
function interpolate2(expr, vars) {
|
|
238986
|
+
const masked = expr.replace(/\\\{/g, "O").replace(/\\\}/g, "C");
|
|
238987
|
+
const out = interpolateBraces(masked, vars);
|
|
238685
238988
|
return out.replace(/\u0001O/g, "{").replace(/\u0001C/g, "}");
|
|
238686
238989
|
}
|
|
238687
238990
|
function isTruthy2(val) {
|
|
@@ -239118,6 +239421,11 @@ function generateElement(el, ctx) {
|
|
|
239118
239421
|
}
|
|
239119
239422
|
function renderAttrs(el, ctx) {
|
|
239120
239423
|
const parts = [];
|
|
239424
|
+
const classAttrs = el.attrs.filter((a) => a.name === "class" && !a.isInterpolated && typeof a.value === "string");
|
|
239425
|
+
if (classAttrs.length > 1) {
|
|
239426
|
+
const merged = classAttrs.map((a) => String(a.value).trim()).filter(Boolean).join(" ");
|
|
239427
|
+
el = { ...el, attrs: el.attrs.filter((a) => a.name !== "class").concat([{ ...classAttrs[0], value: merged }]) };
|
|
239428
|
+
}
|
|
239121
239429
|
for (let attr of el.attrs) {
|
|
239122
239430
|
if (attr.name === "class" && typeof attr.value === "string" && !attr.isInterpolated) {
|
|
239123
239431
|
const scoped = ctx.scopedClasses;
|
|
@@ -239160,7 +239468,21 @@ function renderBindings(bindings, ctx) {
|
|
|
239160
239468
|
if (bindings.length === 0) return "";
|
|
239161
239469
|
const parts = [];
|
|
239162
239470
|
for (const binding of bindings) {
|
|
239163
|
-
|
|
239471
|
+
const expr = String(binding.expression ?? "");
|
|
239472
|
+
let initial = "";
|
|
239473
|
+
try {
|
|
239474
|
+
if (/^[A-Za-z_$][\w$]*$/.test(expr)) {
|
|
239475
|
+
const v = ctx.stateVars[expr];
|
|
239476
|
+
if (v !== void 0 && v !== null) initial = String(v);
|
|
239477
|
+
} else if (expr) {
|
|
239478
|
+
initial = interpolate2("{" + expr + "}", ctx.stateVars);
|
|
239479
|
+
}
|
|
239480
|
+
} catch {
|
|
239481
|
+
}
|
|
239482
|
+
if (initial && !/[{}]/.test(initial)) {
|
|
239483
|
+
parts.push(`${binding.property}="${escapeAttr3(initial)}"`);
|
|
239484
|
+
}
|
|
239485
|
+
parts.push(`data-tw-bind-${binding.property}="${escapeAttr3(expr)}"`);
|
|
239164
239486
|
}
|
|
239165
239487
|
return parts.join(" ");
|
|
239166
239488
|
}
|
|
@@ -239275,8 +239597,13 @@ function generateComponent(comp, ctx) {
|
|
|
239275
239597
|
const savedStateVars = { ...ctx.stateVars };
|
|
239276
239598
|
for (const prop of comp.props) {
|
|
239277
239599
|
if (typeof prop.value === "string") {
|
|
239278
|
-
const
|
|
239279
|
-
|
|
239600
|
+
const raw = String(prop.value);
|
|
239601
|
+
const head = raw.split(/[.[]/)[0];
|
|
239602
|
+
if (!/[{}]/.test(raw) && Object.prototype.hasOwnProperty.call(ctx.stateVars, head)) {
|
|
239603
|
+
ctx.stateVars[prop.name] = interpolate2("{" + raw + "}", ctx.stateVars);
|
|
239604
|
+
} else {
|
|
239605
|
+
ctx.stateVars[prop.name] = interpolate2(raw, ctx.stateVars);
|
|
239606
|
+
}
|
|
239280
239607
|
}
|
|
239281
239608
|
}
|
|
239282
239609
|
const componentProgram = componentRegistry.get(comp.name);
|
|
@@ -239370,6 +239697,14 @@ function generateFor(node, ctx) {
|
|
|
239370
239697
|
}
|
|
239371
239698
|
}
|
|
239372
239699
|
}
|
|
239700
|
+
if (items.length === 0 && !/^\s*\[/.test(iterableStr)) {
|
|
239701
|
+
try {
|
|
239702
|
+
const evaluated = evaluate(String(node.iterable ?? "").replace(/^\{/, "").replace(/\}$/, "").trim(), ctx.stateVars);
|
|
239703
|
+
const parsed = JSON.parse(evaluated);
|
|
239704
|
+
if (Array.isArray(parsed)) items = parsed;
|
|
239705
|
+
} catch {
|
|
239706
|
+
}
|
|
239707
|
+
}
|
|
239373
239708
|
for (let i = 0; i < items.length; i++) {
|
|
239374
239709
|
const childCtx = { ...ctx };
|
|
239375
239710
|
childCtx.stateVars = { ...ctx.stateVars };
|
|
@@ -239390,7 +239725,7 @@ function generateFor(node, ctx) {
|
|
|
239390
239725
|
tplSource = node.body.map((c) => generateNode(c, childCtx)).join("");
|
|
239391
239726
|
}
|
|
239392
239727
|
const listExpr = String(node.iterable ?? "").replace(/^\{/, "").replace(/\}$/, "");
|
|
239393
|
-
const tpl = tplSource.replace(/"/g, """);
|
|
239728
|
+
const tpl = tplSource.replace(/&/g, "&").replace(/"/g, """);
|
|
239394
239729
|
return `<tw-for data-tw-var="${node.varName}"${node.indexName ? ` data-tw-index="${node.indexName}"` : ""} data-tw-list="${listExpr}" data-tw-tpl="${tpl}">${html}</tw-for>`;
|
|
239395
239730
|
}
|
|
239396
239731
|
return html;
|
|
@@ -243176,16 +243511,22 @@ function generateWithLayoutChain(layoutPrograms, pageProgram, stateVars) {
|
|
|
243176
243511
|
}
|
|
243177
243512
|
};
|
|
243178
243513
|
let pageTitle = "TW Page";
|
|
243514
|
+
let pageDescription = "";
|
|
243179
243515
|
for (const dir of pageProgram.directives || []) {
|
|
243180
|
-
if (dir.type === "PageDirective"
|
|
243181
|
-
|
|
243182
|
-
|
|
243516
|
+
if (dir.type === "PageDirective") {
|
|
243517
|
+
if (dir.key === "title") {
|
|
243518
|
+
const t3 = dir.value;
|
|
243519
|
+
if (t3 != null && String(t3) !== "") pageTitle = String(t3);
|
|
243520
|
+
} else if (dir.key === "description") {
|
|
243521
|
+
const d = dir.value;
|
|
243522
|
+
if (d != null) pageDescription = String(d);
|
|
243523
|
+
}
|
|
243183
243524
|
}
|
|
243184
243525
|
}
|
|
243185
243526
|
const pageCtx = createContext("ssr");
|
|
243186
243527
|
seedCtx(pageCtx);
|
|
243187
243528
|
try {
|
|
243188
|
-
pageCtx.stateVars["page"] = JSON.stringify({ title: pageTitle });
|
|
243529
|
+
pageCtx.stateVars["page"] = JSON.stringify({ title: pageTitle, description: pageDescription });
|
|
243189
243530
|
} catch {
|
|
243190
243531
|
}
|
|
243191
243532
|
{
|
|
@@ -243341,6 +243682,10 @@ function generate(program, stateVars, genOpts2) {
|
|
|
243341
243682
|
const startTime = performance.now();
|
|
243342
243683
|
const ctx = createContext("ssr");
|
|
243343
243684
|
if (stateVars) ctx.stateVars = stateVars;
|
|
243685
|
+
if (genOpts2?.imports) {
|
|
243686
|
+
ctx.imports = genOpts2.imports;
|
|
243687
|
+
setEvalBindings(genOpts2.imports);
|
|
243688
|
+
} else setEvalBindings({});
|
|
243344
243689
|
if (genOpts2 && genOpts2.scopedStyles === false) ctx.scopedStyles = false;
|
|
243345
243690
|
if (genOpts2?.scopeId) ctx.scopeId = genOpts2.scopeId;
|
|
243346
243691
|
if (genOpts2?.cssPrefix) ctx.cssPrefix = genOpts2.cssPrefix;
|
|
@@ -243425,6 +243770,7 @@ var init_vdom = __esm({
|
|
|
243425
243770
|
init_types4();
|
|
243426
243771
|
init_html2();
|
|
243427
243772
|
init_builtin_components();
|
|
243773
|
+
init_evaluate();
|
|
243428
243774
|
}
|
|
243429
243775
|
});
|
|
243430
243776
|
|
|
@@ -243765,6 +244111,7 @@ var init_codes = __esm({
|
|
|
243765
244111
|
TW095: { message: "Invalid for-loop iterable -- use {varName} or a valid comma-separated literal", severity: "error", category: "syntax" },
|
|
243766
244112
|
TW096: { message: "Unknown state variable in interpolation (renders empty)", severity: "warning", category: "semantic" },
|
|
243767
244113
|
TW097: { message: "while with a comparison renders its body ONCE at build time (state cannot mutate during SSR) -- use for loops for repetition", severity: "warning", category: "semantic" },
|
|
244114
|
+
TW098: { message: "Interpolation cannot be evaluated at build time -- it renders as its source text", severity: "warning", category: "semantic" },
|
|
243768
244115
|
// Server blocks (TW099-TW101)
|
|
243769
244116
|
TW099: { message: "Unknown server modifier (only ':defer' is supported)", severity: "error", category: "syntax" },
|
|
243770
244117
|
TW100: { message: "Expected '{' after 'server'", severity: "error", category: "syntax" },
|
|
@@ -243788,6 +244135,8 @@ var init_codes = __esm({
|
|
|
243788
244135
|
TW117: { message: "fetch() with a request-derived URL (SSRF lint)", severity: "warning", category: "semantic" },
|
|
243789
244136
|
TW118: { message: "A deferred server block cannot redirect() or notFound() -- the response has already begun", severity: "error", category: "semantic" },
|
|
243790
244137
|
TW119: { message: "A deferred server block cannot be used on a cached page -- cache { } serves one HTML to every request", severity: "error", category: "semantic" },
|
|
244138
|
+
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
244139
|
+
TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
|
|
243791
244140
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
243792
244141
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
243793
244142
|
// carries no code of its own.
|
|
@@ -243852,6 +244201,7 @@ function checkUnknownTags(program, filePath, diags) {
|
|
|
243852
244201
|
forEachNode(program, (node, ctx) => {
|
|
243853
244202
|
if (!isElement(node)) return;
|
|
243854
244203
|
if (node.tag[0] === node.tag[0]?.toUpperCase()) return;
|
|
244204
|
+
if (BUILTIN_COMPONENT_TAGS.has(node.tag)) return;
|
|
243855
244205
|
const parent = ctx?.parent;
|
|
243856
244206
|
if (parent && (parent.type === "Element" && typeof parent.tag === "string" && parent.tag[0] === parent.tag[0]?.toUpperCase() || parent.type === "Component")) return;
|
|
243857
244207
|
if (HTML_ELEMENTS2.has(node.tag.toLowerCase())) return;
|
|
@@ -244180,6 +244530,14 @@ function checkUnknownStateVars(program, filePath, diags) {
|
|
|
244180
244530
|
if (d && d.type === "ServerBlock" && Array.isArray(d.declaredNames)) {
|
|
244181
244531
|
for (const n of d.declaredNames) known.add(n);
|
|
244182
244532
|
}
|
|
244533
|
+
if (d && d.type === "ImportDirective" && !d.isTypeOnly) {
|
|
244534
|
+
if (d.defaultImport) known.add(String(d.defaultImport));
|
|
244535
|
+
if (d.namespaceImport) known.add(String(d.namespaceImport));
|
|
244536
|
+
for (const it of d.items ?? []) {
|
|
244537
|
+
const nm = String(it).split(/\s+as\s+/).pop()?.trim();
|
|
244538
|
+
if (nm) known.add(nm);
|
|
244539
|
+
}
|
|
244540
|
+
}
|
|
244183
244541
|
}
|
|
244184
244542
|
const texts = [];
|
|
244185
244543
|
forEachNode(program, (node) => {
|
|
@@ -244206,6 +244564,59 @@ function checkUnknownStateVars(program, filePath, diags) {
|
|
|
244206
244564
|
"null",
|
|
244207
244565
|
"undefined"
|
|
244208
244566
|
]);
|
|
244567
|
+
const EVALUABLE_METHODS = /* @__PURE__ */ new Set([
|
|
244568
|
+
"length",
|
|
244569
|
+
"toUpperCase",
|
|
244570
|
+
"toLowerCase",
|
|
244571
|
+
"trim",
|
|
244572
|
+
"trimStart",
|
|
244573
|
+
"trimEnd",
|
|
244574
|
+
"slice",
|
|
244575
|
+
"substring",
|
|
244576
|
+
"substr",
|
|
244577
|
+
"charAt",
|
|
244578
|
+
"at",
|
|
244579
|
+
"includes",
|
|
244580
|
+
"indexOf",
|
|
244581
|
+
"lastIndexOf",
|
|
244582
|
+
"startsWith",
|
|
244583
|
+
"endsWith",
|
|
244584
|
+
"replace",
|
|
244585
|
+
"replaceAll",
|
|
244586
|
+
"split",
|
|
244587
|
+
"join",
|
|
244588
|
+
"concat",
|
|
244589
|
+
"repeat",
|
|
244590
|
+
"padStart",
|
|
244591
|
+
"padEnd",
|
|
244592
|
+
"toString",
|
|
244593
|
+
"toFixed",
|
|
244594
|
+
"map",
|
|
244595
|
+
"filter",
|
|
244596
|
+
"find",
|
|
244597
|
+
"some",
|
|
244598
|
+
"every",
|
|
244599
|
+
"reduce",
|
|
244600
|
+
"sort",
|
|
244601
|
+
"reverse",
|
|
244602
|
+
"stringify",
|
|
244603
|
+
"parse",
|
|
244604
|
+
"keys",
|
|
244605
|
+
"values",
|
|
244606
|
+
"entries",
|
|
244607
|
+
"from",
|
|
244608
|
+
"isArray",
|
|
244609
|
+
"round",
|
|
244610
|
+
"floor",
|
|
244611
|
+
"ceil",
|
|
244612
|
+
"abs",
|
|
244613
|
+
"max",
|
|
244614
|
+
"min",
|
|
244615
|
+
"pow",
|
|
244616
|
+
"sqrt",
|
|
244617
|
+
"random",
|
|
244618
|
+
"now"
|
|
244619
|
+
]);
|
|
244209
244620
|
for (const node of texts) {
|
|
244210
244621
|
const text = String(node.value ?? "");
|
|
244211
244622
|
if (!text.includes("{")) continue;
|
|
@@ -244221,6 +244632,22 @@ function checkUnknownStateVars(program, filePath, diags) {
|
|
|
244221
244632
|
[`Declare it in the state block, or check the spelling`]
|
|
244222
244633
|
));
|
|
244223
244634
|
}
|
|
244635
|
+
for (const m of text.matchAll(/\{([^{}]+)\}/g)) {
|
|
244636
|
+
const expr = m[1].trim();
|
|
244637
|
+
if (/^[A-Za-z_$][\w$]*$/.test(expr)) continue;
|
|
244638
|
+
for (const c of expr.matchAll(/([A-Za-z_$][\w$]*)\s*\(/g)) {
|
|
244639
|
+
const fn = c[1];
|
|
244640
|
+
if (known.has(fn) || BUILTINS2.has(fn) || EVALUABLE_METHODS.has(fn)) continue;
|
|
244641
|
+
diags.push(createDiagnostic(
|
|
244642
|
+
"TW098",
|
|
244643
|
+
node.line,
|
|
244644
|
+
node.col,
|
|
244645
|
+
filePath,
|
|
244646
|
+
`{${expr}}`,
|
|
244647
|
+
[`Cannot evaluate this at build time -- it renders as its source. Check the name, or simplify the expression`]
|
|
244648
|
+
));
|
|
244649
|
+
}
|
|
244650
|
+
}
|
|
244224
244651
|
}
|
|
244225
244652
|
}
|
|
244226
244653
|
function checkWhileComparisons(program, filePath, diags) {
|
|
@@ -244253,7 +244680,28 @@ function checkDeprecatedImports(program, filePath, diags) {
|
|
|
244253
244680
|
}
|
|
244254
244681
|
}
|
|
244255
244682
|
}
|
|
244256
|
-
|
|
244683
|
+
function checkDuplicateDefaultSlots(program, filePath, diags) {
|
|
244684
|
+
let count = 0;
|
|
244685
|
+
let first = null;
|
|
244686
|
+
forEachNode(program, (node) => {
|
|
244687
|
+
if (!node || node.type !== "Slot") return;
|
|
244688
|
+
const name = String(node.name ?? "default");
|
|
244689
|
+
if (name !== "default") return;
|
|
244690
|
+
count++;
|
|
244691
|
+
if (!first) first = node;
|
|
244692
|
+
});
|
|
244693
|
+
if (count > 1 && first) {
|
|
244694
|
+
diags.push(createDiagnostic(
|
|
244695
|
+
"TW122",
|
|
244696
|
+
first.line ?? 1,
|
|
244697
|
+
first.col ?? 1,
|
|
244698
|
+
filePath,
|
|
244699
|
+
`${count} default slots`,
|
|
244700
|
+
["Keep one default slot -- a caller's default content has no defined destination with two"]
|
|
244701
|
+
));
|
|
244702
|
+
}
|
|
244703
|
+
}
|
|
244704
|
+
var HTML_ELEMENTS2, HTML_ATTRIBUTES2, GLOBAL_ATTRIBUTES2, CSS_PROPERTIES2, CSS_ALIASES2, EVENT_TYPES2, ARIA_ROLES2, ARIA_ATTRIBUTES2, BUILTIN_COMPONENT_TAGS, DEPRECATED_IMPORTS;
|
|
244257
244705
|
var init_rules = __esm({
|
|
244258
244706
|
"../../packages/compiler/tw/diagnostics/rules.ts"() {
|
|
244259
244707
|
init_visitors();
|
|
@@ -245117,6 +245565,7 @@ var init_rules = __esm({
|
|
|
245117
245565
|
"aria-valuenow",
|
|
245118
245566
|
"aria-valuetext"
|
|
245119
245567
|
]);
|
|
245568
|
+
BUILTIN_COMPONENT_TAGS = /* @__PURE__ */ new Set(["optImage", "twImage", "twLink", "twImg"]);
|
|
245120
245569
|
DEPRECATED_IMPORTS = [
|
|
245121
245570
|
{ source: "utils/string/transform", name: "toHex", replacement: "stringToHex", removal: "2.1.0" },
|
|
245122
245571
|
{ source: "utils/string/transform", name: "fromHex", replacement: "hexToString", removal: "2.1.0" },
|
|
@@ -245160,6 +245609,7 @@ function diagnose(program, filePath) {
|
|
|
245160
245609
|
checkLoopIterables(program, filePath, diagnostics);
|
|
245161
245610
|
checkUnknownStateVars(program, filePath, diagnostics);
|
|
245162
245611
|
checkWhileComparisons(program, filePath, diagnostics);
|
|
245612
|
+
checkDuplicateDefaultSlots(program, filePath, diagnostics);
|
|
245163
245613
|
return diagnostics;
|
|
245164
245614
|
}
|
|
245165
245615
|
var RuleEngine;
|
|
@@ -247516,6 +247966,28 @@ function lintSsrf(body) {
|
|
|
247516
247966
|
while (m = re.exec(body)) out.push("fetch(<dynamic url>)");
|
|
247517
247967
|
const concat = /fetch\s*\(\s*[^,)]*\b(params|query|headers|cookies)\b[^,)]*\+/g;
|
|
247518
247968
|
while (m = concat.exec(body)) out.push("fetch(<concatenated url>)");
|
|
247969
|
+
const TAINTED_ROOT = /\b(params|query|headers|cookies)\b/;
|
|
247970
|
+
const tainted = /* @__PURE__ */ new Set();
|
|
247971
|
+
for (let pass = 0; pass < 5; pass++) {
|
|
247972
|
+
let grew = false;
|
|
247973
|
+
const assign = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*([^;\n]+)/g;
|
|
247974
|
+
let a;
|
|
247975
|
+
while (a = assign.exec(body)) {
|
|
247976
|
+
const [, name, rhs] = a;
|
|
247977
|
+
if (tainted.has(name)) continue;
|
|
247978
|
+
const fromRoot = TAINTED_ROOT.test(rhs);
|
|
247979
|
+
const fromTainted = [...tainted].some((t3) => new RegExp("\\b" + t3 + "\\b").test(rhs));
|
|
247980
|
+
if (fromRoot || fromTainted) {
|
|
247981
|
+
tainted.add(name);
|
|
247982
|
+
grew = true;
|
|
247983
|
+
}
|
|
247984
|
+
}
|
|
247985
|
+
if (!grew) break;
|
|
247986
|
+
}
|
|
247987
|
+
for (const name of tainted) {
|
|
247988
|
+
const use = new RegExp("fetch\\s*\\(\\s*[^,)]*\\b" + name + "\\b[^,)]*[,)]", "g");
|
|
247989
|
+
if (use.test(body)) out.push("fetch(<request-derived url>)");
|
|
247990
|
+
}
|
|
247519
247991
|
return out;
|
|
247520
247992
|
}
|
|
247521
247993
|
var ts2, ServerSerializationError, MAX_DEPTH;
|
|
@@ -247618,6 +248090,36 @@ function serverStateCollisions(program) {
|
|
|
247618
248090
|
}
|
|
247619
248091
|
return out;
|
|
247620
248092
|
}
|
|
248093
|
+
function checkDeclarationConflicts(program, paramNames = []) {
|
|
248094
|
+
const out = [];
|
|
248095
|
+
const params = new Set(paramNames);
|
|
248096
|
+
const seen = /* @__PURE__ */ new Set();
|
|
248097
|
+
for (const d of program.directives ?? []) {
|
|
248098
|
+
if (d.type !== "StateDirective") continue;
|
|
248099
|
+
for (const decl of d.declarations ?? []) {
|
|
248100
|
+
const name = String(decl.name ?? "");
|
|
248101
|
+
if (!name) continue;
|
|
248102
|
+
if (params.has(name)) {
|
|
248103
|
+
out.push({
|
|
248104
|
+
code: "TW102",
|
|
248105
|
+
message: `state declares '${name}', which collides with the route param '${name}' -- the param overwrites the state value`,
|
|
248106
|
+
line: decl.line ?? d.line ?? 1,
|
|
248107
|
+
col: decl.col ?? d.col ?? 1
|
|
248108
|
+
});
|
|
248109
|
+
}
|
|
248110
|
+
if (seen.has(name)) {
|
|
248111
|
+
out.push({
|
|
248112
|
+
code: "TW121",
|
|
248113
|
+
message: `'${name}' is declared by more than one state { } block -- the earlier declaration wins and this one is dead`,
|
|
248114
|
+
line: decl.line ?? d.line ?? 1,
|
|
248115
|
+
col: decl.col ?? d.col ?? 1
|
|
248116
|
+
});
|
|
248117
|
+
}
|
|
248118
|
+
seen.add(name);
|
|
248119
|
+
}
|
|
248120
|
+
}
|
|
248121
|
+
return out;
|
|
248122
|
+
}
|
|
247621
248123
|
function serverRouteParamCollisions(blocks, paramNames) {
|
|
247622
248124
|
const params = new Set(paramNames);
|
|
247623
248125
|
const out = [];
|
|
@@ -247855,7 +248357,14 @@ function checkServerBlocks(program, opts = {}) {
|
|
|
247855
248357
|
const blocks = collectServerBlocks(program);
|
|
247856
248358
|
if (!blocks.length) return [];
|
|
247857
248359
|
const out = [];
|
|
247858
|
-
const push = (code, message, line, col) => out.push({
|
|
248360
|
+
const push = (code, message, line, col) => out.push({
|
|
248361
|
+
severity: ERROR_CODES[code]?.severity === "warning" ? "warning" : "error",
|
|
248362
|
+
code,
|
|
248363
|
+
message,
|
|
248364
|
+
line,
|
|
248365
|
+
col,
|
|
248366
|
+
category: "semantic"
|
|
248367
|
+
});
|
|
247859
248368
|
if (opts.isLayout) {
|
|
247860
248369
|
for (const b of blocks) push("TW105", "server blocks in layouts are not supported yet", b.line, b.col);
|
|
247861
248370
|
return out;
|
|
@@ -248033,6 +248542,7 @@ function parsePageCache(source) {
|
|
|
248033
248542
|
var ts3, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS;
|
|
248034
248543
|
var init_server_blocks = __esm({
|
|
248035
248544
|
"../../packages/compiler/tw/server-blocks/index.ts"() {
|
|
248545
|
+
init_codes();
|
|
248036
248546
|
init_serialize();
|
|
248037
248547
|
ts3 = __toESM(require_typescript(), 1);
|
|
248038
248548
|
REQUEST_IDENTIFIERS = /* @__PURE__ */ new Set(["headers", "cookies", "query", "params"]);
|
|
@@ -254753,6 +255263,7 @@ __export(tw_exports3, {
|
|
|
254753
255263
|
canonicalVaryQuery: () => canonicalVaryQuery,
|
|
254754
255264
|
charCode: () => charCode,
|
|
254755
255265
|
check: () => check,
|
|
255266
|
+
checkDeclarationConflicts: () => checkDeclarationConflicts,
|
|
254756
255267
|
checkServerBlocks: () => checkServerBlocks,
|
|
254757
255268
|
chunksToHTML: () => chunksToHTML,
|
|
254758
255269
|
clearComponentRegistry: () => clearComponentRegistry,
|
|
@@ -255429,7 +255940,8 @@ function genOpts(opts, scopeId) {
|
|
|
255429
255940
|
scopedStyles: opts?.compiler?.scopedStyles,
|
|
255430
255941
|
scopeId,
|
|
255431
255942
|
cssPrefix: opts?.cssPrefix,
|
|
255432
|
-
cssImportPaths: opts?.cssImportPaths
|
|
255943
|
+
cssImportPaths: opts?.cssImportPaths,
|
|
255944
|
+
imports: opts?.imports
|
|
255433
255945
|
};
|
|
255434
255946
|
}
|
|
255435
255947
|
function scopeIdFor(filePath) {
|
|
@@ -256881,7 +257393,8 @@ var init_tw8 = __esm({
|
|
|
256881
257393
|
}
|
|
256882
257394
|
async runHook(name, ctx, ...args) {
|
|
256883
257395
|
const results = await this.runHooks(name, ctx, ...args);
|
|
256884
|
-
|
|
257396
|
+
for (const r of results) if (r !== void 0) return r;
|
|
257397
|
+
return void 0;
|
|
256885
257398
|
}
|
|
256886
257399
|
// Value-chaining hook: each plugin receives the previous plugin's return
|
|
256887
257400
|
// value and may return a new one. The transform:* and optimize:asset hooks
|
|
@@ -257739,7 +258252,7 @@ __export(twm_rules_exports, {
|
|
|
257739
258252
|
isRuleDsl: () => isRuleDsl,
|
|
257740
258253
|
parseRules: () => parseRules
|
|
257741
258254
|
});
|
|
257742
|
-
import { createHmac, timingSafeEqual as
|
|
258255
|
+
import { createHmac as createHmac2, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
257743
258256
|
function isRuleDsl(source) {
|
|
257744
258257
|
const stripped = source.split("\n").map((l) => l.replace(/\/\/.*$/, "").trim()).filter((l) => l.length > 0).join("\n");
|
|
257745
258258
|
return stripped.startsWith('rule "') || stripped.startsWith("rule '");
|
|
@@ -257837,14 +258350,14 @@ function verifyJwt_hs256(token, secret) {
|
|
|
257837
258350
|
return false;
|
|
257838
258351
|
}
|
|
257839
258352
|
if (header?.alg !== "HS256") return false;
|
|
257840
|
-
const expected =
|
|
258353
|
+
const expected = createHmac2("sha256", secret).update(`${h3}.${p}`).digest();
|
|
257841
258354
|
let got;
|
|
257842
258355
|
try {
|
|
257843
258356
|
got = b64urlDecode(sig);
|
|
257844
258357
|
} catch {
|
|
257845
258358
|
return false;
|
|
257846
258359
|
}
|
|
257847
|
-
if (expected.length !== got.length || !
|
|
258360
|
+
if (expected.length !== got.length || !timingSafeEqual2(expected, got)) return false;
|
|
257848
258361
|
if (typeof payload?.exp === "number" && payload.exp * 1e3 < Date.now()) return false;
|
|
257849
258362
|
return true;
|
|
257850
258363
|
}
|
|
@@ -258529,6 +259042,18 @@ function findGlobalError(rootNode2) {
|
|
|
258529
259042
|
function findRootError(rootNode2) {
|
|
258530
259043
|
return (rootNode2.files || []).find((f) => f.type === "error");
|
|
258531
259044
|
}
|
|
259045
|
+
function findNearestNotFound(rootNode2, pathParts) {
|
|
259046
|
+
let found = (rootNode2.files || []).find((f) => f.type === "not-found");
|
|
259047
|
+
let node = rootNode2;
|
|
259048
|
+
for (const part of pathParts) {
|
|
259049
|
+
const child = (node.children || []).find((c) => c.segment === part);
|
|
259050
|
+
if (!child) break;
|
|
259051
|
+
const f = (child.files || []).find((x) => x.type === "not-found");
|
|
259052
|
+
if (f) found = f;
|
|
259053
|
+
node = child;
|
|
259054
|
+
}
|
|
259055
|
+
return found;
|
|
259056
|
+
}
|
|
258532
259057
|
function findRootNotFound(rootNode2) {
|
|
258533
259058
|
return rootNode2.files.find((f) => f.type === "not-found");
|
|
258534
259059
|
}
|
|
@@ -259330,6 +259855,26 @@ var init_render_pipeline = __esm({
|
|
|
259330
259855
|
};
|
|
259331
259856
|
}
|
|
259332
259857
|
console.error(`[tw] server block failed for ${pageFile}: ${err2?.message ?? err2}`);
|
|
259858
|
+
try {
|
|
259859
|
+
const errFile = ctx.error ?? findRootError(tree);
|
|
259860
|
+
if (errFile) {
|
|
259861
|
+
const compiled = this.compileFile(errFile);
|
|
259862
|
+
let eh = String(compiled.html || "");
|
|
259863
|
+
const em = eh.match(/<body[^>]*>([\s\S]*)<\/body>/i);
|
|
259864
|
+
eh = (em ? em[1] : eh).replace(/<\/?html[^>]*>/gi, "").replace(/<\/?body[^>]*>/gi, "");
|
|
259865
|
+
return {
|
|
259866
|
+
html: this.assembleHTML(eh, compiled.css, "", "Error"),
|
|
259867
|
+
css: "",
|
|
259868
|
+
js: "",
|
|
259869
|
+
status: 500,
|
|
259870
|
+
headers: { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "private, no-store" },
|
|
259871
|
+
fromCache: false,
|
|
259872
|
+
durationMs: 0,
|
|
259873
|
+
serverBlocks: true
|
|
259874
|
+
};
|
|
259875
|
+
}
|
|
259876
|
+
} catch {
|
|
259877
|
+
}
|
|
259333
259878
|
return {
|
|
259334
259879
|
html: "<!DOCTYPE html><html><head><title>Server Error</title></head><body><h1>Internal Server Error</h1></body></html>",
|
|
259335
259880
|
css: "",
|
|
@@ -259395,7 +259940,7 @@ var init_render_pipeline = __esm({
|
|
|
259395
259940
|
}
|
|
259396
259941
|
const match = matchRoute(tree, pathname);
|
|
259397
259942
|
if (!match) {
|
|
259398
|
-
const rootNotFound =
|
|
259943
|
+
const rootNotFound = findNearestNotFound(tree, pathname.split("/").filter(Boolean));
|
|
259399
259944
|
if (rootNotFound) {
|
|
259400
259945
|
const compiled = this.compileFile(rootNotFound);
|
|
259401
259946
|
let nf = String(compiled.html || "");
|
|
@@ -259461,6 +260006,7 @@ var init_render_pipeline = __esm({
|
|
|
259461
260006
|
}
|
|
259462
260007
|
let bodyHTML = pageCompiled.html;
|
|
259463
260008
|
let allCSS = pageCompiled.css;
|
|
260009
|
+
const parallelSlots = [];
|
|
259464
260010
|
try {
|
|
259465
260011
|
const parentNode = match?.node;
|
|
259466
260012
|
if (parentNode && Array.isArray(parentNode.children)) {
|
|
@@ -259471,9 +260017,7 @@ var init_render_pipeline = __esm({
|
|
|
259471
260017
|
const sbm = slotBody.match(/<body[^>]*>([\s\S]*)<\/body>/i);
|
|
259472
260018
|
if (sbm) slotBody = sbm[1];
|
|
259473
260019
|
slotBody = slotBody.replace(/<\/?html[^>]*>/gi, "").replace(/<\/?body[^>]*>/gi, "");
|
|
259474
|
-
|
|
259475
|
-
const slotRe = new RegExp(`<${comp}(s[^>]*)?>([sS]*?)</${comp}>|<${comp}(s[^>]*)?/>`, "gi");
|
|
259476
|
-
bodyHTML = bodyHTML.replace(slotRe, slotBody);
|
|
260020
|
+
parallelSlots.push({ comp: slotName.charAt(0).toUpperCase() + slotName.slice(1), body: slotBody });
|
|
259477
260021
|
if (slotCompiled.css) allCSS = slotCompiled.css + "\n" + allCSS;
|
|
259478
260022
|
}
|
|
259479
260023
|
}
|
|
@@ -259492,6 +260036,11 @@ var init_render_pipeline = __esm({
|
|
|
259492
260036
|
allJS = templateCompiled.js + "\n" + allJS;
|
|
259493
260037
|
bodyHTML = this.wrapInLayout(templateCompiled.html, bodyHTML);
|
|
259494
260038
|
}
|
|
260039
|
+
for (const { comp, body } of parallelSlots) {
|
|
260040
|
+
const slotRe = new RegExp(`<${comp}(\\s[^>]*)?>([\\s\\S]*?)<\\/${comp}>|<${comp}(\\s[^>]*)?/>`, "gi");
|
|
260041
|
+
bodyHTML = bodyHTML.replace(slotRe, body);
|
|
260042
|
+
bodyHTML = bodyHTML.replace(new RegExp(`<!--\\s*TW: unknown component '${comp}'[\\s\\S]*?-->`, "gi"), body);
|
|
260043
|
+
}
|
|
259495
260044
|
let layoutTitle;
|
|
259496
260045
|
const liftedParts = [];
|
|
259497
260046
|
{
|
|
@@ -259910,8 +260459,6 @@ ${bodyHTML}`;
|
|
|
259910
260459
|
};
|
|
259911
260460
|
let tags = "";
|
|
259912
260461
|
const description = pick2("description");
|
|
259913
|
-
if (description) tags += ` <meta name="description" content="${esc5(description)}">
|
|
259914
|
-
`;
|
|
259915
260462
|
const keywords = pick2("keywords");
|
|
259916
260463
|
if (keywords) tags += ` <meta name="keywords" content="${esc5(keywords)}">
|
|
259917
260464
|
`;
|
|
@@ -262093,6 +262640,7 @@ var init_static = __esm({
|
|
|
262093
262640
|
if (!existsSync21(filePath)) {
|
|
262094
262641
|
filePath = join26(this.root, safePath + ".html");
|
|
262095
262642
|
}
|
|
262643
|
+
let notFoundFallback = false;
|
|
262096
262644
|
if (!existsSync21(filePath)) {
|
|
262097
262645
|
filePath = join26(this.root, safePath, this.indexFile);
|
|
262098
262646
|
}
|
|
@@ -262104,6 +262652,7 @@ var init_static = __esm({
|
|
|
262104
262652
|
}
|
|
262105
262653
|
} else {
|
|
262106
262654
|
filePath = join26(this.root, "404.html");
|
|
262655
|
+
notFoundFallback = true;
|
|
262107
262656
|
if (!existsSync21(filePath)) {
|
|
262108
262657
|
return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
|
|
262109
262658
|
}
|
|
@@ -262171,12 +262720,12 @@ var init_static = __esm({
|
|
|
262171
262720
|
const gzHeaders = { ...headers, "Content-Encoding": "gzip", "Content-Length": String(gz.length), Vary: "Accept-Encoding" };
|
|
262172
262721
|
delete gzHeaders["Content-Length"];
|
|
262173
262722
|
if (this.lastModified) delete gzHeaders["Last-Modified"];
|
|
262174
|
-
return new Response(gz, { headers: gzHeaders });
|
|
262723
|
+
return new Response(gz, { headers: gzHeaders, status: notFoundFallback ? 404 : 200 });
|
|
262175
262724
|
}
|
|
262176
262725
|
} catch {
|
|
262177
262726
|
}
|
|
262178
262727
|
}
|
|
262179
|
-
return new Response(bytes, { headers });
|
|
262728
|
+
return new Response(bytes, { headers, status: notFoundFallback ? 404 : 200 });
|
|
262180
262729
|
}
|
|
262181
262730
|
/**
|
|
262182
262731
|
* Parse a `Range: bytes=...` header against a known content length.
|
|
@@ -262826,6 +263375,12 @@ var init_xss_detector = __esm({
|
|
|
262826
263375
|
{ name: "SQL comment", regex: /--\s/g, severity: "medium", recommendation: "Check for SQL comment injection" },
|
|
262827
263376
|
{ name: "Stacked queries", regex: /;\s*(SELECT|INSERT|UPDATE|DELETE|DROP|UNION)/gi, severity: "high", recommendation: "Prevent stacked queries" },
|
|
262828
263377
|
{ name: "UNION injection", regex: /UNION\s+SELECT/gi, severity: "critical", recommendation: "Filter UNION SELECT from user input" },
|
|
263378
|
+
// Comment-only injections (`admin'--`, `admin'#`, `admin'/*`): a quote
|
|
263379
|
+
// followed by a comment truncates the query and bypasses the login
|
|
263380
|
+
// check, with no OR/UNION for the other patterns to catch.
|
|
263381
|
+
{ name: "Comment-terminated injection", regex: /['"`]\s*(--|#|\/\*)/g, severity: "high", recommendation: "A quote followed by a comment truncates the query -- use parameterized queries" },
|
|
263382
|
+
// Parenthesised boolean injection: `') OR ('1'='1`.
|
|
263383
|
+
{ name: "Parenthesised boolean injection", regex: /['"`]?\s*\)\s*(OR|AND)\s*\(?\s*['"`]?\s*\d/i, severity: "high", recommendation: "Use parameterized queries instead of building boolean expressions" },
|
|
262829
263384
|
{ name: "Boolean-based injection", regex: /OR\s+1\s*=\s*1/gi, severity: "high", recommendation: "Use parameterized queries to prevent boolean injection" },
|
|
262830
263385
|
{ name: "Time-based injection", regex: /WAITFOR\s+DELAY/gi, severity: "high", recommendation: "Filter WAITFOR DELAY from user input" },
|
|
262831
263386
|
{ name: "DROP statement", regex: /DROP\s+(TABLE|DATABASE)/gi, severity: "critical", recommendation: "Prevent DROP statements in queries" },
|
|
@@ -263356,6 +263911,7 @@ var init_logger3 = __esm({
|
|
|
263356
263911
|
}
|
|
263357
263912
|
/** Records an audit event. */
|
|
263358
263913
|
log(event) {
|
|
263914
|
+
event = { type: "system", actor: "unknown", resource: "unknown", ...event };
|
|
263359
263915
|
const fullEvent = {
|
|
263360
263916
|
...event,
|
|
263361
263917
|
id: crypto.randomUUID(),
|
|
@@ -264372,6 +264928,13 @@ var FILE_SIGNATURES, DANGEROUS_EXTENSIONS, DANGEROUS_MIME_TYPES, ContentSecurity
|
|
|
264372
264928
|
var init_protector = __esm({
|
|
264373
264929
|
"../../packages/security/tw/content-security/protector.ts"() {
|
|
264374
264930
|
FILE_SIGNATURES = [
|
|
264931
|
+
// Executables and HTML: without these, content renamed to an image extension
|
|
264932
|
+
// had no detected type, the signature check was skipped, and the upload was
|
|
264933
|
+
// accepted as risk "low" -- the exact rename bypass the check exists for.
|
|
264934
|
+
{ ext: ["exe", "dll", "sys"], mime: "application/x-msdownload", signature: [77, 90] },
|
|
264935
|
+
{ ext: ["elf", "so", "bin"], mime: "application/x-executable", signature: [127, 69, 76, 70] },
|
|
264936
|
+
{ ext: ["html", "htm", "xhtml"], mime: "text/html", signature: [60, 104, 116, 109, 108] },
|
|
264937
|
+
{ ext: ["html", "htm"], mime: "text/html", signature: [60, 33, 68, 79, 67, 84, 89, 80, 69] },
|
|
264375
264938
|
{ ext: ["jpg", "jpeg"], mime: "image/jpeg", signature: [255, 216, 255] },
|
|
264376
264939
|
{ ext: ["png"], mime: "image/png", signature: [137, 80, 78, 71, 13, 10, 26, 10] },
|
|
264377
264940
|
{ ext: ["gif"], mime: "image/gif", signature: [71, 73, 70, 56] },
|
|
@@ -264423,10 +264986,39 @@ var init_protector = __esm({
|
|
|
264423
264986
|
".htpasswd",
|
|
264424
264987
|
".svg",
|
|
264425
264988
|
// Can contain JavaScript
|
|
264426
|
-
".xml"
|
|
264989
|
+
".xml",
|
|
264427
264990
|
// Can contain XXE
|
|
264991
|
+
// Active-content types the set used to let through while still blocking .svg
|
|
264992
|
+
// "because it can contain JavaScript" -- .html/.js are script-capable by
|
|
264993
|
+
// definition, so an accepted upload served from our own origin is stored XSS.
|
|
264994
|
+
".html",
|
|
264995
|
+
".htm",
|
|
264996
|
+
".xhtml",
|
|
264997
|
+
".shtml",
|
|
264998
|
+
".js",
|
|
264999
|
+
".mjs",
|
|
265000
|
+
".cjs",
|
|
265001
|
+
".jsx",
|
|
265002
|
+
".ts",
|
|
265003
|
+
".tsx",
|
|
265004
|
+
".mhtml",
|
|
265005
|
+
".hta",
|
|
265006
|
+
".jsp",
|
|
265007
|
+
".asp",
|
|
265008
|
+
".aspx",
|
|
265009
|
+
".cgi",
|
|
265010
|
+
".pl"
|
|
264428
265011
|
]);
|
|
264429
265012
|
DANGEROUS_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
265013
|
+
// Active-content types: they can carry script (svg, xhtml, xml) or be
|
|
265014
|
+
// rendered as a document (html, pdf). Blocking .svg by extension while
|
|
265015
|
+
// reporting isContentTypeSafe("image/svg+xml") === true was inconsistent.
|
|
265016
|
+
"image/svg+xml",
|
|
265017
|
+
"text/html",
|
|
265018
|
+
"application/xhtml+xml",
|
|
265019
|
+
"application/pdf",
|
|
265020
|
+
"text/xml",
|
|
265021
|
+
"application/xml",
|
|
264430
265022
|
"application/javascript",
|
|
264431
265023
|
"text/javascript",
|
|
264432
265024
|
"application/x-javascript",
|
|
@@ -264481,7 +265073,9 @@ var init_protector = __esm({
|
|
|
264481
265073
|
reason: "Empty file",
|
|
264482
265074
|
sanitizedFilename: sanitized,
|
|
264483
265075
|
detectedType: "unknown",
|
|
264484
|
-
risk
|
|
265076
|
+
// Unknown content is not low risk -- it is content whose type we could
|
|
265077
|
+
// not establish, which is what a rename bypass looks like.
|
|
265078
|
+
risk: "medium"
|
|
264485
265079
|
};
|
|
264486
265080
|
}
|
|
264487
265081
|
if (this.blockedExtensions.has(ext)) {
|
|
@@ -265644,6 +266238,7 @@ var init_nonce_manager = __esm({
|
|
|
265644
266238
|
validate(nonce) {
|
|
265645
266239
|
const entry = this.nonces.get(nonce);
|
|
265646
266240
|
if (!entry) return false;
|
|
266241
|
+
if (entry.used) return false;
|
|
265647
266242
|
if (Date.now() > entry.expiresAt) {
|
|
265648
266243
|
this.nonces.delete(nonce);
|
|
265649
266244
|
return false;
|
|
@@ -266436,7 +267031,15 @@ var init_token_manager = __esm({
|
|
|
266436
267031
|
rotateAfterUse;
|
|
266437
267032
|
maxTokens;
|
|
266438
267033
|
tokens = /* @__PURE__ */ new Map();
|
|
267034
|
+
/** Tokens this manager issued and already consumed. A rotated token is
|
|
267035
|
+
* deleted from `tokens`, so without this marker a replay found no entry and
|
|
267036
|
+
* fell through to the stateless branch, which accepted it -- defeating the
|
|
267037
|
+
* documented single-use guarantee of `rotateAfterUse`. */
|
|
267038
|
+
consumedTokens = /* @__PURE__ */ new Set();
|
|
266439
267039
|
constructor(options) {
|
|
267040
|
+
if (!options || typeof options.secret !== "string" || options.secret.length === 0) {
|
|
267041
|
+
throw new Error("createCSRFManager: options.secret is required (the HMAC key used to sign tokens)");
|
|
267042
|
+
}
|
|
266440
267043
|
this.secret = options.secret;
|
|
266441
267044
|
this.tokenLength = options.tokenLength ?? 32;
|
|
266442
267045
|
this.ttl = options.ttl ?? 36e5;
|
|
@@ -266536,12 +267139,16 @@ var init_token_manager = __esm({
|
|
|
266536
267139
|
}
|
|
266537
267140
|
entry.used = true;
|
|
266538
267141
|
if (this.rotateAfterUse) {
|
|
267142
|
+
this.consumedTokens.add(headerPart);
|
|
266539
267143
|
this.tokens.delete(headerPart);
|
|
266540
267144
|
const rotated = await this.generate(sessionId ?? void 0);
|
|
266541
267145
|
return { valid: true, rotated };
|
|
266542
267146
|
}
|
|
266543
267147
|
return { valid: true };
|
|
266544
267148
|
}
|
|
267149
|
+
if (this.consumedTokens.has(headerPart)) {
|
|
267150
|
+
return { valid: false, reason: "Token already used" };
|
|
267151
|
+
}
|
|
266545
267152
|
const expectedSig = await hmacSign3(
|
|
266546
267153
|
this.secret,
|
|
266547
267154
|
`${headerPart}.${sessionId ?? ""}`
|
|
@@ -272417,17 +273024,17 @@ async function hs256(payload, secret, maxAge) {
|
|
|
272417
273024
|
const header = { alg: "HS256", typ: "JWT" };
|
|
272418
273025
|
const body = { ...payload, iat: now, exp: now + maxAge };
|
|
272419
273026
|
const data = enc(header) + "." + enc(body);
|
|
272420
|
-
const { createHmac:
|
|
272421
|
-
const sig =
|
|
273027
|
+
const { createHmac: createHmac3 } = await import("node:crypto");
|
|
273028
|
+
const sig = createHmac3("sha256", secret).update(data).digest("base64url");
|
|
272422
273029
|
return data + "." + sig;
|
|
272423
273030
|
}
|
|
272424
273031
|
async function verifyHs256(token, secret) {
|
|
272425
273032
|
const parts = token.split(".");
|
|
272426
273033
|
if (parts.length !== 3) return null;
|
|
272427
|
-
const { createHmac:
|
|
272428
|
-
const expected =
|
|
273034
|
+
const { createHmac: createHmac3, timingSafeEqual: timingSafeEqual3 } = await import("node:crypto");
|
|
273035
|
+
const expected = createHmac3("sha256", secret).update(parts[0] + "." + parts[1]).digest("base64url");
|
|
272429
273036
|
const a = Buffer.from(expected), b = Buffer.from(parts[2]);
|
|
272430
|
-
if (a.length !== b.length || !
|
|
273037
|
+
if (a.length !== b.length || !timingSafeEqual3(a, b)) return null;
|
|
272431
273038
|
try {
|
|
272432
273039
|
const body = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
272433
273040
|
if (typeof body.exp === "number" && body.exp < Math.floor(Date.now() / 1e3)) return null;
|
|
@@ -272912,6 +273519,17 @@ var init_tw10 = __esm({
|
|
|
272912
273519
|
cfgIn.redirects = normalizedRedirects.filter(Boolean);
|
|
272913
273520
|
}
|
|
272914
273521
|
}
|
|
273522
|
+
if (Array.isArray(cfgIn.redirects)) {
|
|
273523
|
+
const seenFrom = /* @__PURE__ */ new Set();
|
|
273524
|
+
for (const r of cfgIn.redirects) {
|
|
273525
|
+
const from = r && typeof r.from === "string" ? r.from : null;
|
|
273526
|
+
if (!from) continue;
|
|
273527
|
+
if (seenFrom.has(from)) {
|
|
273528
|
+
console.warn("[tw] redirects: '" + from + "' is listed more than once -- the first entry wins, the later one never runs");
|
|
273529
|
+
}
|
|
273530
|
+
seenFrom.add(from);
|
|
273531
|
+
}
|
|
273532
|
+
}
|
|
272915
273533
|
if (cfgIn.headers && !Array.isArray(cfgIn.headers)) {
|
|
272916
273534
|
const entries = Object.entries(cfgIn.headers);
|
|
272917
273535
|
cfgIn.headers = entries.map(([source, headers]) => ({ source, headers }));
|
|
@@ -273732,6 +274350,19 @@ ${err2.stack ?? ""}`);
|
|
|
273732
274350
|
const isrLookupPath = pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname;
|
|
273733
274351
|
if (this.staticHandler && !this.isrRoutes.has(isrLookupPath)) {
|
|
273734
274352
|
let staticResponse = await this.staticHandler.serve(pathname, request);
|
|
274353
|
+
if (staticResponse.status !== 404) {
|
|
274354
|
+
const reqMethod = request.method.toUpperCase();
|
|
274355
|
+
const allow = "GET, HEAD, OPTIONS";
|
|
274356
|
+
if (reqMethod === "TRACE") {
|
|
274357
|
+
return new Response("Method Not Allowed", { status: 405, headers: { Allow: allow } });
|
|
274358
|
+
}
|
|
274359
|
+
if (reqMethod === "OPTIONS") {
|
|
274360
|
+
return new Response(null, { status: 204, headers: { Allow: allow } });
|
|
274361
|
+
}
|
|
274362
|
+
if (reqMethod !== "GET" && reqMethod !== "HEAD") {
|
|
274363
|
+
return new Response("Method Not Allowed", { status: 405, headers: { Allow: allow } });
|
|
274364
|
+
}
|
|
274365
|
+
}
|
|
273735
274366
|
if (staticResponse && this.cspEnabled() && (staticResponse.headers.get("content-type") || "").includes("text/html")) {
|
|
273736
274367
|
try {
|
|
273737
274368
|
let buf = Buffer.from(await staticResponse.arrayBuffer());
|
|
@@ -273876,6 +274507,32 @@ ${err2.stack ?? ""}`);
|
|
|
273876
274507
|
});
|
|
273877
274508
|
|
|
273878
274509
|
// ../../packages/runtime/tw/dependency-graph.ts
|
|
274510
|
+
function flushPendingSubs() {
|
|
274511
|
+
if (isFlushing || !pendingSubs) return;
|
|
274512
|
+
isFlushing = true;
|
|
274513
|
+
try {
|
|
274514
|
+
let guard = 0;
|
|
274515
|
+
while (pendingSubs && pendingSubs.size > 0 && guard++ < 1e5) {
|
|
274516
|
+
const batchOf = pendingSubs;
|
|
274517
|
+
pendingSubs = /* @__PURE__ */ new Set();
|
|
274518
|
+
for (const sub of batchOf) {
|
|
274519
|
+
try {
|
|
274520
|
+
sub();
|
|
274521
|
+
} catch (e) {
|
|
274522
|
+
console.error("[TW Reactivity] Signal subscriber error:", e);
|
|
274523
|
+
}
|
|
274524
|
+
}
|
|
274525
|
+
}
|
|
274526
|
+
} finally {
|
|
274527
|
+
isFlushing = false;
|
|
274528
|
+
pendingSubs = null;
|
|
274529
|
+
}
|
|
274530
|
+
}
|
|
274531
|
+
function enqueueSubs(subs) {
|
|
274532
|
+
if (!pendingSubs) pendingSubs = /* @__PURE__ */ new Set();
|
|
274533
|
+
for (const s of subs) pendingSubs.add(s);
|
|
274534
|
+
if (batchDepth === 0) flushPendingSubs();
|
|
274535
|
+
}
|
|
273879
274536
|
function startBatch() {
|
|
273880
274537
|
batchDepth++;
|
|
273881
274538
|
}
|
|
@@ -273885,13 +274542,7 @@ function endBatch() {
|
|
|
273885
274542
|
batchDepth = 0;
|
|
273886
274543
|
const effects = Array.from(batchedEffects);
|
|
273887
274544
|
batchedEffects.clear();
|
|
273888
|
-
|
|
273889
|
-
try {
|
|
273890
|
-
eff();
|
|
273891
|
-
} catch (e) {
|
|
273892
|
-
console.error("[TW Reactivity] Batch effect error:", e);
|
|
273893
|
-
}
|
|
273894
|
-
}
|
|
274545
|
+
enqueueSubs(effects);
|
|
273895
274546
|
}
|
|
273896
274547
|
}
|
|
273897
274548
|
function batch(fn) {
|
|
@@ -274073,12 +274724,14 @@ function isComputed(value) {
|
|
|
274073
274724
|
function createScope3() {
|
|
274074
274725
|
return new ReactiveScope();
|
|
274075
274726
|
}
|
|
274076
|
-
var currentEffect, batchDepth, batchedEffects, SignalImpl, ComputedImpl, watchEffect, currentCleanup, ReactiveScope;
|
|
274727
|
+
var currentEffect, batchDepth, batchedEffects, pendingSubs, isFlushing, SignalImpl, ComputedImpl, watchEffect, currentCleanup, ReactiveScope;
|
|
274077
274728
|
var init_dependency_graph = __esm({
|
|
274078
274729
|
"../../packages/runtime/tw/dependency-graph.ts"() {
|
|
274079
274730
|
currentEffect = null;
|
|
274080
274731
|
batchDepth = 0;
|
|
274081
274732
|
batchedEffects = /* @__PURE__ */ new Set();
|
|
274733
|
+
pendingSubs = null;
|
|
274734
|
+
isFlushing = false;
|
|
274082
274735
|
SignalImpl = class {
|
|
274083
274736
|
value;
|
|
274084
274737
|
subscribers = /* @__PURE__ */ new Set();
|
|
@@ -274097,19 +274750,9 @@ var init_dependency_graph = __esm({
|
|
|
274097
274750
|
if (this.equals(this.value, value)) return;
|
|
274098
274751
|
this.value = value;
|
|
274099
274752
|
if (batchDepth > 0) {
|
|
274100
|
-
for (const sub of this.subscribers)
|
|
274101
|
-
batchedEffects.add(sub);
|
|
274102
|
-
}
|
|
274103
|
-
} else {
|
|
274104
|
-
const subs = Array.from(this.subscribers);
|
|
274105
|
-
for (const sub of subs) {
|
|
274106
|
-
try {
|
|
274107
|
-
sub();
|
|
274108
|
-
} catch (e) {
|
|
274109
|
-
console.error("[TW Reactivity] Signal subscriber error:", e);
|
|
274110
|
-
}
|
|
274111
|
-
}
|
|
274753
|
+
for (const sub of this.subscribers) batchedEffects.add(sub);
|
|
274112
274754
|
}
|
|
274755
|
+
enqueueSubs(this.subscribers);
|
|
274113
274756
|
}
|
|
274114
274757
|
update(fn) {
|
|
274115
274758
|
this.set(fn(this.value));
|
|
@@ -274175,14 +274818,11 @@ var init_dependency_graph = __esm({
|
|
|
274175
274818
|
return this.cachedValue;
|
|
274176
274819
|
}
|
|
274177
274820
|
notify() {
|
|
274178
|
-
|
|
274179
|
-
|
|
274180
|
-
|
|
274181
|
-
sub();
|
|
274182
|
-
} catch (e) {
|
|
274183
|
-
console.error("[TW Reactivity] Computed subscriber error:", e);
|
|
274184
|
-
}
|
|
274821
|
+
if (batchDepth > 0) {
|
|
274822
|
+
for (const sub of this.subscribers) batchedEffects.add(sub);
|
|
274823
|
+
return;
|
|
274185
274824
|
}
|
|
274825
|
+
enqueueSubs(this.subscribers);
|
|
274186
274826
|
}
|
|
274187
274827
|
set(_value) {
|
|
274188
274828
|
throw new Error("Cannot set a computed signal");
|
|
@@ -277367,10 +278007,12 @@ var init_diff = __esm({
|
|
|
277367
278007
|
"../../packages/runtime/tw/diff.ts"() {
|
|
277368
278008
|
init_vdom2();
|
|
277369
278009
|
HTML_ESCAPE_MAP = {
|
|
277370
|
-
|
|
277371
|
-
|
|
277372
|
-
"
|
|
277373
|
-
|
|
278010
|
+
// These four mapped to THEMSELVES, so a <script> tag passed through
|
|
278011
|
+
// untouched -- only ' was actually escaped.
|
|
278012
|
+
"&": "&",
|
|
278013
|
+
"<": "<",
|
|
278014
|
+
">": ">",
|
|
278015
|
+
'"': """,
|
|
277374
278016
|
"'": "'"
|
|
277375
278017
|
};
|
|
277376
278018
|
HTML_ESCAPE_REGEX = /[&<>"']/g;
|
|
@@ -280900,8 +281542,19 @@ async function hydrateElementById(id, component, root = typeof document !== "und
|
|
|
280900
281542
|
);
|
|
280901
281543
|
}
|
|
280902
281544
|
function markForHydration(element, componentId, props) {
|
|
281545
|
+
if (!element || typeof componentId !== "string") return;
|
|
280903
281546
|
element.setAttribute(HYDRATE_ATTR, componentId);
|
|
280904
|
-
|
|
281547
|
+
let serialised = null;
|
|
281548
|
+
if (props && typeof props === "object") {
|
|
281549
|
+
try {
|
|
281550
|
+
serialised = JSON.stringify(props);
|
|
281551
|
+
} catch {
|
|
281552
|
+
serialised = null;
|
|
281553
|
+
}
|
|
281554
|
+
}
|
|
281555
|
+
if (serialised !== null && serialised !== void 0) {
|
|
281556
|
+
element.setAttribute("data-tw-props", serialised);
|
|
281557
|
+
}
|
|
280905
281558
|
}
|
|
280906
281559
|
function unmarkForHydration(element) {
|
|
280907
281560
|
element.removeAttribute(HYDRATE_ATTR);
|
|
@@ -284201,15 +284854,21 @@ function usePathname(opts) {
|
|
|
284201
284854
|
function matchPathPattern(path, pattern) {
|
|
284202
284855
|
const pSeg = path.split("/").filter(Boolean);
|
|
284203
284856
|
const tSeg = pattern.split("/").filter(Boolean);
|
|
284204
|
-
|
|
284857
|
+
const catchAllAt = tSeg.findIndex((t3) => t3.startsWith("[...") || t3.startsWith(":..."));
|
|
284858
|
+
if (catchAllAt === -1) {
|
|
284859
|
+
if (pSeg.length !== tSeg.length) return { matches: false, params: {}, score: 0 };
|
|
284860
|
+
} else if (pSeg.length < tSeg.length) {
|
|
284861
|
+
return { matches: false, params: {}, score: 0 };
|
|
284862
|
+
}
|
|
284205
284863
|
const params = {};
|
|
284206
284864
|
let literal = 0;
|
|
284207
284865
|
for (let i = 0; i < tSeg.length; i++) {
|
|
284208
284866
|
const t3 = tSeg[i];
|
|
284209
284867
|
const isParam = t3.startsWith("[") && t3.endsWith("]") || t3.startsWith(":");
|
|
284210
284868
|
if (isParam) {
|
|
284211
|
-
const name = t3.startsWith("[") ? t3.slice(1, -1).replace(
|
|
284212
|
-
|
|
284869
|
+
const name = t3.startsWith("[") ? t3.slice(1, -1).replace(/^\.\.\./, "") : t3.slice(1);
|
|
284870
|
+
const isCatchAll = t3.startsWith("[...") || t3.startsWith(":...");
|
|
284871
|
+
params[name] = isCatchAll ? pSeg.slice(i).map((seg) => decodeURIComponent(seg)).join("/") : decodeURIComponent(pSeg[i]);
|
|
284213
284872
|
} else if (t3 !== pSeg[i]) {
|
|
284214
284873
|
return { matches: false, params: {}, score: 0 };
|
|
284215
284874
|
} else {
|
|
@@ -285024,7 +285683,11 @@ function defineStore(idOrDefinition, maybeDefinition) {
|
|
|
285024
285683
|
const getterDeps = Object.values(reactiveState);
|
|
285025
285684
|
for (const key2 of Object.keys(getters)) {
|
|
285026
285685
|
const getter = getters[key2];
|
|
285027
|
-
getterValues[key2] = computed4(getterDeps,
|
|
285686
|
+
getterValues[key2] = computed4(getterDeps, () => {
|
|
285687
|
+
const snap = {};
|
|
285688
|
+
for (const k of Object.keys(reactiveState)) snap[k] = reactiveState[k].value;
|
|
285689
|
+
return getter.call(snap, snap);
|
|
285690
|
+
});
|
|
285028
285691
|
}
|
|
285029
285692
|
const subscribers = /* @__PURE__ */ new Set();
|
|
285030
285693
|
const actionListeners = /* @__PURE__ */ new Set();
|
|
@@ -285049,9 +285712,41 @@ function defineStore(idOrDefinition, maybeDefinition) {
|
|
|
285049
285712
|
return () => set.delete(cb);
|
|
285050
285713
|
}
|
|
285051
285714
|
};
|
|
285715
|
+
const MUTATORS = /* @__PURE__ */ new Set(["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"]);
|
|
285716
|
+
const tracking = /* @__PURE__ */ new WeakMap();
|
|
285717
|
+
const track2 = (value, prop) => {
|
|
285718
|
+
if (value === null || typeof value !== "object") return value;
|
|
285719
|
+
const existing2 = tracking.get(value);
|
|
285720
|
+
if (existing2) return existing2;
|
|
285721
|
+
const wrapped = new Proxy(value, {
|
|
285722
|
+
get(t3, key2, recv) {
|
|
285723
|
+
const v = Reflect.get(t3, key2, recv);
|
|
285724
|
+
if (typeof v === "function" && MUTATORS.has(String(key2))) {
|
|
285725
|
+
return (...args) => {
|
|
285726
|
+
const out = v.apply(t3, args);
|
|
285727
|
+
reactiveState[prop]?.touch();
|
|
285728
|
+
return out;
|
|
285729
|
+
};
|
|
285730
|
+
}
|
|
285731
|
+
return v;
|
|
285732
|
+
},
|
|
285733
|
+
set(t3, key2, v) {
|
|
285734
|
+
const ok3 = Reflect.set(t3, key2, v);
|
|
285735
|
+
reactiveState[prop]?.touch();
|
|
285736
|
+
return ok3;
|
|
285737
|
+
},
|
|
285738
|
+
deleteProperty(t3, key2) {
|
|
285739
|
+
const ok3 = Reflect.deleteProperty(t3, key2);
|
|
285740
|
+
reactiveState[prop]?.touch();
|
|
285741
|
+
return ok3;
|
|
285742
|
+
}
|
|
285743
|
+
});
|
|
285744
|
+
tracking.set(value, wrapped);
|
|
285745
|
+
return wrapped;
|
|
285746
|
+
};
|
|
285052
285747
|
const stateProxy = new Proxy({}, {
|
|
285053
285748
|
get(_target, prop) {
|
|
285054
|
-
return reactiveState[prop]?.value;
|
|
285749
|
+
return track2(reactiveState[prop]?.value, prop);
|
|
285055
285750
|
},
|
|
285056
285751
|
set(_target, prop, value) {
|
|
285057
285752
|
if (reactiveState[prop]) {
|
|
@@ -285067,7 +285762,7 @@ function defineStore(idOrDefinition, maybeDefinition) {
|
|
|
285067
285762
|
const fn = actions[key2];
|
|
285068
285763
|
boundActions[key2] = (...args) => {
|
|
285069
285764
|
actionListeners.forEach((cb) => cb({ name: key2, args }));
|
|
285070
|
-
return fn.call(
|
|
285765
|
+
return fn.call(stateProxy, stateProxy, ...args);
|
|
285071
285766
|
};
|
|
285072
285767
|
}
|
|
285073
285768
|
for (const rv of Object.values(reactiveState)) {
|
|
@@ -285172,6 +285867,14 @@ var init_store = __esm({
|
|
|
285172
285867
|
update(updater) {
|
|
285173
285868
|
this.set(updater(this._value));
|
|
285174
285869
|
}
|
|
285870
|
+
/**
|
|
285871
|
+
* Re-notify subscribers without replacing the value. An array or object that
|
|
285872
|
+
* was mutated in place (`this.items.push(x)`) has the same identity, so
|
|
285873
|
+
* `set()` short-circuits and nothing downstream hears about it.
|
|
285874
|
+
*/
|
|
285875
|
+
touch() {
|
|
285876
|
+
this._notify();
|
|
285877
|
+
}
|
|
285175
285878
|
subscribe(listener) {
|
|
285176
285879
|
this._listeners.add(listener);
|
|
285177
285880
|
return () => {
|
|
@@ -285179,9 +285882,10 @@ var init_store = __esm({
|
|
|
285179
285882
|
};
|
|
285180
285883
|
}
|
|
285181
285884
|
_notify() {
|
|
285885
|
+
const current2 = this.value ?? this._value;
|
|
285182
285886
|
for (const l of this._listeners) {
|
|
285183
285887
|
try {
|
|
285184
|
-
l();
|
|
285888
|
+
l(current2);
|
|
285185
285889
|
} catch {
|
|
285186
285890
|
}
|
|
285187
285891
|
}
|
|
@@ -286187,7 +286891,8 @@ var init_virtual_list = __esm({
|
|
|
286187
286891
|
return this.container.scrollTop;
|
|
286188
286892
|
}
|
|
286189
286893
|
getFirstVisibleIndex() {
|
|
286190
|
-
|
|
286894
|
+
const last = Math.max(0, (this.options?.itemCount ?? 0) - 1);
|
|
286895
|
+
return Math.min(Math.max(this.visibleRange.start, 0), last);
|
|
286191
286896
|
}
|
|
286192
286897
|
getLastVisibleIndex() {
|
|
286193
286898
|
return this.visibleRange.end;
|
|
@@ -289179,7 +289884,7 @@ __export(server_boundary_exports, {
|
|
|
289179
289884
|
walkClientGraph: () => walkClientGraph
|
|
289180
289885
|
});
|
|
289181
289886
|
import { readFileSync as readFileSync17, existsSync as existsSync25 } from "node:fs";
|
|
289182
|
-
import { dirname as dirname12, resolve as resolve7, extname as extname9, relative as relative2 } from "node:path";
|
|
289887
|
+
import { dirname as dirname12, resolve as resolve7, extname as extname9, relative as relative2, sep as sep2 } from "node:path";
|
|
289183
289888
|
function collectModuleImports(src) {
|
|
289184
289889
|
const out = [];
|
|
289185
289890
|
if (!src.trim()) return out;
|
|
@@ -289216,7 +289921,7 @@ function matchesOnlyPackages(spec, only) {
|
|
|
289216
289921
|
return false;
|
|
289217
289922
|
}
|
|
289218
289923
|
function isServerOnlyByName(spec) {
|
|
289219
|
-
return /\.server\.(ts|js)
|
|
289924
|
+
return /\.server(\.(ts|js|mjs|cjs))?$/.test(spec);
|
|
289220
289925
|
}
|
|
289221
289926
|
function packageName(spec) {
|
|
289222
289927
|
if (spec.startsWith("@")) return spec.split("/").slice(0, 2).join("/");
|
|
@@ -289247,8 +289952,13 @@ function walkClientGraph(entryFiles, opts = {}) {
|
|
|
289247
289952
|
const spec = imp.specifier;
|
|
289248
289953
|
let layer = null;
|
|
289249
289954
|
if (isServerOnlyByName(spec)) layer = "name";
|
|
289250
|
-
else if (isLocal(spec))
|
|
289251
|
-
|
|
289955
|
+
else if (isLocal(spec)) {
|
|
289956
|
+
const resolvedLocal = resolveLocal(spec, dirname12(file));
|
|
289957
|
+
const libRoot = opts.rootDir ? resolve7(opts.rootDir, "lib") : null;
|
|
289958
|
+
if (resolvedLocal && libRoot && (resolvedLocal === libRoot || resolvedLocal.startsWith(libRoot + sep2))) {
|
|
289959
|
+
layer = "lib";
|
|
289960
|
+
}
|
|
289961
|
+
} else if (spec === SERVER_ONLY_MARKER) layer = "L4";
|
|
289252
289962
|
else if (spec.startsWith("node:") || DENY_NODE_BUILTINS.has(spec)) layer = "L1";
|
|
289253
289963
|
else if (matchesOnlyPackages(spec, only)) layer = "L3";
|
|
289254
289964
|
else if (DEFAULT_DENY_PACKAGES.includes(packageName(spec))) layer = "L2";
|
|
@@ -289490,8 +290200,6 @@ function buildMetaTagsFromSource(source) {
|
|
|
289490
290200
|
};
|
|
289491
290201
|
let tags = "";
|
|
289492
290202
|
const description = pick2("description");
|
|
289493
|
-
if (description) tags += ` <meta name="description" content="${esc5(description)}">
|
|
289494
|
-
`;
|
|
289495
290203
|
const keywords = pick2("keywords");
|
|
289496
290204
|
if (keywords) tags += ` <meta name="keywords" content="${esc5(keywords)}">
|
|
289497
290205
|
`;
|
|
@@ -290006,6 +290714,30 @@ async function buildCommand() {
|
|
|
290006
290714
|
console.log(" index.tw wins this route -- delete one of them");
|
|
290007
290715
|
}
|
|
290008
290716
|
}
|
|
290717
|
+
{
|
|
290718
|
+
const shapes = /* @__PURE__ */ new Map();
|
|
290719
|
+
for (const pf of pageFiles) {
|
|
290720
|
+
const dir = dirname13(pf);
|
|
290721
|
+
if (existsSync26(join30(dir, "page.twm"))) {
|
|
290722
|
+
console.log(" \x1B[33m!\x1B[0m " + dir.replace(homeDir, "").replace(/^\//, "") + "/ has BOTH page.tw and page.twm");
|
|
290723
|
+
console.log(" the .twm handler never runs -- delete one of them");
|
|
290724
|
+
}
|
|
290725
|
+
const rel = pf.replace(homeDir, "").replace(/^\//, "");
|
|
290726
|
+
const segs = rel.split("/").slice(0, -1).filter((seg) => !/^\(.*\)$/.test(seg));
|
|
290727
|
+
const parent = segs.slice(0, -1).join("/");
|
|
290728
|
+
const shape = segs.map((seg) => seg.startsWith("[") ? "[*]" : seg).join("/");
|
|
290729
|
+
if (!segs.length) continue;
|
|
290730
|
+
const key2 = parent + "\0" + shape;
|
|
290731
|
+
const prev = shapes.get(key2);
|
|
290732
|
+
if (prev && prev !== dir) {
|
|
290733
|
+
console.log(" \x1B[31m\u2717\x1B[0m two dynamic routes match the same URL: " + prev.replace(homeDir, "") + " and " + dir.replace(homeDir, ""));
|
|
290734
|
+
console.log(" rename one of the params -- only one of these pages can ever render");
|
|
290735
|
+
errorCount++;
|
|
290736
|
+
} else if (!prev) {
|
|
290737
|
+
shapes.set(key2, dir);
|
|
290738
|
+
}
|
|
290739
|
+
}
|
|
290740
|
+
}
|
|
290009
290741
|
begin("compile", pageFiles.length);
|
|
290010
290742
|
await runBuildHook("pages:discover", { pages: pageFiles, rootDir });
|
|
290011
290743
|
await runBuildHook("before:build", { pages: pageFiles, rootDir, outDir });
|
|
@@ -290071,6 +290803,16 @@ async function buildCommand() {
|
|
|
290071
290803
|
}
|
|
290072
290804
|
}
|
|
290073
290805
|
const renderMode = extractRenderMode2(readFileSync18(pageFile, "utf8"));
|
|
290806
|
+
try {
|
|
290807
|
+
const { parseWithDetails: _pd, checkDeclarationConflicts: checkDeclarationConflicts2 } = _compilerMod;
|
|
290808
|
+
const _prog = _pd(readFileSync18(pageFile, "utf-8"), { filePath: pageFile, cache: false }).program;
|
|
290809
|
+
const _paramNames = routePath.split("/").filter((seg) => seg.startsWith("[")).map((seg) => seg.replace(/^\[+/, "").replace(/\]+$/, "").replace(/^\.\.\./, ""));
|
|
290810
|
+
for (const c of checkDeclarationConflicts2(_prog, _paramNames)) {
|
|
290811
|
+
console.error(" \x1B[33m!\x1B[0m " + pageFile.replace(rootDir + "/", "") + ":" + c.line + " " + c.code + " " + c.message);
|
|
290812
|
+
errorCount++;
|
|
290813
|
+
}
|
|
290814
|
+
} catch {
|
|
290815
|
+
}
|
|
290074
290816
|
{
|
|
290075
290817
|
const pageSrc = readFileSync18(pageFile, "utf-8");
|
|
290076
290818
|
const { extractCacheDirective: extractCacheDirective2, resolveCache: resolveCache2 } = await Promise.resolve().then(() => (init_tw(), tw_exports));
|
|
@@ -290108,6 +290850,7 @@ async function buildCommand() {
|
|
|
290108
290850
|
if ((renderMode === "ssr" || renderMode === "stream") && !hasExplicitParams) {
|
|
290109
290851
|
requestRenderedCount++;
|
|
290110
290852
|
console.log(" \x1B[36m~\x1B[0m " + routePath + " [" + renderMode + ": rendered at request time]");
|
|
290853
|
+
isrRoutes.set(routePath === "" ? "/" : routePath, 0);
|
|
290111
290854
|
try {
|
|
290112
290855
|
const src = readFileSync18(pageFile, "utf-8");
|
|
290113
290856
|
if (serverBlocksOn) {
|
|
@@ -290124,8 +290867,11 @@ async function buildCommand() {
|
|
|
290124
290867
|
hasVary: extractVary2(src).length > 0,
|
|
290125
290868
|
referenced: collectReferencedNames3(src)
|
|
290126
290869
|
});
|
|
290127
|
-
for (const p of problems)
|
|
290128
|
-
|
|
290870
|
+
for (const p of problems) {
|
|
290871
|
+
const warn2 = p.severity === "warning";
|
|
290872
|
+
console.error(" " + (warn2 ? "\x1B[33m!\x1B[0m" : "\x1B[31m\u2717\x1B[0m") + " " + pageFile.replace(rootDir + "/", "") + ":" + p.line + " " + p.code + " " + p.message);
|
|
290873
|
+
if (!warn2) errorCount++;
|
|
290874
|
+
}
|
|
290129
290875
|
}
|
|
290130
290876
|
} catch {
|
|
290131
290877
|
}
|
|
@@ -290208,7 +290954,30 @@ async function buildCommand() {
|
|
|
290208
290954
|
}
|
|
290209
290955
|
}
|
|
290210
290956
|
const scopeVars = { ...paramSet, params: paramSet, ...serverVars };
|
|
290211
|
-
|
|
290957
|
+
let pageImports = {};
|
|
290958
|
+
try {
|
|
290959
|
+
const { twImportTs: twImportTs2 } = await Promise.resolve().then(() => (init_node_import(), node_import_exports));
|
|
290960
|
+
const { dirname: dirname17, resolve: resolvePath } = await import("node:path");
|
|
290961
|
+
const parseFn = _compilerMod.parseWithDetails;
|
|
290962
|
+
const parsed = parseFn(source, pageFile);
|
|
290963
|
+
const prog = parsed?.program ?? parsed?.ast;
|
|
290964
|
+
for (const d of prog?.directives ?? []) {
|
|
290965
|
+
if (d?.type !== "ImportDirective" || !d.source || d.isTypeOnly) continue;
|
|
290966
|
+
const spec = String(d.source);
|
|
290967
|
+
if (!(spec.startsWith("./") || spec.startsWith("../") || spec.startsWith("@./"))) continue;
|
|
290968
|
+
const abs = spec.startsWith("@./") ? resolvePath(rootDir, spec.slice(3)) : resolvePath(dirname17(pageFile), spec);
|
|
290969
|
+
const mod = await twImportTs2(abs);
|
|
290970
|
+
if (d.namespaceImport) pageImports[d.namespaceImport] = mod;
|
|
290971
|
+
if (d.defaultImport) pageImports[d.defaultImport] = mod?.default ?? mod;
|
|
290972
|
+
for (const it of d.items ?? []) {
|
|
290973
|
+
const name = String(it).split(/\s+as\s+/).pop()?.trim();
|
|
290974
|
+
if (name && mod && name in mod) pageImports[name] = mod[name];
|
|
290975
|
+
}
|
|
290976
|
+
}
|
|
290977
|
+
} catch (e) {
|
|
290978
|
+
if (process.env.TW_DEBUG === "1") console.error("[tw] page imports failed:", e?.message ?? e);
|
|
290979
|
+
}
|
|
290980
|
+
const result = _compileSync(source, { filePath: pageFile, stateVars: scopeVars, imports: pageImports, ...compilePassOpts() });
|
|
290212
290981
|
{
|
|
290213
290982
|
const used = /* @__PURE__ */ new Set();
|
|
290214
290983
|
collectComponentUsages(result.ast, used);
|
|
@@ -290431,10 +291200,6 @@ async function buildCommand() {
|
|
|
290431
291200
|
apiCount++;
|
|
290432
291201
|
}
|
|
290433
291202
|
}
|
|
290434
|
-
if (existsSync26(libDir)) {
|
|
290435
|
-
copyDir2(libDir, join30(outDir, "lib"));
|
|
290436
|
-
console.log(" \x1B[32mOK\x1B[0m lib/");
|
|
290437
|
-
}
|
|
290438
291203
|
if (existsSync26(publicDir)) {
|
|
290439
291204
|
copyDir2(publicDir, outDir);
|
|
290440
291205
|
console.log(" \x1B[32mOK\x1B[0m public/");
|
|
@@ -290452,6 +291217,10 @@ async function buildCommand() {
|
|
|
290452
291217
|
}
|
|
290453
291218
|
process.exit(1);
|
|
290454
291219
|
}
|
|
291220
|
+
if (existsSync26(libDir)) {
|
|
291221
|
+
copyDir2(libDir, join30(outDir, "lib"));
|
|
291222
|
+
console.log(" \x1B[32mOK\x1B[0m lib/");
|
|
291223
|
+
}
|
|
290455
291224
|
if (clientChunkUrls.size > 0) {
|
|
290456
291225
|
console.log(" \x1B[36m\u26A1\x1B[0m client modules: " + clientChunkUrls.size + " shared chunk" + (clientChunkUrls.size === 1 ? "" : "s") + " (content-hashed, tree-shaken)");
|
|
290457
291226
|
}
|
|
@@ -293598,10 +294367,10 @@ if (typeof globalThis.Bun === "undefined") {
|
|
|
293598
294367
|
const parts = bodyStr.split(boundary);
|
|
293599
294368
|
for (let i = 1; i < parts.length - 1; i++) {
|
|
293600
294369
|
const raw = parts[i];
|
|
293601
|
-
const
|
|
293602
|
-
if (
|
|
293603
|
-
const head = raw.slice(0,
|
|
293604
|
-
let data = raw.slice(
|
|
294370
|
+
const sep3 = raw.indexOf("\r\n\r\n");
|
|
294371
|
+
if (sep3 < 0) continue;
|
|
294372
|
+
const head = raw.slice(0, sep3);
|
|
294373
|
+
let data = raw.slice(sep3 + 4);
|
|
293605
294374
|
if (data.endsWith("\r\n")) data = data.slice(0, -2);
|
|
293606
294375
|
const nameM = /name="([^"]*)"/.exec(head);
|
|
293607
294376
|
if (!nameM) continue;
|
|
@@ -293906,7 +294675,7 @@ async function createPackageJson(dir, name) {
|
|
|
293906
294675
|
ship: "tw ship"
|
|
293907
294676
|
},
|
|
293908
294677
|
dependencies: {
|
|
293909
|
-
"tw-framework": "^2.0.
|
|
294678
|
+
"tw-framework": "^2.0.2"
|
|
293910
294679
|
},
|
|
293911
294680
|
devDependencies: {
|
|
293912
294681
|
typescript: "^5.4.0",
|
|
@@ -293993,7 +294762,7 @@ dist/
|
|
|
293993
294762
|
async function createReadme(dir, name) {
|
|
293994
294763
|
const content = `# ${name}
|
|
293995
294764
|
|
|
293996
|
-
Built with TW Framework 2.0.
|
|
294765
|
+
Built with TW Framework 2.0.2.
|
|
293997
294766
|
|
|
293998
294767
|
## Getting Started
|
|
293999
294768
|
|
|
@@ -295685,7 +296454,31 @@ async function devCommand() {
|
|
|
295685
296454
|
try {
|
|
295686
296455
|
const source = readFileSync19(twFile, "utf-8");
|
|
295687
296456
|
if (typeof beginCssRouteCapture2 === "function") beginCssRouteCapture2(path);
|
|
295688
|
-
|
|
296457
|
+
let result = compileSync3(source, { filePath: twFile, stateVars: resolved.params });
|
|
296458
|
+
try {
|
|
296459
|
+
const _c = await Promise.resolve().then(() => (init_tw7(), tw_exports3));
|
|
296460
|
+
const blocks = _c.collectServerBlocks(result.ast);
|
|
296461
|
+
if (blocks.length) {
|
|
296462
|
+
const values = await _c.executeServerBlocks(blocks.filter((b) => !b.deferred), { label: twFile });
|
|
296463
|
+
if (values && Object.keys(values).length) {
|
|
296464
|
+
result = compileSync3(source, { filePath: twFile, stateVars: { ...resolved.params, ...values } });
|
|
296465
|
+
}
|
|
296466
|
+
}
|
|
296467
|
+
} catch (e) {
|
|
296468
|
+
console.log(" -> 500 Error (server block): " + (e?.message ?? e));
|
|
296469
|
+
if (devOpts?.overlay === false) {
|
|
296470
|
+
return new Response(
|
|
296471
|
+
"500 - Server Error\n\n" + (e?.message ?? String(e)),
|
|
296472
|
+
{ status: 500, headers: { "Content-Type": "text/plain; charset=utf-8" } }
|
|
296473
|
+
);
|
|
296474
|
+
}
|
|
296475
|
+
return new Response(devErrorPage({
|
|
296476
|
+
title: "Server Error",
|
|
296477
|
+
message: e?.message ?? String(e),
|
|
296478
|
+
stack: e?.stack,
|
|
296479
|
+
file: twFile
|
|
296480
|
+
}), { status: 500, headers: { "Content-Type": "text/html; charset=utf-8" } });
|
|
296481
|
+
}
|
|
295689
296482
|
let html = result.html;
|
|
295690
296483
|
const pageDir = twFile.substring(0, twFile.lastIndexOf("/"));
|
|
295691
296484
|
const chain2 = [];
|
|
@@ -296511,7 +297304,7 @@ function ensureTestingShim(rootDir) {
|
|
|
296511
297304
|
if (existsSync32(marker)) return;
|
|
296512
297305
|
const { mkdirSync: mkdirSync12, writeFileSync: writeFileSync14 } = _require("node:fs");
|
|
296513
297306
|
mkdirSync12(join37(shimPkgDir, "tw"), { recursive: true });
|
|
296514
|
-
writeFileSync14(marker, JSON.stringify({ name: "@tw/server", version: "2.0.
|
|
297307
|
+
writeFileSync14(marker, JSON.stringify({ name: "@tw/server", version: "2.0.2", private: true }, null, 2));
|
|
296515
297308
|
let testingBundle = null;
|
|
296516
297309
|
try {
|
|
296517
297310
|
const here = new URL(".", import.meta.url).pathname;
|
|
@@ -297408,7 +298201,7 @@ import { join as join42 } from "node:path";
|
|
|
297408
298201
|
function cliVersion() {
|
|
297409
298202
|
try {
|
|
297410
298203
|
const bd = globalThis.__TW_BUNDLE_DIR;
|
|
297411
|
-
const pj = bd ? join42(bd, "..", "package.json") : new URL("
|
|
298204
|
+
const pj = bd ? join42(bd, "..", "package.json") : new URL("../package.json", import.meta.url).pathname;
|
|
297412
298205
|
return JSON.parse(readFileSync26(pj, "utf-8")).version ?? "0.0.0";
|
|
297413
298206
|
} catch {
|
|
297414
298207
|
return "0.0.0";
|
|
@@ -297517,7 +298310,20 @@ async function run() {
|
|
|
297517
298310
|
console.log(` ${colors.bold("tw")} ${colors.cyan(`v${VERSION2}`)}`);
|
|
297518
298311
|
return;
|
|
297519
298312
|
}
|
|
297520
|
-
|
|
298313
|
+
let handler = commands[parsed.command];
|
|
298314
|
+
if (!handler) {
|
|
298315
|
+
try {
|
|
298316
|
+
const { loadPlugins: loadPlugins2 } = await Promise.resolve().then(() => (init_tw8(), tw_exports4));
|
|
298317
|
+
const pm = await loadPlugins2(process.cwd());
|
|
298318
|
+
const cmd = pm?.getCommands?.()[parsed.command];
|
|
298319
|
+
if (typeof cmd === "function") {
|
|
298320
|
+
handler = async () => {
|
|
298321
|
+
await cmd(process.argv.slice(3));
|
|
298322
|
+
};
|
|
298323
|
+
}
|
|
298324
|
+
} catch {
|
|
298325
|
+
}
|
|
298326
|
+
}
|
|
297521
298327
|
if (!handler) {
|
|
297522
298328
|
console.error(` ${colors.red("?")} Unknown command: ${parsed.command}`);
|
|
297523
298329
|
console.log("\n" + helpText);
|