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-server.mjs
CHANGED
|
@@ -6908,20 +6908,39 @@ function sha12(data) {
|
|
|
6908
6908
|
async function md52(data) {
|
|
6909
6909
|
return hashWithWebCrypto("md5", data);
|
|
6910
6910
|
}
|
|
6911
|
+
function webcryptoHashName(algorithm) {
|
|
6912
|
+
const key2 = String(algorithm).toLowerCase().replace(/[-_]/g, "");
|
|
6913
|
+
const map2 = {
|
|
6914
|
+
md5: "MD5",
|
|
6915
|
+
sha1: "SHA-1",
|
|
6916
|
+
sha224: "SHA-224",
|
|
6917
|
+
sha256: "SHA-256",
|
|
6918
|
+
sha384: "SHA-384",
|
|
6919
|
+
sha512: "SHA-512"
|
|
6920
|
+
};
|
|
6921
|
+
return map2[key2] ?? algorithm;
|
|
6922
|
+
}
|
|
6911
6923
|
async function hmac2(data, key2, algorithm = "sha256") {
|
|
6912
6924
|
const encoder2 = new TextEncoder();
|
|
6913
6925
|
const keyData = encoder2.encode(key2);
|
|
6914
6926
|
const messageData = encoder2.encode(data);
|
|
6915
|
-
const cryptoKey = await crypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: algorithm }, false, ["sign"]);
|
|
6927
|
+
const cryptoKey = await crypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: webcryptoHashName(algorithm) }, false, ["sign"]);
|
|
6916
6928
|
const signature = await crypto.subtle.sign("HMAC", cryptoKey, messageData);
|
|
6917
6929
|
const hashArray = Array.from(new Uint8Array(signature));
|
|
6918
6930
|
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
6919
6931
|
}
|
|
6932
|
+
async function verifyHmac(data, key2, signature, algorithm = "sha256") {
|
|
6933
|
+
const expected = await hmac2(data, key2, algorithm);
|
|
6934
|
+
if (expected.length !== signature.length) return false;
|
|
6935
|
+
let diff2 = 0;
|
|
6936
|
+
for (let i = 0; i < expected.length; i++) diff2 |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
|
|
6937
|
+
return diff2 === 0;
|
|
6938
|
+
}
|
|
6920
6939
|
async function pbkdf2(password, salt, iterations = 1e5, keyLength = 256) {
|
|
6921
6940
|
const encoder2 = new TextEncoder();
|
|
6922
6941
|
const keyMaterial = await crypto.subtle.importKey("raw", encoder2.encode(password), "PBKDF2", false, ["deriveBits"]);
|
|
6923
6942
|
const derivedBits = await crypto.subtle.deriveBits(
|
|
6924
|
-
{ name: "PBKDF2", salt: encoder2.encode(salt), iterations, hash: "
|
|
6943
|
+
{ name: "PBKDF2", salt: encoder2.encode(salt), iterations, hash: "SHA-256" },
|
|
6925
6944
|
keyMaterial,
|
|
6926
6945
|
keyLength
|
|
6927
6946
|
);
|
|
@@ -6966,9 +6985,16 @@ async function decryptString(encryptedData, password, salt) {
|
|
|
6966
6985
|
const key2 = await deriveKey(password, salt);
|
|
6967
6986
|
return decryptAES(encrypted, key2, iv);
|
|
6968
6987
|
}
|
|
6988
|
+
async function generateRSASigningKeyPair(bits = 2048) {
|
|
6989
|
+
return crypto.subtle.generateKey(
|
|
6990
|
+
{ name: "RSASSA-PKCS1-v1_5", modulusLength: bits, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" },
|
|
6991
|
+
true,
|
|
6992
|
+
["sign", "verify"]
|
|
6993
|
+
);
|
|
6994
|
+
}
|
|
6969
6995
|
async function generateRSAKeyPair(bits = 2048) {
|
|
6970
6996
|
return crypto.subtle.generateKey(
|
|
6971
|
-
{ name: "RSA-OAEP", modulusLength: bits, publicExponent: new Uint8Array([1, 0, 1]), hash: "
|
|
6997
|
+
{ name: "RSA-OAEP", modulusLength: bits, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" },
|
|
6972
6998
|
true,
|
|
6973
6999
|
["encrypt", "decrypt"]
|
|
6974
7000
|
);
|
|
@@ -8416,36 +8442,6 @@ var init_etag = __esm({
|
|
|
8416
8442
|
});
|
|
8417
8443
|
|
|
8418
8444
|
// ../../packages/shared/tw/hashing/hmac.ts
|
|
8419
|
-
function bufferToHex2(buffer) {
|
|
8420
|
-
const bytes = new Uint8Array(buffer);
|
|
8421
|
-
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
8422
|
-
}
|
|
8423
|
-
function timingSafeEqual2(a, b) {
|
|
8424
|
-
if (a.length !== b.length) return false;
|
|
8425
|
-
let result = 0;
|
|
8426
|
-
for (let i = 0; i < a.length; i++) {
|
|
8427
|
-
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
8428
|
-
}
|
|
8429
|
-
return result === 0;
|
|
8430
|
-
}
|
|
8431
|
-
async function hmac3(key2, message, algorithm = "SHA-256") {
|
|
8432
|
-
const encoder2 = new TextEncoder();
|
|
8433
|
-
const keyData = encoder2.encode(key2);
|
|
8434
|
-
const messageData = encoder2.encode(message);
|
|
8435
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
8436
|
-
"raw",
|
|
8437
|
-
keyData,
|
|
8438
|
-
{ name: "HMAC", hash: algorithm },
|
|
8439
|
-
false,
|
|
8440
|
-
["sign"]
|
|
8441
|
-
);
|
|
8442
|
-
const signature = await crypto.subtle.sign("HMAC", cryptoKey, messageData);
|
|
8443
|
-
return bufferToHex2(signature);
|
|
8444
|
-
}
|
|
8445
|
-
async function verifyHmac(key2, message, signature, algorithm = "SHA-256") {
|
|
8446
|
-
const computed6 = await hmac3(key2, message, algorithm);
|
|
8447
|
-
return timingSafeEqual2(computed6, signature);
|
|
8448
|
-
}
|
|
8449
8445
|
var init_hmac = __esm({
|
|
8450
8446
|
"../../packages/shared/tw/hashing/hmac.ts"() {
|
|
8451
8447
|
}
|
|
@@ -9110,6 +9106,7 @@ __export(tw_exports, {
|
|
|
9110
9106
|
generatePIN: () => generatePIN,
|
|
9111
9107
|
generateProofOfKnowledge: () => generateProofOfKnowledge,
|
|
9112
9108
|
generateRSAKeyPair: () => generateRSAKeyPair,
|
|
9109
|
+
generateRSASigningKeyPair: () => generateRSASigningKeyPair,
|
|
9113
9110
|
generateSecret: () => generateSecret,
|
|
9114
9111
|
generateTOTP: () => generateTOTP,
|
|
9115
9112
|
geolocation: () => geolocation,
|
|
@@ -9615,6 +9612,7 @@ __export(tw_exports, {
|
|
|
9615
9612
|
zip: () => zip,
|
|
9616
9613
|
zipWith: () => zipWith
|
|
9617
9614
|
});
|
|
9615
|
+
import { createHmac } from "node:crypto";
|
|
9618
9616
|
function generateETag(data) {
|
|
9619
9617
|
let hash2 = 0;
|
|
9620
9618
|
for (let i = 0; i < data.length; i++) {
|
|
@@ -9640,19 +9638,14 @@ function merkleRoot(hashes) {
|
|
|
9640
9638
|
return level[0];
|
|
9641
9639
|
}
|
|
9642
9640
|
function hmacSign(data, key2) {
|
|
9643
|
-
|
|
9644
|
-
for (let i = 0; i < data.length; i++) {
|
|
9645
|
-
h1 = (h1 << 5) - h1 + data.charCodeAt(i);
|
|
9646
|
-
h1 |= 0;
|
|
9647
|
-
}
|
|
9648
|
-
for (let i = 0; i < key2.length; i++) {
|
|
9649
|
-
h22 = (h22 << 5) - h22 + key2.charCodeAt(i);
|
|
9650
|
-
h22 |= 0;
|
|
9651
|
-
}
|
|
9652
|
-
return (h1 ^ h22).toString(16);
|
|
9641
|
+
return createHmac("sha256", key2).update(data).digest("hex");
|
|
9653
9642
|
}
|
|
9654
9643
|
function hmacVerify(data, key2, signature) {
|
|
9655
|
-
|
|
9644
|
+
const expected = hmacSign(data, key2);
|
|
9645
|
+
if (expected.length !== signature.length) return false;
|
|
9646
|
+
let diff2 = 0;
|
|
9647
|
+
for (let i = 0; i < expected.length; i++) diff2 |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
|
|
9648
|
+
return diff2 === 0;
|
|
9656
9649
|
}
|
|
9657
9650
|
var HTML_TAGS;
|
|
9658
9651
|
var init_tw = __esm({
|
|
@@ -9809,6 +9802,9 @@ function optimizedImageUrl(src, opts = {}) {
|
|
|
9809
9802
|
if (opts.quality) p.set("q", String(opts.quality));
|
|
9810
9803
|
p.set("f", opts.format ?? "auto");
|
|
9811
9804
|
const qs = p.toString();
|
|
9805
|
+
if (/^https?:\/\//i.test(src)) {
|
|
9806
|
+
return `/_tw/img/_remote?src=${encodeURIComponent(src)}&${qs}`;
|
|
9807
|
+
}
|
|
9812
9808
|
return `/_tw/img${src.startsWith("/") ? src : "/" + src}?${qs}`;
|
|
9813
9809
|
}
|
|
9814
9810
|
function imageAttributesFor(opts, config = DEFAULT_IMAGE_CONFIG) {
|
|
@@ -9816,7 +9812,7 @@ function imageAttributesFor(opts, config = DEFAULT_IMAGE_CONFIG) {
|
|
|
9816
9812
|
const quality = opts.quality ?? config.quality;
|
|
9817
9813
|
const format = config.formats[0] ?? "webp";
|
|
9818
9814
|
const isRemote = /^https?:\/\//i.test(opts.src);
|
|
9819
|
-
const src = isRemote ? `/_tw/img/_remote?src=${encodeURIComponent(opts.src)}
|
|
9815
|
+
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 });
|
|
9820
9816
|
const widths = config.breakpoints.filter((bp) => width === 0 || bp <= width * 2);
|
|
9821
9817
|
const srcset = widths.map(
|
|
9822
9818
|
(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`
|
|
@@ -9996,7 +9992,7 @@ function createImageHandler(options) {
|
|
|
9996
9992
|
}
|
|
9997
9993
|
if (!warnedNoSharp) {
|
|
9998
9994
|
warnedNoSharp = true;
|
|
9999
|
-
console.warn(" [tw/image] sharp not installed \u2014
|
|
9995
|
+
console.warn(" [tw/image] sharp not installed \u2014 using the built-in converter (WebP/AVIF); install sharp for faster resizing");
|
|
10000
9996
|
}
|
|
10001
9997
|
return { data, contentType: "", viaSharp: false };
|
|
10002
9998
|
}
|
|
@@ -10788,6 +10784,18 @@ function findGlobalError(rootNode2) {
|
|
|
10788
10784
|
function findRootError(rootNode2) {
|
|
10789
10785
|
return (rootNode2.files || []).find((f) => f.type === "error");
|
|
10790
10786
|
}
|
|
10787
|
+
function findNearestNotFound(rootNode2, pathParts) {
|
|
10788
|
+
let found = (rootNode2.files || []).find((f) => f.type === "not-found");
|
|
10789
|
+
let node = rootNode2;
|
|
10790
|
+
for (const part of pathParts) {
|
|
10791
|
+
const child = (node.children || []).find((c) => c.segment === part);
|
|
10792
|
+
if (!child) break;
|
|
10793
|
+
const f = (child.files || []).find((x) => x.type === "not-found");
|
|
10794
|
+
if (f) found = f;
|
|
10795
|
+
node = child;
|
|
10796
|
+
}
|
|
10797
|
+
return found;
|
|
10798
|
+
}
|
|
10791
10799
|
function findRootNotFound(rootNode2) {
|
|
10792
10800
|
return rootNode2.files.find((f) => f.type === "not-found");
|
|
10793
10801
|
}
|
|
@@ -228129,7 +228137,7 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
228129
228137
|
const after2 = cursor.peek(1);
|
|
228130
228138
|
if (after2 && after2.type === "COLON") break;
|
|
228131
228139
|
}
|
|
228132
|
-
if (ct.type === "IDENT" && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
228140
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !prevWasMinus && classVal.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
228133
228141
|
break;
|
|
228134
228142
|
}
|
|
228135
228143
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -228157,7 +228165,11 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
228157
228165
|
while (!cursor.done) {
|
|
228158
228166
|
const ct = cursor.peek();
|
|
228159
228167
|
if (!ct) break;
|
|
228160
|
-
if (ct.type === "IDENT" &&
|
|
228168
|
+
if (ct.type === "IDENT" && ct.value === "on") {
|
|
228169
|
+
const after2 = cursor.peek(1);
|
|
228170
|
+
if (after2 && after2.type === "COLON") break;
|
|
228171
|
+
}
|
|
228172
|
+
if ((ct.type === "IDENT" || ct.type === "KEYWORD") && !nextPrevMinus && nextClass.length > 0 && (CLASS_BOUNDARY_BOOLEAN_ATTRS.has(ct.value) || inlineAttrStartsAt(cursor))) {
|
|
228161
228173
|
break;
|
|
228162
228174
|
}
|
|
228163
228175
|
if (ct.type === "IDENT" || ct.type === "TEXT" || ct.type === "KEYWORD") {
|
|
@@ -228447,7 +228459,9 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
228447
228459
|
const first = cursor.peek();
|
|
228448
228460
|
const second = cursor.peek(1);
|
|
228449
228461
|
const CONTROL_FLOW = /* @__PURE__ */ new Set(["for", "if", "while", "switch", "else", "try", "catch"]);
|
|
228450
|
-
const
|
|
228462
|
+
const third = cursor.peek(2);
|
|
228463
|
+
const isPropBlock = second && second.type === "ASSIGN" && third && third.type === "LBRACE";
|
|
228464
|
+
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");
|
|
228451
228465
|
if (isAttrBlock) {
|
|
228452
228466
|
while (!cursor.done) {
|
|
228453
228467
|
const t3 = cursor.peek();
|
|
@@ -228455,6 +228469,34 @@ function parseTWSelector(cursor, errors, state, parseBody) {
|
|
|
228455
228469
|
if (t3.type === "IDENT" || t3.type === "KEYWORD") {
|
|
228456
228470
|
const attrName = t3.value;
|
|
228457
228471
|
cursor.advance();
|
|
228472
|
+
if (cursor.peek() && (cursor.peek().type === "ASSIGN" || cursor.peek().type === "EQUALS")) {
|
|
228473
|
+
cursor.advance();
|
|
228474
|
+
cursor.skipWhitespace();
|
|
228475
|
+
if (cursor.peek() && cursor.peek().type === "LBRACE") {
|
|
228476
|
+
cursor.advance();
|
|
228477
|
+
let expr = "";
|
|
228478
|
+
let depth = 1;
|
|
228479
|
+
let prevWS = false;
|
|
228480
|
+
while (!cursor.done) {
|
|
228481
|
+
const tk = cursor.peek();
|
|
228482
|
+
if (!tk || tk.type === "EOF") break;
|
|
228483
|
+
if (tk.type === "LBRACE") depth++;
|
|
228484
|
+
else if (tk.type === "RBRACE") {
|
|
228485
|
+
depth--;
|
|
228486
|
+
if (depth === 0) {
|
|
228487
|
+
cursor.advance();
|
|
228488
|
+
break;
|
|
228489
|
+
}
|
|
228490
|
+
}
|
|
228491
|
+
if (expr && prevWS) expr += " ";
|
|
228492
|
+
expr += tk.raw ?? tk.value;
|
|
228493
|
+
prevWS = !!tk.followedByWhitespace;
|
|
228494
|
+
cursor.advance();
|
|
228495
|
+
}
|
|
228496
|
+
el.attrs.push(createAttribute(attrName, expr.trim(), t3.pos.line, t3.pos.col, true));
|
|
228497
|
+
continue;
|
|
228498
|
+
}
|
|
228499
|
+
}
|
|
228458
228500
|
const vToken = cursor.peek();
|
|
228459
228501
|
if (vToken && (vToken.type === "STRING" || vToken.type === "NUMBER")) {
|
|
228460
228502
|
cursor.advance();
|
|
@@ -237200,13 +237242,17 @@ var init_types4 = __esm({
|
|
|
237200
237242
|
var TW_VERSION, TW_GENERATOR_META;
|
|
237201
237243
|
var init_version = __esm({
|
|
237202
237244
|
"../../packages/compiler/tw/codegen/version.ts"() {
|
|
237203
|
-
TW_VERSION = "2.0.
|
|
237245
|
+
TW_VERSION = "2.0.2";
|
|
237204
237246
|
TW_GENERATOR_META = `<meta name="generator" content="TW Framework ${TW_VERSION}">`;
|
|
237205
237247
|
}
|
|
237206
237248
|
});
|
|
237207
237249
|
|
|
237208
237250
|
// ../../packages/link/tw/index.ts
|
|
237251
|
+
function isDangerousHref(href) {
|
|
237252
|
+
return DANGEROUS_SCHEME.test(href.replace(/[\u0000-\u0020]/g, ""));
|
|
237253
|
+
}
|
|
237209
237254
|
function isExternalHref(href) {
|
|
237255
|
+
if (isDangerousHref(href)) return false;
|
|
237210
237256
|
return /^[a-z][a-z0-9+.-]*:/i.test(href) || // any scheme: http(s), mailto, tel, ...
|
|
237211
237257
|
href.startsWith("//");
|
|
237212
237258
|
}
|
|
@@ -237215,7 +237261,8 @@ function isWebExternal(href) {
|
|
|
237215
237261
|
return true;
|
|
237216
237262
|
}
|
|
237217
237263
|
function linkAttributesFor(opts) {
|
|
237218
|
-
const
|
|
237264
|
+
const rawHref = (opts.href ?? "").trim();
|
|
237265
|
+
const href = isDangerousHref(rawHref) ? "#" : rawHref;
|
|
237219
237266
|
const external = opts.external === true || isExternalHref(href);
|
|
237220
237267
|
const attrs = {};
|
|
237221
237268
|
if (external) {
|
|
@@ -237244,8 +237291,10 @@ function linkAttributesFor(opts) {
|
|
|
237244
237291
|
if (opts.id) attrs["id"] = opts.id;
|
|
237245
237292
|
return { href, external, attrs };
|
|
237246
237293
|
}
|
|
237294
|
+
var DANGEROUS_SCHEME;
|
|
237247
237295
|
var init_tw3 = __esm({
|
|
237248
237296
|
"../../packages/link/tw/index.ts"() {
|
|
237297
|
+
DANGEROUS_SCHEME = /^(javascript|data|vbscript):/i;
|
|
237249
237298
|
}
|
|
237250
237299
|
});
|
|
237251
237300
|
|
|
@@ -237758,12 +237807,31 @@ var init_interpolate = __esm({
|
|
|
237758
237807
|
});
|
|
237759
237808
|
|
|
237760
237809
|
// ../../packages/compiler/tw/eval/evaluate.ts
|
|
237810
|
+
function setEvalBindings(bindings) {
|
|
237811
|
+
extraBindings = bindings ?? {};
|
|
237812
|
+
}
|
|
237761
237813
|
function evaluate(expr, vars, sandbox) {
|
|
237762
237814
|
if (!expr) return "";
|
|
237763
237815
|
const sb = sandbox ?? defaultSandbox;
|
|
237764
237816
|
if (vars[expr] !== void 0) {
|
|
237765
237817
|
return vars[expr];
|
|
237766
237818
|
}
|
|
237819
|
+
if (expr.startsWith("(") && expr.endsWith(")")) {
|
|
237820
|
+
let d = 0;
|
|
237821
|
+
let wraps = true;
|
|
237822
|
+
for (let i = 0; i < expr.length; i++) {
|
|
237823
|
+
const ch = expr[i];
|
|
237824
|
+
if (ch === "(") d++;
|
|
237825
|
+
else if (ch === ")") {
|
|
237826
|
+
d--;
|
|
237827
|
+
if (d === 0 && i < expr.length - 1) {
|
|
237828
|
+
wraps = false;
|
|
237829
|
+
break;
|
|
237830
|
+
}
|
|
237831
|
+
}
|
|
237832
|
+
}
|
|
237833
|
+
if (wraps && d === 0) return evaluate(expr.slice(1, -1).trim(), vars, sb);
|
|
237834
|
+
}
|
|
237767
237835
|
if (/^-?\d+(\.\d+)?$/.test(expr)) return expr;
|
|
237768
237836
|
if (expr.startsWith('"') && expr.endsWith('"') || expr.startsWith("'") && expr.endsWith("'")) {
|
|
237769
237837
|
return expr.slice(1, -1);
|
|
@@ -237771,11 +237839,54 @@ function evaluate(expr, vars, sandbox) {
|
|
|
237771
237839
|
if (expr === "true") return "true";
|
|
237772
237840
|
if (expr === "false") return "false";
|
|
237773
237841
|
if (expr === "null" || expr === "undefined") return "";
|
|
237774
|
-
|
|
237775
|
-
|
|
237776
|
-
|
|
237777
|
-
|
|
237842
|
+
{
|
|
237843
|
+
let depth = 0;
|
|
237844
|
+
let pending2 = 0;
|
|
237845
|
+
let q = -1;
|
|
237846
|
+
let quote = "";
|
|
237847
|
+
for (let i = 0; i < expr.length; i++) {
|
|
237848
|
+
const ch = expr[i];
|
|
237849
|
+
if (quote) {
|
|
237850
|
+
if (ch === "\\") {
|
|
237851
|
+
i++;
|
|
237852
|
+
continue;
|
|
237853
|
+
}
|
|
237854
|
+
if (ch === quote) quote = "";
|
|
237855
|
+
continue;
|
|
237856
|
+
}
|
|
237857
|
+
if (ch === "'" || ch === '"' || ch === "`") {
|
|
237858
|
+
quote = ch;
|
|
237859
|
+
continue;
|
|
237860
|
+
}
|
|
237861
|
+
if (ch === "(" || ch === "[" || ch === "{") {
|
|
237862
|
+
depth++;
|
|
237863
|
+
continue;
|
|
237864
|
+
}
|
|
237865
|
+
if (ch === ")" || ch === "]" || ch === "}") {
|
|
237866
|
+
depth--;
|
|
237867
|
+
continue;
|
|
237868
|
+
}
|
|
237869
|
+
if (depth !== 0) continue;
|
|
237870
|
+
if (ch === "?") {
|
|
237871
|
+
if (pending2 === 0) q = i;
|
|
237872
|
+
pending2++;
|
|
237873
|
+
continue;
|
|
237874
|
+
}
|
|
237875
|
+
if (ch === ":" && pending2 > 0) {
|
|
237876
|
+
pending2--;
|
|
237877
|
+
if (pending2 > 0) continue;
|
|
237878
|
+
const cond = expr.slice(0, q).trim();
|
|
237879
|
+
const cons = expr.slice(q + 1, i).trim();
|
|
237880
|
+
const alt = expr.slice(i + 1).trim();
|
|
237881
|
+
if (cond && cons && alt) {
|
|
237882
|
+
return isTruthy(resolve2(cond, vars, sb)) ? resolve2(cons, vars, sb) : resolve2(alt, vars, sb);
|
|
237883
|
+
}
|
|
237884
|
+
break;
|
|
237885
|
+
}
|
|
237886
|
+
}
|
|
237778
237887
|
}
|
|
237888
|
+
const dyn = evalWithVars(expr, vars);
|
|
237889
|
+
if (dyn !== null) return dyn;
|
|
237779
237890
|
const orParts = splitLogical(expr, "||");
|
|
237780
237891
|
if (orParts.length > 1) {
|
|
237781
237892
|
for (const part of orParts) {
|
|
@@ -237852,7 +237963,7 @@ function evaluate(expr, vars, sandbox) {
|
|
|
237852
237963
|
return current2 !== void 0 && current2 !== null ? String(current2) : "";
|
|
237853
237964
|
}
|
|
237854
237965
|
const fnMatch = expr.match(/^(\w+)\((.*)\)$/);
|
|
237855
|
-
if (fnMatch) {
|
|
237966
|
+
if (fnMatch && isBuiltinName(fnMatch[1])) {
|
|
237856
237967
|
const fn = fnMatch[1];
|
|
237857
237968
|
const arg = resolve2(fnMatch[2].trim(), vars, sb);
|
|
237858
237969
|
return callBuiltin(fn, arg, sb);
|
|
@@ -237871,6 +237982,38 @@ function evaluate(expr, vars, sandbox) {
|
|
|
237871
237982
|
}
|
|
237872
237983
|
return expr;
|
|
237873
237984
|
}
|
|
237985
|
+
function evalWithVars(expr, vars) {
|
|
237986
|
+
if (!expr || /[`\\]/.test(expr)) return null;
|
|
237987
|
+
if (!/^[\w\s.$[\]{}()'"`,+\-*/%?:<>=!&|]*$/.test(expr)) return null;
|
|
237988
|
+
for (const m of expr.matchAll(/\.([A-Za-z_$][\w$]*)\s*\(/g)) {
|
|
237989
|
+
if (!SAFE_MEMBERS.has(m[1])) return null;
|
|
237990
|
+
}
|
|
237991
|
+
const names = [];
|
|
237992
|
+
const vals = [];
|
|
237993
|
+
for (const k of Object.keys(vars)) {
|
|
237994
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(k)) continue;
|
|
237995
|
+
if (k in extraBindings) continue;
|
|
237996
|
+
names.push(k);
|
|
237997
|
+
try {
|
|
237998
|
+
vals.push(JSON.parse(vars[k]));
|
|
237999
|
+
} catch {
|
|
238000
|
+
vals.push(vars[k]);
|
|
238001
|
+
}
|
|
238002
|
+
}
|
|
238003
|
+
for (const k of Object.keys(extraBindings)) {
|
|
238004
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(k)) continue;
|
|
238005
|
+
names.push(k);
|
|
238006
|
+
vals.push(extraBindings[k]);
|
|
238007
|
+
}
|
|
238008
|
+
try {
|
|
238009
|
+
const fn = new Function(...names, `"use strict"; return (${expr});`);
|
|
238010
|
+
const out = fn(...vals);
|
|
238011
|
+
if (out === void 0 || out === null) return null;
|
|
238012
|
+
return typeof out === "object" ? JSON.stringify(out) : String(out);
|
|
238013
|
+
} catch {
|
|
238014
|
+
return null;
|
|
238015
|
+
}
|
|
238016
|
+
}
|
|
237874
238017
|
function resolve2(token, vars, sandbox) {
|
|
237875
238018
|
const trimmed = token.trim();
|
|
237876
238019
|
if (!trimmed) return "";
|
|
@@ -238039,7 +238182,7 @@ function coerce(value, targetType) {
|
|
|
238039
238182
|
return value;
|
|
238040
238183
|
}
|
|
238041
238184
|
}
|
|
238042
|
-
var defaultSandbox;
|
|
238185
|
+
var defaultSandbox, extraBindings, SAFE_MEMBERS;
|
|
238043
238186
|
var init_evaluate = __esm({
|
|
238044
238187
|
"../../packages/compiler/tw/eval/evaluate.ts"() {
|
|
238045
238188
|
init_sandbox();
|
|
@@ -238047,6 +238190,64 @@ var init_evaluate = __esm({
|
|
|
238047
238190
|
init_builtins();
|
|
238048
238191
|
init_interpolate();
|
|
238049
238192
|
defaultSandbox = new Sandbox();
|
|
238193
|
+
extraBindings = {};
|
|
238194
|
+
SAFE_MEMBERS = /* @__PURE__ */ new Set([
|
|
238195
|
+
"length",
|
|
238196
|
+
"toUpperCase",
|
|
238197
|
+
"toLowerCase",
|
|
238198
|
+
"trim",
|
|
238199
|
+
"trimStart",
|
|
238200
|
+
"trimEnd",
|
|
238201
|
+
"slice",
|
|
238202
|
+
"substring",
|
|
238203
|
+
"substr",
|
|
238204
|
+
"charAt",
|
|
238205
|
+
"at",
|
|
238206
|
+
"includes",
|
|
238207
|
+
"indexOf",
|
|
238208
|
+
"lastIndexOf",
|
|
238209
|
+
"startsWith",
|
|
238210
|
+
"endsWith",
|
|
238211
|
+
"replace",
|
|
238212
|
+
"replaceAll",
|
|
238213
|
+
"split",
|
|
238214
|
+
"join",
|
|
238215
|
+
"concat",
|
|
238216
|
+
"repeat",
|
|
238217
|
+
"padStart",
|
|
238218
|
+
"padEnd",
|
|
238219
|
+
"toString",
|
|
238220
|
+
"toFixed",
|
|
238221
|
+
"map",
|
|
238222
|
+
"filter",
|
|
238223
|
+
"find",
|
|
238224
|
+
"some",
|
|
238225
|
+
"every",
|
|
238226
|
+
"reduce",
|
|
238227
|
+
"sort",
|
|
238228
|
+
"reverse",
|
|
238229
|
+
// Static helpers on the built-ins (JSON.stringify, Object.keys, Math.round).
|
|
238230
|
+
"stringify",
|
|
238231
|
+
"parse",
|
|
238232
|
+
"keys",
|
|
238233
|
+
"values",
|
|
238234
|
+
"entries",
|
|
238235
|
+
"from",
|
|
238236
|
+
"isArray",
|
|
238237
|
+
"isInteger",
|
|
238238
|
+
"isFinite",
|
|
238239
|
+
"abs",
|
|
238240
|
+
"ceil",
|
|
238241
|
+
"floor",
|
|
238242
|
+
"round",
|
|
238243
|
+
"max",
|
|
238244
|
+
"min",
|
|
238245
|
+
"pow",
|
|
238246
|
+
"sqrt",
|
|
238247
|
+
"random",
|
|
238248
|
+
"now",
|
|
238249
|
+
"toISOString"
|
|
238250
|
+
]);
|
|
238050
238251
|
}
|
|
238051
238252
|
});
|
|
238052
238253
|
|
|
@@ -238201,9 +238402,78 @@ function callBuiltin(fn, arg, sandbox) {
|
|
|
238201
238402
|
function applyFilter(value, filter, args, vars, sandbox) {
|
|
238202
238403
|
return callBuiltin(filter, value, sandbox);
|
|
238203
238404
|
}
|
|
238405
|
+
function isBuiltinName(fn) {
|
|
238406
|
+
return BUILTIN_NAMES.has(fn);
|
|
238407
|
+
}
|
|
238408
|
+
var BUILTIN_NAMES;
|
|
238204
238409
|
var init_builtins = __esm({
|
|
238205
238410
|
"../../packages/compiler/tw/eval/builtins.ts"() {
|
|
238206
238411
|
init_evaluate();
|
|
238412
|
+
BUILTIN_NAMES = /* @__PURE__ */ new Set([
|
|
238413
|
+
"Boolean",
|
|
238414
|
+
"Number",
|
|
238415
|
+
"String",
|
|
238416
|
+
"abs",
|
|
238417
|
+
"base64decode",
|
|
238418
|
+
"base64encode",
|
|
238419
|
+
"bool",
|
|
238420
|
+
"camelCase",
|
|
238421
|
+
"capitalize",
|
|
238422
|
+
"ceil",
|
|
238423
|
+
"cos",
|
|
238424
|
+
"date",
|
|
238425
|
+
"decodeURI",
|
|
238426
|
+
"encodeURI",
|
|
238427
|
+
"endsWith",
|
|
238428
|
+
"exp",
|
|
238429
|
+
"first",
|
|
238430
|
+
"float",
|
|
238431
|
+
"floor",
|
|
238432
|
+
"includes",
|
|
238433
|
+
"indexOf",
|
|
238434
|
+
"int",
|
|
238435
|
+
"join",
|
|
238436
|
+
"json",
|
|
238437
|
+
"kebabCase",
|
|
238438
|
+
"last",
|
|
238439
|
+
"len",
|
|
238440
|
+
"length",
|
|
238441
|
+
"log",
|
|
238442
|
+
"lower",
|
|
238443
|
+
"lowercase",
|
|
238444
|
+
"match",
|
|
238445
|
+
"max",
|
|
238446
|
+
"min",
|
|
238447
|
+
"now",
|
|
238448
|
+
"num",
|
|
238449
|
+
"padEnd",
|
|
238450
|
+
"padStart",
|
|
238451
|
+
"parseFloat",
|
|
238452
|
+
"parseInt",
|
|
238453
|
+
"parseJSON",
|
|
238454
|
+
"pow",
|
|
238455
|
+
"random",
|
|
238456
|
+
"repeat",
|
|
238457
|
+
"replace",
|
|
238458
|
+
"reverse",
|
|
238459
|
+
"round",
|
|
238460
|
+
"sin",
|
|
238461
|
+
"size",
|
|
238462
|
+
"slice",
|
|
238463
|
+
"snakeCase",
|
|
238464
|
+
"split",
|
|
238465
|
+
"sqrt",
|
|
238466
|
+
"startsWith",
|
|
238467
|
+
"str",
|
|
238468
|
+
"stringify",
|
|
238469
|
+
"tan",
|
|
238470
|
+
"test",
|
|
238471
|
+
"time",
|
|
238472
|
+
"title",
|
|
238473
|
+
"trim",
|
|
238474
|
+
"upper",
|
|
238475
|
+
"uppercase"
|
|
238476
|
+
]);
|
|
238207
238477
|
}
|
|
238208
238478
|
});
|
|
238209
238479
|
|
|
@@ -239252,16 +239522,61 @@ function addScope(css, scopeId) {
|
|
|
239252
239522
|
out += prelude;
|
|
239253
239523
|
return out;
|
|
239254
239524
|
}
|
|
239255
|
-
function
|
|
239256
|
-
|
|
239257
|
-
|
|
239258
|
-
|
|
239525
|
+
function interpolateBraces(input, vars) {
|
|
239526
|
+
let out = "";
|
|
239527
|
+
let i = 0;
|
|
239528
|
+
while (i < input.length) {
|
|
239529
|
+
const ch = input[i];
|
|
239530
|
+
if (ch !== "{") {
|
|
239531
|
+
out += ch;
|
|
239532
|
+
i++;
|
|
239533
|
+
continue;
|
|
239534
|
+
}
|
|
239535
|
+
let depth = 1;
|
|
239536
|
+
let j = i + 1;
|
|
239537
|
+
let quote = "";
|
|
239538
|
+
while (j < input.length && depth > 0) {
|
|
239539
|
+
const c = input[j];
|
|
239540
|
+
if (quote) {
|
|
239541
|
+
if (c === "\\") {
|
|
239542
|
+
j += 2;
|
|
239543
|
+
continue;
|
|
239544
|
+
}
|
|
239545
|
+
if (c === quote) quote = "";
|
|
239546
|
+
j++;
|
|
239547
|
+
continue;
|
|
239548
|
+
}
|
|
239549
|
+
if (c === "'" || c === '"' || c === "`") {
|
|
239550
|
+
quote = c;
|
|
239551
|
+
j++;
|
|
239552
|
+
continue;
|
|
239553
|
+
}
|
|
239554
|
+
if (c === "{") depth++;
|
|
239555
|
+
else if (c === "}") {
|
|
239556
|
+
depth--;
|
|
239557
|
+
if (depth === 0) break;
|
|
239558
|
+
}
|
|
239559
|
+
j++;
|
|
239560
|
+
}
|
|
239561
|
+
if (depth !== 0) {
|
|
239562
|
+
out += ch;
|
|
239563
|
+
i++;
|
|
239564
|
+
continue;
|
|
239565
|
+
}
|
|
239566
|
+
const key2 = input.slice(i + 1, j).trim();
|
|
239259
239567
|
if (/^[a-zA-Z_$][\w$]*$/.test(key2)) {
|
|
239260
|
-
|
|
239568
|
+
out += vars[key2] ?? "";
|
|
239569
|
+
} else {
|
|
239570
|
+
const val = evaluate(key2, vars);
|
|
239571
|
+
out += val === null ? "" : val;
|
|
239261
239572
|
}
|
|
239262
|
-
|
|
239263
|
-
|
|
239264
|
-
|
|
239573
|
+
i = j + 1;
|
|
239574
|
+
}
|
|
239575
|
+
return out;
|
|
239576
|
+
}
|
|
239577
|
+
function interpolate2(expr, vars) {
|
|
239578
|
+
const masked = expr.replace(/\\\{/g, "O").replace(/\\\}/g, "C");
|
|
239579
|
+
const out = interpolateBraces(masked, vars);
|
|
239265
239580
|
return out.replace(/\u0001O/g, "{").replace(/\u0001C/g, "}");
|
|
239266
239581
|
}
|
|
239267
239582
|
function isTruthy2(val) {
|
|
@@ -239698,6 +240013,11 @@ function generateElement(el, ctx) {
|
|
|
239698
240013
|
}
|
|
239699
240014
|
function renderAttrs(el, ctx) {
|
|
239700
240015
|
const parts = [];
|
|
240016
|
+
const classAttrs = el.attrs.filter((a) => a.name === "class" && !a.isInterpolated && typeof a.value === "string");
|
|
240017
|
+
if (classAttrs.length > 1) {
|
|
240018
|
+
const merged = classAttrs.map((a) => String(a.value).trim()).filter(Boolean).join(" ");
|
|
240019
|
+
el = { ...el, attrs: el.attrs.filter((a) => a.name !== "class").concat([{ ...classAttrs[0], value: merged }]) };
|
|
240020
|
+
}
|
|
239701
240021
|
for (let attr of el.attrs) {
|
|
239702
240022
|
if (attr.name === "class" && typeof attr.value === "string" && !attr.isInterpolated) {
|
|
239703
240023
|
const scoped = ctx.scopedClasses;
|
|
@@ -239740,7 +240060,21 @@ function renderBindings(bindings, ctx) {
|
|
|
239740
240060
|
if (bindings.length === 0) return "";
|
|
239741
240061
|
const parts = [];
|
|
239742
240062
|
for (const binding of bindings) {
|
|
239743
|
-
|
|
240063
|
+
const expr = String(binding.expression ?? "");
|
|
240064
|
+
let initial = "";
|
|
240065
|
+
try {
|
|
240066
|
+
if (/^[A-Za-z_$][\w$]*$/.test(expr)) {
|
|
240067
|
+
const v = ctx.stateVars[expr];
|
|
240068
|
+
if (v !== void 0 && v !== null) initial = String(v);
|
|
240069
|
+
} else if (expr) {
|
|
240070
|
+
initial = interpolate2("{" + expr + "}", ctx.stateVars);
|
|
240071
|
+
}
|
|
240072
|
+
} catch {
|
|
240073
|
+
}
|
|
240074
|
+
if (initial && !/[{}]/.test(initial)) {
|
|
240075
|
+
parts.push(`${binding.property}="${escapeAttr3(initial)}"`);
|
|
240076
|
+
}
|
|
240077
|
+
parts.push(`data-tw-bind-${binding.property}="${escapeAttr3(expr)}"`);
|
|
239744
240078
|
}
|
|
239745
240079
|
return parts.join(" ");
|
|
239746
240080
|
}
|
|
@@ -239855,8 +240189,13 @@ function generateComponent(comp, ctx) {
|
|
|
239855
240189
|
const savedStateVars = { ...ctx.stateVars };
|
|
239856
240190
|
for (const prop of comp.props) {
|
|
239857
240191
|
if (typeof prop.value === "string") {
|
|
239858
|
-
const
|
|
239859
|
-
|
|
240192
|
+
const raw = String(prop.value);
|
|
240193
|
+
const head = raw.split(/[.[]/)[0];
|
|
240194
|
+
if (!/[{}]/.test(raw) && Object.prototype.hasOwnProperty.call(ctx.stateVars, head)) {
|
|
240195
|
+
ctx.stateVars[prop.name] = interpolate2("{" + raw + "}", ctx.stateVars);
|
|
240196
|
+
} else {
|
|
240197
|
+
ctx.stateVars[prop.name] = interpolate2(raw, ctx.stateVars);
|
|
240198
|
+
}
|
|
239860
240199
|
}
|
|
239861
240200
|
}
|
|
239862
240201
|
const componentProgram = componentRegistry.get(comp.name);
|
|
@@ -239950,6 +240289,14 @@ function generateFor(node, ctx) {
|
|
|
239950
240289
|
}
|
|
239951
240290
|
}
|
|
239952
240291
|
}
|
|
240292
|
+
if (items.length === 0 && !/^\s*\[/.test(iterableStr)) {
|
|
240293
|
+
try {
|
|
240294
|
+
const evaluated = evaluate(String(node.iterable ?? "").replace(/^\{/, "").replace(/\}$/, "").trim(), ctx.stateVars);
|
|
240295
|
+
const parsed = JSON.parse(evaluated);
|
|
240296
|
+
if (Array.isArray(parsed)) items = parsed;
|
|
240297
|
+
} catch {
|
|
240298
|
+
}
|
|
240299
|
+
}
|
|
239953
240300
|
for (let i = 0; i < items.length; i++) {
|
|
239954
240301
|
const childCtx = { ...ctx };
|
|
239955
240302
|
childCtx.stateVars = { ...ctx.stateVars };
|
|
@@ -239970,7 +240317,7 @@ function generateFor(node, ctx) {
|
|
|
239970
240317
|
tplSource = node.body.map((c) => generateNode(c, childCtx)).join("");
|
|
239971
240318
|
}
|
|
239972
240319
|
const listExpr = String(node.iterable ?? "").replace(/^\{/, "").replace(/\}$/, "");
|
|
239973
|
-
const tpl = tplSource.replace(/"/g, """);
|
|
240320
|
+
const tpl = tplSource.replace(/&/g, "&").replace(/"/g, """);
|
|
239974
240321
|
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>`;
|
|
239975
240322
|
}
|
|
239976
240323
|
return html;
|
|
@@ -243756,16 +244103,22 @@ function generateWithLayoutChain(layoutPrograms, pageProgram, stateVars) {
|
|
|
243756
244103
|
}
|
|
243757
244104
|
};
|
|
243758
244105
|
let pageTitle = "TW Page";
|
|
244106
|
+
let pageDescription = "";
|
|
243759
244107
|
for (const dir of pageProgram.directives || []) {
|
|
243760
|
-
if (dir.type === "PageDirective"
|
|
243761
|
-
|
|
243762
|
-
|
|
244108
|
+
if (dir.type === "PageDirective") {
|
|
244109
|
+
if (dir.key === "title") {
|
|
244110
|
+
const t3 = dir.value;
|
|
244111
|
+
if (t3 != null && String(t3) !== "") pageTitle = String(t3);
|
|
244112
|
+
} else if (dir.key === "description") {
|
|
244113
|
+
const d = dir.value;
|
|
244114
|
+
if (d != null) pageDescription = String(d);
|
|
244115
|
+
}
|
|
243763
244116
|
}
|
|
243764
244117
|
}
|
|
243765
244118
|
const pageCtx = createContext("ssr");
|
|
243766
244119
|
seedCtx(pageCtx);
|
|
243767
244120
|
try {
|
|
243768
|
-
pageCtx.stateVars["page"] = JSON.stringify({ title: pageTitle });
|
|
244121
|
+
pageCtx.stateVars["page"] = JSON.stringify({ title: pageTitle, description: pageDescription });
|
|
243769
244122
|
} catch {
|
|
243770
244123
|
}
|
|
243771
244124
|
{
|
|
@@ -243921,6 +244274,10 @@ function generate(program, stateVars, genOpts2) {
|
|
|
243921
244274
|
const startTime = performance.now();
|
|
243922
244275
|
const ctx = createContext("ssr");
|
|
243923
244276
|
if (stateVars) ctx.stateVars = stateVars;
|
|
244277
|
+
if (genOpts2?.imports) {
|
|
244278
|
+
ctx.imports = genOpts2.imports;
|
|
244279
|
+
setEvalBindings(genOpts2.imports);
|
|
244280
|
+
} else setEvalBindings({});
|
|
243924
244281
|
if (genOpts2 && genOpts2.scopedStyles === false) ctx.scopedStyles = false;
|
|
243925
244282
|
if (genOpts2?.scopeId) ctx.scopeId = genOpts2.scopeId;
|
|
243926
244283
|
if (genOpts2?.cssPrefix) ctx.cssPrefix = genOpts2.cssPrefix;
|
|
@@ -244005,6 +244362,7 @@ var init_vdom = __esm({
|
|
|
244005
244362
|
init_types4();
|
|
244006
244363
|
init_html2();
|
|
244007
244364
|
init_builtin_components();
|
|
244365
|
+
init_evaluate();
|
|
244008
244366
|
}
|
|
244009
244367
|
});
|
|
244010
244368
|
|
|
@@ -244345,6 +244703,7 @@ var init_codes = __esm({
|
|
|
244345
244703
|
TW095: { message: "Invalid for-loop iterable -- use {varName} or a valid comma-separated literal", severity: "error", category: "syntax" },
|
|
244346
244704
|
TW096: { message: "Unknown state variable in interpolation (renders empty)", severity: "warning", category: "semantic" },
|
|
244347
244705
|
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" },
|
|
244706
|
+
TW098: { message: "Interpolation cannot be evaluated at build time -- it renders as its source text", severity: "warning", category: "semantic" },
|
|
244348
244707
|
// Server blocks (TW099-TW101)
|
|
244349
244708
|
TW099: { message: "Unknown server modifier (only ':defer' is supported)", severity: "error", category: "syntax" },
|
|
244350
244709
|
TW100: { message: "Expected '{' after 'server'", severity: "error", category: "syntax" },
|
|
@@ -244368,6 +244727,8 @@ var init_codes = __esm({
|
|
|
244368
244727
|
TW117: { message: "fetch() with a request-derived URL (SSRF lint)", severity: "warning", category: "semantic" },
|
|
244369
244728
|
TW118: { message: "A deferred server block cannot redirect() or notFound() -- the response has already begun", severity: "error", category: "semantic" },
|
|
244370
244729
|
TW119: { message: "A deferred server block cannot be used on a cached page -- cache { } serves one HTML to every request", severity: "error", category: "semantic" },
|
|
244730
|
+
TW121: { message: "The same name is declared by more than one state { } block (the earlier one wins)", severity: "warning", category: "semantic" },
|
|
244731
|
+
TW122: { message: "More than one default slot in the same component -- a caller's default content has no defined destination", severity: "warning", category: "semantic" },
|
|
244371
244732
|
// Codes thrown outside the rule engine. TW303 comes from the stylesheet
|
|
244372
244733
|
// parser (codegen/tss.ts); TW000 is the generic fallback used when an error
|
|
244373
244734
|
// carries no code of its own.
|
|
@@ -244432,6 +244793,7 @@ function checkUnknownTags(program, filePath, diags) {
|
|
|
244432
244793
|
forEachNode(program, (node, ctx) => {
|
|
244433
244794
|
if (!isElement(node)) return;
|
|
244434
244795
|
if (node.tag[0] === node.tag[0]?.toUpperCase()) return;
|
|
244796
|
+
if (BUILTIN_COMPONENT_TAGS.has(node.tag)) return;
|
|
244435
244797
|
const parent = ctx?.parent;
|
|
244436
244798
|
if (parent && (parent.type === "Element" && typeof parent.tag === "string" && parent.tag[0] === parent.tag[0]?.toUpperCase() || parent.type === "Component")) return;
|
|
244437
244799
|
if (HTML_ELEMENTS2.has(node.tag.toLowerCase())) return;
|
|
@@ -244760,6 +245122,14 @@ function checkUnknownStateVars(program, filePath, diags) {
|
|
|
244760
245122
|
if (d && d.type === "ServerBlock" && Array.isArray(d.declaredNames)) {
|
|
244761
245123
|
for (const n of d.declaredNames) known.add(n);
|
|
244762
245124
|
}
|
|
245125
|
+
if (d && d.type === "ImportDirective" && !d.isTypeOnly) {
|
|
245126
|
+
if (d.defaultImport) known.add(String(d.defaultImport));
|
|
245127
|
+
if (d.namespaceImport) known.add(String(d.namespaceImport));
|
|
245128
|
+
for (const it of d.items ?? []) {
|
|
245129
|
+
const nm = String(it).split(/\s+as\s+/).pop()?.trim();
|
|
245130
|
+
if (nm) known.add(nm);
|
|
245131
|
+
}
|
|
245132
|
+
}
|
|
244763
245133
|
}
|
|
244764
245134
|
const texts = [];
|
|
244765
245135
|
forEachNode(program, (node) => {
|
|
@@ -244786,6 +245156,59 @@ function checkUnknownStateVars(program, filePath, diags) {
|
|
|
244786
245156
|
"null",
|
|
244787
245157
|
"undefined"
|
|
244788
245158
|
]);
|
|
245159
|
+
const EVALUABLE_METHODS = /* @__PURE__ */ new Set([
|
|
245160
|
+
"length",
|
|
245161
|
+
"toUpperCase",
|
|
245162
|
+
"toLowerCase",
|
|
245163
|
+
"trim",
|
|
245164
|
+
"trimStart",
|
|
245165
|
+
"trimEnd",
|
|
245166
|
+
"slice",
|
|
245167
|
+
"substring",
|
|
245168
|
+
"substr",
|
|
245169
|
+
"charAt",
|
|
245170
|
+
"at",
|
|
245171
|
+
"includes",
|
|
245172
|
+
"indexOf",
|
|
245173
|
+
"lastIndexOf",
|
|
245174
|
+
"startsWith",
|
|
245175
|
+
"endsWith",
|
|
245176
|
+
"replace",
|
|
245177
|
+
"replaceAll",
|
|
245178
|
+
"split",
|
|
245179
|
+
"join",
|
|
245180
|
+
"concat",
|
|
245181
|
+
"repeat",
|
|
245182
|
+
"padStart",
|
|
245183
|
+
"padEnd",
|
|
245184
|
+
"toString",
|
|
245185
|
+
"toFixed",
|
|
245186
|
+
"map",
|
|
245187
|
+
"filter",
|
|
245188
|
+
"find",
|
|
245189
|
+
"some",
|
|
245190
|
+
"every",
|
|
245191
|
+
"reduce",
|
|
245192
|
+
"sort",
|
|
245193
|
+
"reverse",
|
|
245194
|
+
"stringify",
|
|
245195
|
+
"parse",
|
|
245196
|
+
"keys",
|
|
245197
|
+
"values",
|
|
245198
|
+
"entries",
|
|
245199
|
+
"from",
|
|
245200
|
+
"isArray",
|
|
245201
|
+
"round",
|
|
245202
|
+
"floor",
|
|
245203
|
+
"ceil",
|
|
245204
|
+
"abs",
|
|
245205
|
+
"max",
|
|
245206
|
+
"min",
|
|
245207
|
+
"pow",
|
|
245208
|
+
"sqrt",
|
|
245209
|
+
"random",
|
|
245210
|
+
"now"
|
|
245211
|
+
]);
|
|
244789
245212
|
for (const node of texts) {
|
|
244790
245213
|
const text = String(node.value ?? "");
|
|
244791
245214
|
if (!text.includes("{")) continue;
|
|
@@ -244801,6 +245224,22 @@ function checkUnknownStateVars(program, filePath, diags) {
|
|
|
244801
245224
|
[`Declare it in the state block, or check the spelling`]
|
|
244802
245225
|
));
|
|
244803
245226
|
}
|
|
245227
|
+
for (const m of text.matchAll(/\{([^{}]+)\}/g)) {
|
|
245228
|
+
const expr = m[1].trim();
|
|
245229
|
+
if (/^[A-Za-z_$][\w$]*$/.test(expr)) continue;
|
|
245230
|
+
for (const c of expr.matchAll(/([A-Za-z_$][\w$]*)\s*\(/g)) {
|
|
245231
|
+
const fn = c[1];
|
|
245232
|
+
if (known.has(fn) || BUILTINS2.has(fn) || EVALUABLE_METHODS.has(fn)) continue;
|
|
245233
|
+
diags.push(createDiagnostic(
|
|
245234
|
+
"TW098",
|
|
245235
|
+
node.line,
|
|
245236
|
+
node.col,
|
|
245237
|
+
filePath,
|
|
245238
|
+
`{${expr}}`,
|
|
245239
|
+
[`Cannot evaluate this at build time -- it renders as its source. Check the name, or simplify the expression`]
|
|
245240
|
+
));
|
|
245241
|
+
}
|
|
245242
|
+
}
|
|
244804
245243
|
}
|
|
244805
245244
|
}
|
|
244806
245245
|
function checkWhileComparisons(program, filePath, diags) {
|
|
@@ -244833,7 +245272,28 @@ function checkDeprecatedImports(program, filePath, diags) {
|
|
|
244833
245272
|
}
|
|
244834
245273
|
}
|
|
244835
245274
|
}
|
|
244836
|
-
|
|
245275
|
+
function checkDuplicateDefaultSlots(program, filePath, diags) {
|
|
245276
|
+
let count = 0;
|
|
245277
|
+
let first = null;
|
|
245278
|
+
forEachNode(program, (node) => {
|
|
245279
|
+
if (!node || node.type !== "Slot") return;
|
|
245280
|
+
const name = String(node.name ?? "default");
|
|
245281
|
+
if (name !== "default") return;
|
|
245282
|
+
count++;
|
|
245283
|
+
if (!first) first = node;
|
|
245284
|
+
});
|
|
245285
|
+
if (count > 1 && first) {
|
|
245286
|
+
diags.push(createDiagnostic(
|
|
245287
|
+
"TW122",
|
|
245288
|
+
first.line ?? 1,
|
|
245289
|
+
first.col ?? 1,
|
|
245290
|
+
filePath,
|
|
245291
|
+
`${count} default slots`,
|
|
245292
|
+
["Keep one default slot -- a caller's default content has no defined destination with two"]
|
|
245293
|
+
));
|
|
245294
|
+
}
|
|
245295
|
+
}
|
|
245296
|
+
var HTML_ELEMENTS2, HTML_ATTRIBUTES2, GLOBAL_ATTRIBUTES2, CSS_PROPERTIES2, CSS_ALIASES2, EVENT_TYPES2, ARIA_ROLES2, ARIA_ATTRIBUTES2, BUILTIN_COMPONENT_TAGS, DEPRECATED_IMPORTS;
|
|
244837
245297
|
var init_rules = __esm({
|
|
244838
245298
|
"../../packages/compiler/tw/diagnostics/rules.ts"() {
|
|
244839
245299
|
init_visitors();
|
|
@@ -245697,6 +246157,7 @@ var init_rules = __esm({
|
|
|
245697
246157
|
"aria-valuenow",
|
|
245698
246158
|
"aria-valuetext"
|
|
245699
246159
|
]);
|
|
246160
|
+
BUILTIN_COMPONENT_TAGS = /* @__PURE__ */ new Set(["optImage", "twImage", "twLink", "twImg"]);
|
|
245700
246161
|
DEPRECATED_IMPORTS = [
|
|
245701
246162
|
{ source: "utils/string/transform", name: "toHex", replacement: "stringToHex", removal: "2.1.0" },
|
|
245702
246163
|
{ source: "utils/string/transform", name: "fromHex", replacement: "hexToString", removal: "2.1.0" },
|
|
@@ -245740,6 +246201,7 @@ function diagnose(program, filePath) {
|
|
|
245740
246201
|
checkLoopIterables(program, filePath, diagnostics);
|
|
245741
246202
|
checkUnknownStateVars(program, filePath, diagnostics);
|
|
245742
246203
|
checkWhileComparisons(program, filePath, diagnostics);
|
|
246204
|
+
checkDuplicateDefaultSlots(program, filePath, diagnostics);
|
|
245743
246205
|
return diagnostics;
|
|
245744
246206
|
}
|
|
245745
246207
|
var RuleEngine;
|
|
@@ -248096,6 +248558,28 @@ function lintSsrf(body) {
|
|
|
248096
248558
|
while (m = re.exec(body)) out.push("fetch(<dynamic url>)");
|
|
248097
248559
|
const concat = /fetch\s*\(\s*[^,)]*\b(params|query|headers|cookies)\b[^,)]*\+/g;
|
|
248098
248560
|
while (m = concat.exec(body)) out.push("fetch(<concatenated url>)");
|
|
248561
|
+
const TAINTED_ROOT = /\b(params|query|headers|cookies)\b/;
|
|
248562
|
+
const tainted = /* @__PURE__ */ new Set();
|
|
248563
|
+
for (let pass = 0; pass < 5; pass++) {
|
|
248564
|
+
let grew = false;
|
|
248565
|
+
const assign = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*([^;\n]+)/g;
|
|
248566
|
+
let a;
|
|
248567
|
+
while (a = assign.exec(body)) {
|
|
248568
|
+
const [, name, rhs] = a;
|
|
248569
|
+
if (tainted.has(name)) continue;
|
|
248570
|
+
const fromRoot = TAINTED_ROOT.test(rhs);
|
|
248571
|
+
const fromTainted = [...tainted].some((t3) => new RegExp("\\b" + t3 + "\\b").test(rhs));
|
|
248572
|
+
if (fromRoot || fromTainted) {
|
|
248573
|
+
tainted.add(name);
|
|
248574
|
+
grew = true;
|
|
248575
|
+
}
|
|
248576
|
+
}
|
|
248577
|
+
if (!grew) break;
|
|
248578
|
+
}
|
|
248579
|
+
for (const name of tainted) {
|
|
248580
|
+
const use = new RegExp("fetch\\s*\\(\\s*[^,)]*\\b" + name + "\\b[^,)]*[,)]", "g");
|
|
248581
|
+
if (use.test(body)) out.push("fetch(<request-derived url>)");
|
|
248582
|
+
}
|
|
248099
248583
|
return out;
|
|
248100
248584
|
}
|
|
248101
248585
|
var ts2, ServerSerializationError, MAX_DEPTH;
|
|
@@ -248198,6 +248682,36 @@ function serverStateCollisions(program) {
|
|
|
248198
248682
|
}
|
|
248199
248683
|
return out;
|
|
248200
248684
|
}
|
|
248685
|
+
function checkDeclarationConflicts(program, paramNames = []) {
|
|
248686
|
+
const out = [];
|
|
248687
|
+
const params = new Set(paramNames);
|
|
248688
|
+
const seen = /* @__PURE__ */ new Set();
|
|
248689
|
+
for (const d of program.directives ?? []) {
|
|
248690
|
+
if (d.type !== "StateDirective") continue;
|
|
248691
|
+
for (const decl of d.declarations ?? []) {
|
|
248692
|
+
const name = String(decl.name ?? "");
|
|
248693
|
+
if (!name) continue;
|
|
248694
|
+
if (params.has(name)) {
|
|
248695
|
+
out.push({
|
|
248696
|
+
code: "TW102",
|
|
248697
|
+
message: `state declares '${name}', which collides with the route param '${name}' -- the param overwrites the state value`,
|
|
248698
|
+
line: decl.line ?? d.line ?? 1,
|
|
248699
|
+
col: decl.col ?? d.col ?? 1
|
|
248700
|
+
});
|
|
248701
|
+
}
|
|
248702
|
+
if (seen.has(name)) {
|
|
248703
|
+
out.push({
|
|
248704
|
+
code: "TW121",
|
|
248705
|
+
message: `'${name}' is declared by more than one state { } block -- the earlier declaration wins and this one is dead`,
|
|
248706
|
+
line: decl.line ?? d.line ?? 1,
|
|
248707
|
+
col: decl.col ?? d.col ?? 1
|
|
248708
|
+
});
|
|
248709
|
+
}
|
|
248710
|
+
seen.add(name);
|
|
248711
|
+
}
|
|
248712
|
+
}
|
|
248713
|
+
return out;
|
|
248714
|
+
}
|
|
248201
248715
|
function serverRouteParamCollisions(blocks, paramNames) {
|
|
248202
248716
|
const params = new Set(paramNames);
|
|
248203
248717
|
const out = [];
|
|
@@ -248435,7 +248949,14 @@ function checkServerBlocks(program, opts = {}) {
|
|
|
248435
248949
|
const blocks = collectServerBlocks(program);
|
|
248436
248950
|
if (!blocks.length) return [];
|
|
248437
248951
|
const out = [];
|
|
248438
|
-
const push = (code, message, line, col) => out.push({
|
|
248952
|
+
const push = (code, message, line, col) => out.push({
|
|
248953
|
+
severity: ERROR_CODES[code]?.severity === "warning" ? "warning" : "error",
|
|
248954
|
+
code,
|
|
248955
|
+
message,
|
|
248956
|
+
line,
|
|
248957
|
+
col,
|
|
248958
|
+
category: "semantic"
|
|
248959
|
+
});
|
|
248439
248960
|
if (opts.isLayout) {
|
|
248440
248961
|
for (const b of blocks) push("TW105", "server blocks in layouts are not supported yet", b.line, b.col);
|
|
248441
248962
|
return out;
|
|
@@ -248613,6 +249134,7 @@ function parsePageCache(source) {
|
|
|
248613
249134
|
var ts3, REQUEST_IDENTIFIERS, SERVER_REDIRECT_BRAND, SERVER_NOT_FOUND_BRAND, ServerRedirect, ServerNotFound, isServerRedirect, isServerNotFound, DEFAULT_SERVER_BLOCK_TIMEOUT_MS;
|
|
248614
249135
|
var init_server_blocks = __esm({
|
|
248615
249136
|
"../../packages/compiler/tw/server-blocks/index.ts"() {
|
|
249137
|
+
init_codes();
|
|
248616
249138
|
init_serialize();
|
|
248617
249139
|
ts3 = __toESM(require_typescript(), 1);
|
|
248618
249140
|
REQUEST_IDENTIFIERS = /* @__PURE__ */ new Set(["headers", "cookies", "query", "params"]);
|
|
@@ -255333,6 +255855,7 @@ __export(tw_exports2, {
|
|
|
255333
255855
|
canonicalVaryQuery: () => canonicalVaryQuery,
|
|
255334
255856
|
charCode: () => charCode,
|
|
255335
255857
|
check: () => check,
|
|
255858
|
+
checkDeclarationConflicts: () => checkDeclarationConflicts,
|
|
255336
255859
|
checkServerBlocks: () => checkServerBlocks,
|
|
255337
255860
|
chunksToHTML: () => chunksToHTML,
|
|
255338
255861
|
clearComponentRegistry: () => clearComponentRegistry,
|
|
@@ -256009,7 +256532,8 @@ function genOpts(opts, scopeId) {
|
|
|
256009
256532
|
scopedStyles: opts?.compiler?.scopedStyles,
|
|
256010
256533
|
scopeId,
|
|
256011
256534
|
cssPrefix: opts?.cssPrefix,
|
|
256012
|
-
cssImportPaths: opts?.cssImportPaths
|
|
256535
|
+
cssImportPaths: opts?.cssImportPaths,
|
|
256536
|
+
imports: opts?.imports
|
|
256013
256537
|
};
|
|
256014
256538
|
}
|
|
256015
256539
|
function scopeIdFor(filePath) {
|
|
@@ -256283,7 +256807,7 @@ __export(twm_rules_exports, {
|
|
|
256283
256807
|
isRuleDsl: () => isRuleDsl,
|
|
256284
256808
|
parseRules: () => parseRules
|
|
256285
256809
|
});
|
|
256286
|
-
import { createHmac, timingSafeEqual as
|
|
256810
|
+
import { createHmac as createHmac2, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
256287
256811
|
function isRuleDsl(source) {
|
|
256288
256812
|
const stripped = source.split("\n").map((l) => l.replace(/\/\/.*$/, "").trim()).filter((l) => l.length > 0).join("\n");
|
|
256289
256813
|
return stripped.startsWith('rule "') || stripped.startsWith("rule '");
|
|
@@ -256381,14 +256905,14 @@ function verifyJwt_hs256(token, secret) {
|
|
|
256381
256905
|
return false;
|
|
256382
256906
|
}
|
|
256383
256907
|
if (header?.alg !== "HS256") return false;
|
|
256384
|
-
const expected =
|
|
256908
|
+
const expected = createHmac2("sha256", secret).update(`${h3}.${p}`).digest();
|
|
256385
256909
|
let got;
|
|
256386
256910
|
try {
|
|
256387
256911
|
got = b64urlDecode(sig);
|
|
256388
256912
|
} catch {
|
|
256389
256913
|
return false;
|
|
256390
256914
|
}
|
|
256391
|
-
if (expected.length !== got.length || !
|
|
256915
|
+
if (expected.length !== got.length || !timingSafeEqual2(expected, got)) return false;
|
|
256392
256916
|
if (typeof payload?.exp === "number" && payload.exp * 1e3 < Date.now()) return false;
|
|
256393
256917
|
return true;
|
|
256394
256918
|
}
|
|
@@ -256764,6 +257288,32 @@ var init_twm_rules = __esm({
|
|
|
256764
257288
|
});
|
|
256765
257289
|
|
|
256766
257290
|
// ../../packages/runtime/tw/dependency-graph.ts
|
|
257291
|
+
function flushPendingSubs() {
|
|
257292
|
+
if (isFlushing || !pendingSubs) return;
|
|
257293
|
+
isFlushing = true;
|
|
257294
|
+
try {
|
|
257295
|
+
let guard = 0;
|
|
257296
|
+
while (pendingSubs && pendingSubs.size > 0 && guard++ < 1e5) {
|
|
257297
|
+
const batchOf = pendingSubs;
|
|
257298
|
+
pendingSubs = /* @__PURE__ */ new Set();
|
|
257299
|
+
for (const sub of batchOf) {
|
|
257300
|
+
try {
|
|
257301
|
+
sub();
|
|
257302
|
+
} catch (e) {
|
|
257303
|
+
console.error("[TW Reactivity] Signal subscriber error:", e);
|
|
257304
|
+
}
|
|
257305
|
+
}
|
|
257306
|
+
}
|
|
257307
|
+
} finally {
|
|
257308
|
+
isFlushing = false;
|
|
257309
|
+
pendingSubs = null;
|
|
257310
|
+
}
|
|
257311
|
+
}
|
|
257312
|
+
function enqueueSubs(subs) {
|
|
257313
|
+
if (!pendingSubs) pendingSubs = /* @__PURE__ */ new Set();
|
|
257314
|
+
for (const s of subs) pendingSubs.add(s);
|
|
257315
|
+
if (batchDepth === 0) flushPendingSubs();
|
|
257316
|
+
}
|
|
256767
257317
|
function startBatch() {
|
|
256768
257318
|
batchDepth++;
|
|
256769
257319
|
}
|
|
@@ -256773,13 +257323,7 @@ function endBatch() {
|
|
|
256773
257323
|
batchDepth = 0;
|
|
256774
257324
|
const effects = Array.from(batchedEffects);
|
|
256775
257325
|
batchedEffects.clear();
|
|
256776
|
-
|
|
256777
|
-
try {
|
|
256778
|
-
eff();
|
|
256779
|
-
} catch (e) {
|
|
256780
|
-
console.error("[TW Reactivity] Batch effect error:", e);
|
|
256781
|
-
}
|
|
256782
|
-
}
|
|
257326
|
+
enqueueSubs(effects);
|
|
256783
257327
|
}
|
|
256784
257328
|
}
|
|
256785
257329
|
function batch(fn) {
|
|
@@ -256961,12 +257505,14 @@ function isComputed(value) {
|
|
|
256961
257505
|
function createScope3() {
|
|
256962
257506
|
return new ReactiveScope();
|
|
256963
257507
|
}
|
|
256964
|
-
var currentEffect, batchDepth, batchedEffects, SignalImpl, ComputedImpl, watchEffect, currentCleanup, ReactiveScope;
|
|
257508
|
+
var currentEffect, batchDepth, batchedEffects, pendingSubs, isFlushing, SignalImpl, ComputedImpl, watchEffect, currentCleanup, ReactiveScope;
|
|
256965
257509
|
var init_dependency_graph = __esm({
|
|
256966
257510
|
"../../packages/runtime/tw/dependency-graph.ts"() {
|
|
256967
257511
|
currentEffect = null;
|
|
256968
257512
|
batchDepth = 0;
|
|
256969
257513
|
batchedEffects = /* @__PURE__ */ new Set();
|
|
257514
|
+
pendingSubs = null;
|
|
257515
|
+
isFlushing = false;
|
|
256970
257516
|
SignalImpl = class {
|
|
256971
257517
|
value;
|
|
256972
257518
|
subscribers = /* @__PURE__ */ new Set();
|
|
@@ -256985,19 +257531,9 @@ var init_dependency_graph = __esm({
|
|
|
256985
257531
|
if (this.equals(this.value, value)) return;
|
|
256986
257532
|
this.value = value;
|
|
256987
257533
|
if (batchDepth > 0) {
|
|
256988
|
-
for (const sub of this.subscribers)
|
|
256989
|
-
batchedEffects.add(sub);
|
|
256990
|
-
}
|
|
256991
|
-
} else {
|
|
256992
|
-
const subs = Array.from(this.subscribers);
|
|
256993
|
-
for (const sub of subs) {
|
|
256994
|
-
try {
|
|
256995
|
-
sub();
|
|
256996
|
-
} catch (e) {
|
|
256997
|
-
console.error("[TW Reactivity] Signal subscriber error:", e);
|
|
256998
|
-
}
|
|
256999
|
-
}
|
|
257534
|
+
for (const sub of this.subscribers) batchedEffects.add(sub);
|
|
257000
257535
|
}
|
|
257536
|
+
enqueueSubs(this.subscribers);
|
|
257001
257537
|
}
|
|
257002
257538
|
update(fn) {
|
|
257003
257539
|
this.set(fn(this.value));
|
|
@@ -257063,14 +257599,11 @@ var init_dependency_graph = __esm({
|
|
|
257063
257599
|
return this.cachedValue;
|
|
257064
257600
|
}
|
|
257065
257601
|
notify() {
|
|
257066
|
-
|
|
257067
|
-
|
|
257068
|
-
|
|
257069
|
-
sub();
|
|
257070
|
-
} catch (e) {
|
|
257071
|
-
console.error("[TW Reactivity] Computed subscriber error:", e);
|
|
257072
|
-
}
|
|
257602
|
+
if (batchDepth > 0) {
|
|
257603
|
+
for (const sub of this.subscribers) batchedEffects.add(sub);
|
|
257604
|
+
return;
|
|
257073
257605
|
}
|
|
257606
|
+
enqueueSubs(this.subscribers);
|
|
257074
257607
|
}
|
|
257075
257608
|
set(_value) {
|
|
257076
257609
|
throw new Error("Cannot set a computed signal");
|
|
@@ -260255,10 +260788,12 @@ var init_diff = __esm({
|
|
|
260255
260788
|
"../../packages/runtime/tw/diff.ts"() {
|
|
260256
260789
|
init_vdom2();
|
|
260257
260790
|
HTML_ESCAPE_MAP = {
|
|
260258
|
-
|
|
260259
|
-
|
|
260260
|
-
"
|
|
260261
|
-
|
|
260791
|
+
// These four mapped to THEMSELVES, so a <script> tag passed through
|
|
260792
|
+
// untouched -- only ' was actually escaped.
|
|
260793
|
+
"&": "&",
|
|
260794
|
+
"<": "<",
|
|
260795
|
+
">": ">",
|
|
260796
|
+
'"': """,
|
|
260262
260797
|
"'": "'"
|
|
260263
260798
|
};
|
|
260264
260799
|
HTML_ESCAPE_REGEX = /[&<>"']/g;
|
|
@@ -263788,8 +264323,19 @@ async function hydrateElementById(id, component, root = typeof document !== "und
|
|
|
263788
264323
|
);
|
|
263789
264324
|
}
|
|
263790
264325
|
function markForHydration(element, componentId, props) {
|
|
264326
|
+
if (!element || typeof componentId !== "string") return;
|
|
263791
264327
|
element.setAttribute(HYDRATE_ATTR, componentId);
|
|
263792
|
-
|
|
264328
|
+
let serialised = null;
|
|
264329
|
+
if (props && typeof props === "object") {
|
|
264330
|
+
try {
|
|
264331
|
+
serialised = JSON.stringify(props);
|
|
264332
|
+
} catch {
|
|
264333
|
+
serialised = null;
|
|
264334
|
+
}
|
|
264335
|
+
}
|
|
264336
|
+
if (serialised !== null && serialised !== void 0) {
|
|
264337
|
+
element.setAttribute("data-tw-props", serialised);
|
|
264338
|
+
}
|
|
263793
264339
|
}
|
|
263794
264340
|
function unmarkForHydration(element) {
|
|
263795
264341
|
element.removeAttribute(HYDRATE_ATTR);
|
|
@@ -267089,15 +267635,21 @@ function usePathname(opts) {
|
|
|
267089
267635
|
function matchPathPattern(path, pattern) {
|
|
267090
267636
|
const pSeg = path.split("/").filter(Boolean);
|
|
267091
267637
|
const tSeg = pattern.split("/").filter(Boolean);
|
|
267092
|
-
|
|
267638
|
+
const catchAllAt = tSeg.findIndex((t3) => t3.startsWith("[...") || t3.startsWith(":..."));
|
|
267639
|
+
if (catchAllAt === -1) {
|
|
267640
|
+
if (pSeg.length !== tSeg.length) return { matches: false, params: {}, score: 0 };
|
|
267641
|
+
} else if (pSeg.length < tSeg.length) {
|
|
267642
|
+
return { matches: false, params: {}, score: 0 };
|
|
267643
|
+
}
|
|
267093
267644
|
const params = {};
|
|
267094
267645
|
let literal = 0;
|
|
267095
267646
|
for (let i = 0; i < tSeg.length; i++) {
|
|
267096
267647
|
const t3 = tSeg[i];
|
|
267097
267648
|
const isParam = t3.startsWith("[") && t3.endsWith("]") || t3.startsWith(":");
|
|
267098
267649
|
if (isParam) {
|
|
267099
|
-
const name = t3.startsWith("[") ? t3.slice(1, -1).replace(
|
|
267100
|
-
|
|
267650
|
+
const name = t3.startsWith("[") ? t3.slice(1, -1).replace(/^\.\.\./, "") : t3.slice(1);
|
|
267651
|
+
const isCatchAll = t3.startsWith("[...") || t3.startsWith(":...");
|
|
267652
|
+
params[name] = isCatchAll ? pSeg.slice(i).map((seg) => decodeURIComponent(seg)).join("/") : decodeURIComponent(pSeg[i]);
|
|
267101
267653
|
} else if (t3 !== pSeg[i]) {
|
|
267102
267654
|
return { matches: false, params: {}, score: 0 };
|
|
267103
267655
|
} else {
|
|
@@ -267912,7 +268464,11 @@ function defineStore(idOrDefinition, maybeDefinition) {
|
|
|
267912
268464
|
const getterDeps = Object.values(reactiveState);
|
|
267913
268465
|
for (const key2 of Object.keys(getters)) {
|
|
267914
268466
|
const getter = getters[key2];
|
|
267915
|
-
getterValues[key2] = computed4(getterDeps,
|
|
268467
|
+
getterValues[key2] = computed4(getterDeps, () => {
|
|
268468
|
+
const snap = {};
|
|
268469
|
+
for (const k of Object.keys(reactiveState)) snap[k] = reactiveState[k].value;
|
|
268470
|
+
return getter.call(snap, snap);
|
|
268471
|
+
});
|
|
267916
268472
|
}
|
|
267917
268473
|
const subscribers = /* @__PURE__ */ new Set();
|
|
267918
268474
|
const actionListeners = /* @__PURE__ */ new Set();
|
|
@@ -267937,9 +268493,41 @@ function defineStore(idOrDefinition, maybeDefinition) {
|
|
|
267937
268493
|
return () => set.delete(cb);
|
|
267938
268494
|
}
|
|
267939
268495
|
};
|
|
268496
|
+
const MUTATORS = /* @__PURE__ */ new Set(["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"]);
|
|
268497
|
+
const tracking = /* @__PURE__ */ new WeakMap();
|
|
268498
|
+
const track2 = (value, prop) => {
|
|
268499
|
+
if (value === null || typeof value !== "object") return value;
|
|
268500
|
+
const existing2 = tracking.get(value);
|
|
268501
|
+
if (existing2) return existing2;
|
|
268502
|
+
const wrapped = new Proxy(value, {
|
|
268503
|
+
get(t3, key2, recv) {
|
|
268504
|
+
const v = Reflect.get(t3, key2, recv);
|
|
268505
|
+
if (typeof v === "function" && MUTATORS.has(String(key2))) {
|
|
268506
|
+
return (...args) => {
|
|
268507
|
+
const out = v.apply(t3, args);
|
|
268508
|
+
reactiveState[prop]?.touch();
|
|
268509
|
+
return out;
|
|
268510
|
+
};
|
|
268511
|
+
}
|
|
268512
|
+
return v;
|
|
268513
|
+
},
|
|
268514
|
+
set(t3, key2, v) {
|
|
268515
|
+
const ok2 = Reflect.set(t3, key2, v);
|
|
268516
|
+
reactiveState[prop]?.touch();
|
|
268517
|
+
return ok2;
|
|
268518
|
+
},
|
|
268519
|
+
deleteProperty(t3, key2) {
|
|
268520
|
+
const ok2 = Reflect.deleteProperty(t3, key2);
|
|
268521
|
+
reactiveState[prop]?.touch();
|
|
268522
|
+
return ok2;
|
|
268523
|
+
}
|
|
268524
|
+
});
|
|
268525
|
+
tracking.set(value, wrapped);
|
|
268526
|
+
return wrapped;
|
|
268527
|
+
};
|
|
267940
268528
|
const stateProxy = new Proxy({}, {
|
|
267941
268529
|
get(_target, prop) {
|
|
267942
|
-
return reactiveState[prop]?.value;
|
|
268530
|
+
return track2(reactiveState[prop]?.value, prop);
|
|
267943
268531
|
},
|
|
267944
268532
|
set(_target, prop, value) {
|
|
267945
268533
|
if (reactiveState[prop]) {
|
|
@@ -267955,7 +268543,7 @@ function defineStore(idOrDefinition, maybeDefinition) {
|
|
|
267955
268543
|
const fn = actions[key2];
|
|
267956
268544
|
boundActions[key2] = (...args) => {
|
|
267957
268545
|
actionListeners.forEach((cb) => cb({ name: key2, args }));
|
|
267958
|
-
return fn.call(
|
|
268546
|
+
return fn.call(stateProxy, stateProxy, ...args);
|
|
267959
268547
|
};
|
|
267960
268548
|
}
|
|
267961
268549
|
for (const rv of Object.values(reactiveState)) {
|
|
@@ -268060,6 +268648,14 @@ var init_store = __esm({
|
|
|
268060
268648
|
update(updater) {
|
|
268061
268649
|
this.set(updater(this._value));
|
|
268062
268650
|
}
|
|
268651
|
+
/**
|
|
268652
|
+
* Re-notify subscribers without replacing the value. An array or object that
|
|
268653
|
+
* was mutated in place (`this.items.push(x)`) has the same identity, so
|
|
268654
|
+
* `set()` short-circuits and nothing downstream hears about it.
|
|
268655
|
+
*/
|
|
268656
|
+
touch() {
|
|
268657
|
+
this._notify();
|
|
268658
|
+
}
|
|
268063
268659
|
subscribe(listener) {
|
|
268064
268660
|
this._listeners.add(listener);
|
|
268065
268661
|
return () => {
|
|
@@ -268067,9 +268663,10 @@ var init_store = __esm({
|
|
|
268067
268663
|
};
|
|
268068
268664
|
}
|
|
268069
268665
|
_notify() {
|
|
268666
|
+
const current2 = this.value ?? this._value;
|
|
268070
268667
|
for (const l of this._listeners) {
|
|
268071
268668
|
try {
|
|
268072
|
-
l();
|
|
268669
|
+
l(current2);
|
|
268073
268670
|
} catch {
|
|
268074
268671
|
}
|
|
268075
268672
|
}
|
|
@@ -269075,7 +269672,8 @@ var init_virtual_list = __esm({
|
|
|
269075
269672
|
return this.container.scrollTop;
|
|
269076
269673
|
}
|
|
269077
269674
|
getFirstVisibleIndex() {
|
|
269078
|
-
|
|
269675
|
+
const last = Math.max(0, (this.options?.itemCount ?? 0) - 1);
|
|
269676
|
+
return Math.min(Math.max(this.visibleRange.start, 0), last);
|
|
269079
269677
|
}
|
|
269080
269678
|
getLastVisibleIndex() {
|
|
269081
269679
|
return this.visibleRange.end;
|
|
@@ -271924,6 +272522,12 @@ var init_xss_detector = __esm({
|
|
|
271924
272522
|
{ name: "SQL comment", regex: /--\s/g, severity: "medium", recommendation: "Check for SQL comment injection" },
|
|
271925
272523
|
{ name: "Stacked queries", regex: /;\s*(SELECT|INSERT|UPDATE|DELETE|DROP|UNION)/gi, severity: "high", recommendation: "Prevent stacked queries" },
|
|
271926
272524
|
{ name: "UNION injection", regex: /UNION\s+SELECT/gi, severity: "critical", recommendation: "Filter UNION SELECT from user input" },
|
|
272525
|
+
// Comment-only injections (`admin'--`, `admin'#`, `admin'/*`): a quote
|
|
272526
|
+
// followed by a comment truncates the query and bypasses the login
|
|
272527
|
+
// check, with no OR/UNION for the other patterns to catch.
|
|
272528
|
+
{ name: "Comment-terminated injection", regex: /['"`]\s*(--|#|\/\*)/g, severity: "high", recommendation: "A quote followed by a comment truncates the query -- use parameterized queries" },
|
|
272529
|
+
// Parenthesised boolean injection: `') OR ('1'='1`.
|
|
272530
|
+
{ 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" },
|
|
271927
272531
|
{ name: "Boolean-based injection", regex: /OR\s+1\s*=\s*1/gi, severity: "high", recommendation: "Use parameterized queries to prevent boolean injection" },
|
|
271928
272532
|
{ name: "Time-based injection", regex: /WAITFOR\s+DELAY/gi, severity: "high", recommendation: "Filter WAITFOR DELAY from user input" },
|
|
271929
272533
|
{ name: "DROP statement", regex: /DROP\s+(TABLE|DATABASE)/gi, severity: "critical", recommendation: "Prevent DROP statements in queries" },
|
|
@@ -272454,6 +273058,7 @@ var init_logger4 = __esm({
|
|
|
272454
273058
|
}
|
|
272455
273059
|
/** Records an audit event. */
|
|
272456
273060
|
log(event) {
|
|
273061
|
+
event = { type: "system", actor: "unknown", resource: "unknown", ...event };
|
|
272457
273062
|
const fullEvent = {
|
|
272458
273063
|
...event,
|
|
272459
273064
|
id: crypto.randomUUID(),
|
|
@@ -273470,6 +274075,13 @@ var FILE_SIGNATURES, DANGEROUS_EXTENSIONS, DANGEROUS_MIME_TYPES, ContentSecurity
|
|
|
273470
274075
|
var init_protector = __esm({
|
|
273471
274076
|
"../../packages/security/tw/content-security/protector.ts"() {
|
|
273472
274077
|
FILE_SIGNATURES = [
|
|
274078
|
+
// Executables and HTML: without these, content renamed to an image extension
|
|
274079
|
+
// had no detected type, the signature check was skipped, and the upload was
|
|
274080
|
+
// accepted as risk "low" -- the exact rename bypass the check exists for.
|
|
274081
|
+
{ ext: ["exe", "dll", "sys"], mime: "application/x-msdownload", signature: [77, 90] },
|
|
274082
|
+
{ ext: ["elf", "so", "bin"], mime: "application/x-executable", signature: [127, 69, 76, 70] },
|
|
274083
|
+
{ ext: ["html", "htm", "xhtml"], mime: "text/html", signature: [60, 104, 116, 109, 108] },
|
|
274084
|
+
{ ext: ["html", "htm"], mime: "text/html", signature: [60, 33, 68, 79, 67, 84, 89, 80, 69] },
|
|
273473
274085
|
{ ext: ["jpg", "jpeg"], mime: "image/jpeg", signature: [255, 216, 255] },
|
|
273474
274086
|
{ ext: ["png"], mime: "image/png", signature: [137, 80, 78, 71, 13, 10, 26, 10] },
|
|
273475
274087
|
{ ext: ["gif"], mime: "image/gif", signature: [71, 73, 70, 56] },
|
|
@@ -273521,10 +274133,39 @@ var init_protector = __esm({
|
|
|
273521
274133
|
".htpasswd",
|
|
273522
274134
|
".svg",
|
|
273523
274135
|
// Can contain JavaScript
|
|
273524
|
-
".xml"
|
|
274136
|
+
".xml",
|
|
273525
274137
|
// Can contain XXE
|
|
274138
|
+
// Active-content types the set used to let through while still blocking .svg
|
|
274139
|
+
// "because it can contain JavaScript" -- .html/.js are script-capable by
|
|
274140
|
+
// definition, so an accepted upload served from our own origin is stored XSS.
|
|
274141
|
+
".html",
|
|
274142
|
+
".htm",
|
|
274143
|
+
".xhtml",
|
|
274144
|
+
".shtml",
|
|
274145
|
+
".js",
|
|
274146
|
+
".mjs",
|
|
274147
|
+
".cjs",
|
|
274148
|
+
".jsx",
|
|
274149
|
+
".ts",
|
|
274150
|
+
".tsx",
|
|
274151
|
+
".mhtml",
|
|
274152
|
+
".hta",
|
|
274153
|
+
".jsp",
|
|
274154
|
+
".asp",
|
|
274155
|
+
".aspx",
|
|
274156
|
+
".cgi",
|
|
274157
|
+
".pl"
|
|
273526
274158
|
]);
|
|
273527
274159
|
DANGEROUS_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
274160
|
+
// Active-content types: they can carry script (svg, xhtml, xml) or be
|
|
274161
|
+
// rendered as a document (html, pdf). Blocking .svg by extension while
|
|
274162
|
+
// reporting isContentTypeSafe("image/svg+xml") === true was inconsistent.
|
|
274163
|
+
"image/svg+xml",
|
|
274164
|
+
"text/html",
|
|
274165
|
+
"application/xhtml+xml",
|
|
274166
|
+
"application/pdf",
|
|
274167
|
+
"text/xml",
|
|
274168
|
+
"application/xml",
|
|
273528
274169
|
"application/javascript",
|
|
273529
274170
|
"text/javascript",
|
|
273530
274171
|
"application/x-javascript",
|
|
@@ -273579,7 +274220,9 @@ var init_protector = __esm({
|
|
|
273579
274220
|
reason: "Empty file",
|
|
273580
274221
|
sanitizedFilename: sanitized,
|
|
273581
274222
|
detectedType: "unknown",
|
|
273582
|
-
risk
|
|
274223
|
+
// Unknown content is not low risk -- it is content whose type we could
|
|
274224
|
+
// not establish, which is what a rename bypass looks like.
|
|
274225
|
+
risk: "medium"
|
|
273583
274226
|
};
|
|
273584
274227
|
}
|
|
273585
274228
|
if (this.blockedExtensions.has(ext)) {
|
|
@@ -274742,6 +275385,7 @@ var init_nonce_manager = __esm({
|
|
|
274742
275385
|
validate(nonce) {
|
|
274743
275386
|
const entry = this.nonces.get(nonce);
|
|
274744
275387
|
if (!entry) return false;
|
|
275388
|
+
if (entry.used) return false;
|
|
274745
275389
|
if (Date.now() > entry.expiresAt) {
|
|
274746
275390
|
this.nonces.delete(nonce);
|
|
274747
275391
|
return false;
|
|
@@ -275534,7 +276178,15 @@ var init_token_manager = __esm({
|
|
|
275534
276178
|
rotateAfterUse;
|
|
275535
276179
|
maxTokens;
|
|
275536
276180
|
tokens = /* @__PURE__ */ new Map();
|
|
276181
|
+
/** Tokens this manager issued and already consumed. A rotated token is
|
|
276182
|
+
* deleted from `tokens`, so without this marker a replay found no entry and
|
|
276183
|
+
* fell through to the stateless branch, which accepted it -- defeating the
|
|
276184
|
+
* documented single-use guarantee of `rotateAfterUse`. */
|
|
276185
|
+
consumedTokens = /* @__PURE__ */ new Set();
|
|
275537
276186
|
constructor(options) {
|
|
276187
|
+
if (!options || typeof options.secret !== "string" || options.secret.length === 0) {
|
|
276188
|
+
throw new Error("createCSRFManager: options.secret is required (the HMAC key used to sign tokens)");
|
|
276189
|
+
}
|
|
275538
276190
|
this.secret = options.secret;
|
|
275539
276191
|
this.tokenLength = options.tokenLength ?? 32;
|
|
275540
276192
|
this.ttl = options.ttl ?? 36e5;
|
|
@@ -275634,12 +276286,16 @@ var init_token_manager = __esm({
|
|
|
275634
276286
|
}
|
|
275635
276287
|
entry.used = true;
|
|
275636
276288
|
if (this.rotateAfterUse) {
|
|
276289
|
+
this.consumedTokens.add(headerPart);
|
|
275637
276290
|
this.tokens.delete(headerPart);
|
|
275638
276291
|
const rotated = await this.generate(sessionId ?? void 0);
|
|
275639
276292
|
return { valid: true, rotated };
|
|
275640
276293
|
}
|
|
275641
276294
|
return { valid: true };
|
|
275642
276295
|
}
|
|
276296
|
+
if (this.consumedTokens.has(headerPart)) {
|
|
276297
|
+
return { valid: false, reason: "Token already used" };
|
|
276298
|
+
}
|
|
275643
276299
|
const expectedSig = await hmacSign3(
|
|
275644
276300
|
this.secret,
|
|
275645
276301
|
`${headerPart}.${sessionId ?? ""}`
|
|
@@ -281709,6 +282365,26 @@ var init_render_pipeline = __esm({
|
|
|
281709
282365
|
};
|
|
281710
282366
|
}
|
|
281711
282367
|
console.error(`[tw] server block failed for ${pageFile}: ${err2?.message ?? err2}`);
|
|
282368
|
+
try {
|
|
282369
|
+
const errFile = ctx.error ?? findRootError(tree);
|
|
282370
|
+
if (errFile) {
|
|
282371
|
+
const compiled = this.compileFile(errFile);
|
|
282372
|
+
let eh = String(compiled.html || "");
|
|
282373
|
+
const em = eh.match(/<body[^>]*>([\s\S]*)<\/body>/i);
|
|
282374
|
+
eh = (em ? em[1] : eh).replace(/<\/?html[^>]*>/gi, "").replace(/<\/?body[^>]*>/gi, "");
|
|
282375
|
+
return {
|
|
282376
|
+
html: this.assembleHTML(eh, compiled.css, "", "Error"),
|
|
282377
|
+
css: "",
|
|
282378
|
+
js: "",
|
|
282379
|
+
status: 500,
|
|
282380
|
+
headers: { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "private, no-store" },
|
|
282381
|
+
fromCache: false,
|
|
282382
|
+
durationMs: 0,
|
|
282383
|
+
serverBlocks: true
|
|
282384
|
+
};
|
|
282385
|
+
}
|
|
282386
|
+
} catch {
|
|
282387
|
+
}
|
|
281712
282388
|
return {
|
|
281713
282389
|
html: "<!DOCTYPE html><html><head><title>Server Error</title></head><body><h1>Internal Server Error</h1></body></html>",
|
|
281714
282390
|
css: "",
|
|
@@ -281774,7 +282450,7 @@ var init_render_pipeline = __esm({
|
|
|
281774
282450
|
}
|
|
281775
282451
|
const match = matchRoute2(tree, pathname);
|
|
281776
282452
|
if (!match) {
|
|
281777
|
-
const rootNotFound =
|
|
282453
|
+
const rootNotFound = findNearestNotFound(tree, pathname.split("/").filter(Boolean));
|
|
281778
282454
|
if (rootNotFound) {
|
|
281779
282455
|
const compiled = this.compileFile(rootNotFound);
|
|
281780
282456
|
let nf = String(compiled.html || "");
|
|
@@ -281840,6 +282516,7 @@ var init_render_pipeline = __esm({
|
|
|
281840
282516
|
}
|
|
281841
282517
|
let bodyHTML = pageCompiled.html;
|
|
281842
282518
|
let allCSS = pageCompiled.css;
|
|
282519
|
+
const parallelSlots = [];
|
|
281843
282520
|
try {
|
|
281844
282521
|
const parentNode = match?.node;
|
|
281845
282522
|
if (parentNode && Array.isArray(parentNode.children)) {
|
|
@@ -281850,9 +282527,7 @@ var init_render_pipeline = __esm({
|
|
|
281850
282527
|
const sbm = slotBody.match(/<body[^>]*>([\s\S]*)<\/body>/i);
|
|
281851
282528
|
if (sbm) slotBody = sbm[1];
|
|
281852
282529
|
slotBody = slotBody.replace(/<\/?html[^>]*>/gi, "").replace(/<\/?body[^>]*>/gi, "");
|
|
281853
|
-
|
|
281854
|
-
const slotRe = new RegExp(`<${comp}(s[^>]*)?>([sS]*?)</${comp}>|<${comp}(s[^>]*)?/>`, "gi");
|
|
281855
|
-
bodyHTML = bodyHTML.replace(slotRe, slotBody);
|
|
282530
|
+
parallelSlots.push({ comp: slotName.charAt(0).toUpperCase() + slotName.slice(1), body: slotBody });
|
|
281856
282531
|
if (slotCompiled.css) allCSS = slotCompiled.css + "\n" + allCSS;
|
|
281857
282532
|
}
|
|
281858
282533
|
}
|
|
@@ -281871,6 +282546,11 @@ var init_render_pipeline = __esm({
|
|
|
281871
282546
|
allJS = templateCompiled.js + "\n" + allJS;
|
|
281872
282547
|
bodyHTML = this.wrapInLayout(templateCompiled.html, bodyHTML);
|
|
281873
282548
|
}
|
|
282549
|
+
for (const { comp, body } of parallelSlots) {
|
|
282550
|
+
const slotRe = new RegExp(`<${comp}(\\s[^>]*)?>([\\s\\S]*?)<\\/${comp}>|<${comp}(\\s[^>]*)?/>`, "gi");
|
|
282551
|
+
bodyHTML = bodyHTML.replace(slotRe, body);
|
|
282552
|
+
bodyHTML = bodyHTML.replace(new RegExp(`<!--\\s*TW: unknown component '${comp}'[\\s\\S]*?-->`, "gi"), body);
|
|
282553
|
+
}
|
|
281874
282554
|
let layoutTitle;
|
|
281875
282555
|
const liftedParts = [];
|
|
281876
282556
|
{
|
|
@@ -282289,8 +282969,6 @@ ${bodyHTML}`;
|
|
|
282289
282969
|
};
|
|
282290
282970
|
let tags = "";
|
|
282291
282971
|
const description = pick2("description");
|
|
282292
|
-
if (description) tags += ` <meta name="description" content="${esc4(description)}">
|
|
282293
|
-
`;
|
|
282294
282972
|
const keywords = pick2("keywords");
|
|
282295
282973
|
if (keywords) tags += ` <meta name="keywords" content="${esc4(keywords)}">
|
|
282296
282974
|
`;
|
|
@@ -284472,6 +285150,7 @@ var init_static = __esm({
|
|
|
284472
285150
|
if (!existsSync15(filePath)) {
|
|
284473
285151
|
filePath = join19(this.root, safePath + ".html");
|
|
284474
285152
|
}
|
|
285153
|
+
let notFoundFallback = false;
|
|
284475
285154
|
if (!existsSync15(filePath)) {
|
|
284476
285155
|
filePath = join19(this.root, safePath, this.indexFile);
|
|
284477
285156
|
}
|
|
@@ -284483,6 +285162,7 @@ var init_static = __esm({
|
|
|
284483
285162
|
}
|
|
284484
285163
|
} else {
|
|
284485
285164
|
filePath = join19(this.root, "404.html");
|
|
285165
|
+
notFoundFallback = true;
|
|
284486
285166
|
if (!existsSync15(filePath)) {
|
|
284487
285167
|
return new Response("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } });
|
|
284488
285168
|
}
|
|
@@ -284550,12 +285230,12 @@ var init_static = __esm({
|
|
|
284550
285230
|
const gzHeaders = { ...headers, "Content-Encoding": "gzip", "Content-Length": String(gz.length), Vary: "Accept-Encoding" };
|
|
284551
285231
|
delete gzHeaders["Content-Length"];
|
|
284552
285232
|
if (this.lastModified) delete gzHeaders["Last-Modified"];
|
|
284553
|
-
return new Response(gz, { headers: gzHeaders });
|
|
285233
|
+
return new Response(gz, { headers: gzHeaders, status: notFoundFallback ? 404 : 200 });
|
|
284554
285234
|
}
|
|
284555
285235
|
} catch {
|
|
284556
285236
|
}
|
|
284557
285237
|
}
|
|
284558
|
-
return new Response(bytes, { headers });
|
|
285238
|
+
return new Response(bytes, { headers, status: notFoundFallback ? 404 : 200 });
|
|
284559
285239
|
}
|
|
284560
285240
|
/**
|
|
284561
285241
|
* Parse a `Range: bytes=...` header against a known content length.
|
|
@@ -285879,17 +286559,17 @@ async function hs256(payload, secret, maxAge) {
|
|
|
285879
286559
|
const header = { alg: "HS256", typ: "JWT" };
|
|
285880
286560
|
const body = { ...payload, iat: now, exp: now + maxAge };
|
|
285881
286561
|
const data = enc(header) + "." + enc(body);
|
|
285882
|
-
const { createHmac:
|
|
285883
|
-
const sig =
|
|
286562
|
+
const { createHmac: createHmac3 } = await import("node:crypto");
|
|
286563
|
+
const sig = createHmac3("sha256", secret).update(data).digest("base64url");
|
|
285884
286564
|
return data + "." + sig;
|
|
285885
286565
|
}
|
|
285886
286566
|
async function verifyHs256(token, secret) {
|
|
285887
286567
|
const parts = token.split(".");
|
|
285888
286568
|
if (parts.length !== 3) return null;
|
|
285889
|
-
const { createHmac:
|
|
285890
|
-
const expected =
|
|
286569
|
+
const { createHmac: createHmac3, timingSafeEqual: timingSafeEqual3 } = await import("node:crypto");
|
|
286570
|
+
const expected = createHmac3("sha256", secret).update(parts[0] + "." + parts[1]).digest("base64url");
|
|
285891
286571
|
const a = Buffer.from(expected), b = Buffer.from(parts[2]);
|
|
285892
|
-
if (a.length !== b.length || !
|
|
286572
|
+
if (a.length !== b.length || !timingSafeEqual3(a, b)) return null;
|
|
285893
286573
|
try {
|
|
285894
286574
|
const body = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
285895
286575
|
if (typeof body.exp === "number" && body.exp < Math.floor(Date.now() / 1e3)) return null;
|
|
@@ -286374,6 +287054,17 @@ var init_tw10 = __esm({
|
|
|
286374
287054
|
cfgIn.redirects = normalizedRedirects.filter(Boolean);
|
|
286375
287055
|
}
|
|
286376
287056
|
}
|
|
287057
|
+
if (Array.isArray(cfgIn.redirects)) {
|
|
287058
|
+
const seenFrom = /* @__PURE__ */ new Set();
|
|
287059
|
+
for (const r of cfgIn.redirects) {
|
|
287060
|
+
const from = r && typeof r.from === "string" ? r.from : null;
|
|
287061
|
+
if (!from) continue;
|
|
287062
|
+
if (seenFrom.has(from)) {
|
|
287063
|
+
console.warn("[tw] redirects: '" + from + "' is listed more than once -- the first entry wins, the later one never runs");
|
|
287064
|
+
}
|
|
287065
|
+
seenFrom.add(from);
|
|
287066
|
+
}
|
|
287067
|
+
}
|
|
286377
287068
|
if (cfgIn.headers && !Array.isArray(cfgIn.headers)) {
|
|
286378
287069
|
const entries = Object.entries(cfgIn.headers);
|
|
286379
287070
|
cfgIn.headers = entries.map(([source, headers]) => ({ source, headers }));
|
|
@@ -287194,6 +287885,19 @@ ${err2.stack ?? ""}`);
|
|
|
287194
287885
|
const isrLookupPath = pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname;
|
|
287195
287886
|
if (this.staticHandler && !this.isrRoutes.has(isrLookupPath)) {
|
|
287196
287887
|
let staticResponse = await this.staticHandler.serve(pathname, request);
|
|
287888
|
+
if (staticResponse.status !== 404) {
|
|
287889
|
+
const reqMethod = request.method.toUpperCase();
|
|
287890
|
+
const allow = "GET, HEAD, OPTIONS";
|
|
287891
|
+
if (reqMethod === "TRACE") {
|
|
287892
|
+
return new Response("Method Not Allowed", { status: 405, headers: { Allow: allow } });
|
|
287893
|
+
}
|
|
287894
|
+
if (reqMethod === "OPTIONS") {
|
|
287895
|
+
return new Response(null, { status: 204, headers: { Allow: allow } });
|
|
287896
|
+
}
|
|
287897
|
+
if (reqMethod !== "GET" && reqMethod !== "HEAD") {
|
|
287898
|
+
return new Response("Method Not Allowed", { status: 405, headers: { Allow: allow } });
|
|
287899
|
+
}
|
|
287900
|
+
}
|
|
287197
287901
|
if (staticResponse && this.cspEnabled() && (staticResponse.headers.get("content-type") || "").includes("text/html")) {
|
|
287198
287902
|
try {
|
|
287199
287903
|
let buf = Buffer.from(await staticResponse.arrayBuffer());
|