noofpi 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +47 -2
- package/bin/noofpi.mjs +2 -0
- package/client.d.ts +79 -0
- package/dist/build-77DKK3YK.js +48 -0
- package/dist/chunk-2XCZWFIQ.js +253 -0
- package/dist/chunk-6OWKWAIW.js +68 -0
- package/dist/chunk-ELXCFUA4.js +97 -0
- package/dist/chunk-EZPJF4D4.js +314 -0
- package/dist/chunk-FIJJ3EGL.js +353 -0
- package/dist/chunk-G35DW4NA.js +129 -0
- package/dist/chunk-KAV3UNMO.js +996 -0
- package/dist/chunk-KGZP2RCF.js +51 -0
- package/dist/chunk-MTWSTW7V.js +44 -0
- package/dist/chunk-MTXQR32N.js +8 -0
- package/dist/chunk-NALDZ3PS.js +90 -0
- package/dist/chunk-WX2V6EYH.js +102 -0
- package/dist/chunk-WXEYXDO6.js +280 -0
- package/dist/chunk-X34Y6ESE.js +810 -0
- package/dist/chunk-Y3NBZ6DW.js +55 -0
- package/dist/chunk-YZAZ7IWK.js +27 -0
- package/dist/cli.js +93 -0
- package/dist/dev-ZJ732ORK.js +122 -0
- package/dist/devtools-KTDSD5PR.js +564 -0
- package/dist/images-BNwTAi50.d.ts +36 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +15 -0
- package/dist/route-rules-COilNsVT.d.ts +127 -0
- package/dist/runtime/default-app.js +15 -0
- package/dist/runtime/entry-client.js +70 -0
- package/dist/runtime/entry-server.js +107 -0
- package/dist/runtime/index.d.ts +523 -0
- package/dist/runtime/index.js +224 -0
- package/dist/runtime/routes.js +14 -0
- package/dist/server/bun.js +47 -0
- package/dist/server/index.d.ts +109 -0
- package/dist/server/index.js +48 -0
- package/dist/server/node.js +15 -0
- package/dist/start-I2LQWV7B.js +61 -0
- package/dist/validation-ClXd_DAW.d.ts +159 -0
- package/package.json +101 -4
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/server/static.ts
|
|
2
|
+
import { stat } from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
var MIME = {
|
|
5
|
+
".html": "text/html; charset=utf-8",
|
|
6
|
+
".js": "text/javascript; charset=utf-8",
|
|
7
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
8
|
+
".css": "text/css; charset=utf-8",
|
|
9
|
+
".json": "application/json; charset=utf-8",
|
|
10
|
+
".svg": "image/svg+xml",
|
|
11
|
+
".png": "image/png",
|
|
12
|
+
".jpg": "image/jpeg",
|
|
13
|
+
".jpeg": "image/jpeg",
|
|
14
|
+
".gif": "image/gif",
|
|
15
|
+
".webp": "image/webp",
|
|
16
|
+
".avif": "image/avif",
|
|
17
|
+
".ico": "image/x-icon",
|
|
18
|
+
".woff": "font/woff",
|
|
19
|
+
".woff2": "font/woff2",
|
|
20
|
+
".txt": "text/plain; charset=utf-8",
|
|
21
|
+
".map": "application/json"
|
|
22
|
+
};
|
|
23
|
+
async function resolveStaticFile(dir, method, rawPath) {
|
|
24
|
+
if (method !== "GET" && method !== "HEAD") return null;
|
|
25
|
+
let pathname;
|
|
26
|
+
try {
|
|
27
|
+
pathname = decodeURIComponent(
|
|
28
|
+
new URL(rawPath, "http://localhost").pathname
|
|
29
|
+
);
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const file = path.join(dir, pathname);
|
|
34
|
+
if (!file.startsWith(dir + path.sep) || path.basename(file) === "index.html")
|
|
35
|
+
return null;
|
|
36
|
+
const info = await stat(file).catch(() => null);
|
|
37
|
+
if (!info?.isFile()) return null;
|
|
38
|
+
return {
|
|
39
|
+
file,
|
|
40
|
+
size: info.size,
|
|
41
|
+
headers: {
|
|
42
|
+
"X-Content-Type-Options": "nosniff",
|
|
43
|
+
"Content-Type": MIME[path.extname(file).toLowerCase()] ?? "application/octet-stream",
|
|
44
|
+
"Cache-Control": pathname.startsWith("/assets/") ? "public, max-age=31536000, immutable" : "no-cache"
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
resolveStaticFile
|
|
51
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeLayout
|
|
3
|
+
} from "./chunk-Y3NBZ6DW.js";
|
|
4
|
+
|
|
5
|
+
// src/runtime/page.ts
|
|
6
|
+
import layouts from "virtual:noofpi/layouts";
|
|
7
|
+
import { RouterLink, RouterView as RouterView2 } from "vue-router";
|
|
8
|
+
|
|
9
|
+
// src/runtime/layout-component.ts
|
|
10
|
+
import { defineComponent, h } from "vue";
|
|
11
|
+
import { RouterView, useRoute } from "vue-router";
|
|
12
|
+
function createLayoutComponent(layouts2) {
|
|
13
|
+
return defineComponent({
|
|
14
|
+
name: "NoofpiLayout",
|
|
15
|
+
setup(_, { slots }) {
|
|
16
|
+
const route = useRoute();
|
|
17
|
+
return () => {
|
|
18
|
+
const content = slots.default ? slots.default() : h(RouterView);
|
|
19
|
+
const name = normalizeLayout(route.meta.layout);
|
|
20
|
+
if (name === false) return content;
|
|
21
|
+
const layout = layouts2[name ?? "default"];
|
|
22
|
+
if (!layout) {
|
|
23
|
+
if (name)
|
|
24
|
+
console.warn(
|
|
25
|
+
`[noofpi] Unknown layout "${name}" (expected app/layouts/${name}.vue)`
|
|
26
|
+
);
|
|
27
|
+
return content;
|
|
28
|
+
}
|
|
29
|
+
return h(layout, null, { default: () => content });
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/runtime/page.ts
|
|
36
|
+
var NoofpiLayout = createLayoutComponent(layouts);
|
|
37
|
+
var NoofpiPage = RouterView2;
|
|
38
|
+
var NoofpiLink = RouterLink;
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
NoofpiLayout,
|
|
42
|
+
NoofpiPage,
|
|
43
|
+
NoofpiLink
|
|
44
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveStaticFile
|
|
3
|
+
} from "./chunk-KGZP2RCF.js";
|
|
4
|
+
|
|
5
|
+
// src/server/node.ts
|
|
6
|
+
import { createReadStream } from "fs";
|
|
7
|
+
import {
|
|
8
|
+
createServer
|
|
9
|
+
} from "http";
|
|
10
|
+
import { pipeline, Readable } from "stream";
|
|
11
|
+
function toWebRequest(req) {
|
|
12
|
+
const proto = req.headers["x-forwarded-proto"]?.split(",")[0]?.trim() ?? "http";
|
|
13
|
+
const target = req.url?.startsWith("/") ? req.url : "/";
|
|
14
|
+
const url = new URL(`${proto}://${req.headers.host ?? "localhost"}${target}`);
|
|
15
|
+
const headers = new Headers();
|
|
16
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
17
|
+
if (value === void 0) continue;
|
|
18
|
+
headers.set(key, Array.isArray(value) ? value.join(", ") : value);
|
|
19
|
+
}
|
|
20
|
+
const method = req.method ?? "GET";
|
|
21
|
+
const hasBody = method !== "GET" && method !== "HEAD";
|
|
22
|
+
return new Request(url, {
|
|
23
|
+
method,
|
|
24
|
+
headers,
|
|
25
|
+
body: hasBody ? Readable.toWeb(req) : void 0,
|
|
26
|
+
...hasBody ? { duplex: "half" } : {}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function sendWebResponse(res, response) {
|
|
30
|
+
res.statusCode = response.status;
|
|
31
|
+
for (const [key, value] of response.headers) {
|
|
32
|
+
if (key !== "set-cookie") res.setHeader(key, value);
|
|
33
|
+
}
|
|
34
|
+
const cookies = response.headers.getSetCookie();
|
|
35
|
+
if (cookies.length) res.setHeader("set-cookie", cookies);
|
|
36
|
+
if (!response.body) {
|
|
37
|
+
res.end();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
pipeline(
|
|
41
|
+
Readable.fromWeb(response.body),
|
|
42
|
+
res,
|
|
43
|
+
ignoreStreamError
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
var ignoreStreamError = () => {
|
|
47
|
+
};
|
|
48
|
+
async function serveStatic(dir, req, res) {
|
|
49
|
+
const found = await resolveStaticFile(
|
|
50
|
+
dir,
|
|
51
|
+
req.method ?? "GET",
|
|
52
|
+
req.url ?? "/"
|
|
53
|
+
);
|
|
54
|
+
if (!found) return false;
|
|
55
|
+
for (const [name, value] of Object.entries(found.headers))
|
|
56
|
+
res.setHeader(name, value);
|
|
57
|
+
res.setHeader("Content-Length", found.size);
|
|
58
|
+
if (req.method === "HEAD") res.end();
|
|
59
|
+
else pipeline(createReadStream(found.file), res, ignoreStreamError);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
function createNodeServer(options) {
|
|
63
|
+
return createServer(async (req, res) => {
|
|
64
|
+
try {
|
|
65
|
+
if (await serveStatic(options.publicDir, req, res)) return;
|
|
66
|
+
await sendWebResponse(res, await options.handler(toWebRequest(req)));
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(error);
|
|
69
|
+
res.statusCode = 500;
|
|
70
|
+
res.end("Internal Server Error");
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async function listenNodeServer(server, port, host) {
|
|
75
|
+
await new Promise((resolve) => server.listen(port, host, resolve));
|
|
76
|
+
console.log(
|
|
77
|
+
`
|
|
78
|
+
noofpi server running at http://${host === "0.0.0.0" ? "localhost" : host}:${port}
|
|
79
|
+
`
|
|
80
|
+
);
|
|
81
|
+
return server;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
toWebRequest,
|
|
86
|
+
sendWebResponse,
|
|
87
|
+
serveStatic,
|
|
88
|
+
createNodeServer,
|
|
89
|
+
listenNodeServer
|
|
90
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// src/banner.ts
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { networkInterfaces } from "os";
|
|
4
|
+
import { version as viteVersion } from "vite";
|
|
5
|
+
var LOGO = ["\u2588\u2584 \u2588 \u2588\u2580\u2588 \u2588\u2580\u2588 \u2588\u2580\u2580 \u2588\u2580\u2588 \u2588", "\u2588 \u2580\u2588 \u2588\u2584\u2588 \u2588\u2584\u2588 \u2588\u2580 \u2588\u2580\u2580 \u2588"];
|
|
6
|
+
var useColor = !process.env.NO_COLOR && (Boolean(process.env.FORCE_COLOR) || Boolean(process.stdout.isTTY));
|
|
7
|
+
var trueColor = useColor && (process.env.COLORTERM === "truecolor" || process.env.COLORTERM === "24bit" || Boolean(process.env.WT_SESSION) || process.env.TERM_PROGRAM === "vscode");
|
|
8
|
+
var wrap = (open, close) => (text) => useColor ? `\x1B[${open}m${text}\x1B[${close}m` : text;
|
|
9
|
+
var bold = wrap("1", "22");
|
|
10
|
+
var dim = wrap("2", "22");
|
|
11
|
+
var green = wrap("32", "39");
|
|
12
|
+
var cyan = wrap("36", "39");
|
|
13
|
+
var STOPS = [
|
|
14
|
+
[52, 211, 153],
|
|
15
|
+
[56, 189, 248],
|
|
16
|
+
[167, 139, 250]
|
|
17
|
+
];
|
|
18
|
+
function gradientAt(t) {
|
|
19
|
+
const scaled = t * (STOPS.length - 1);
|
|
20
|
+
const index = Math.min(Math.floor(scaled), STOPS.length - 2);
|
|
21
|
+
const local = scaled - index;
|
|
22
|
+
const [r1, g1, b1] = STOPS[index];
|
|
23
|
+
const [r2, g2, b2] = STOPS[index + 1];
|
|
24
|
+
const mix = (a, b) => Math.round(a + (b - a) * local);
|
|
25
|
+
return [mix(r1, r2), mix(g1, g2), mix(b1, b2)];
|
|
26
|
+
}
|
|
27
|
+
function gradient(text) {
|
|
28
|
+
if (!trueColor) return useColor ? cyan(text) : text;
|
|
29
|
+
const last = Math.max(text.length - 1, 1);
|
|
30
|
+
let out = "";
|
|
31
|
+
for (let i = 0; i < text.length; i++) {
|
|
32
|
+
const [r, g, b] = gradientAt(i / last);
|
|
33
|
+
out += `\x1B[38;2;${r};${g};${b}m${text[i]}`;
|
|
34
|
+
}
|
|
35
|
+
return out + "\x1B[39m";
|
|
36
|
+
}
|
|
37
|
+
function packageVersion() {
|
|
38
|
+
try {
|
|
39
|
+
const url = new URL("../package.json", import.meta.url);
|
|
40
|
+
return JSON.parse(readFileSync(url, "utf-8")).version;
|
|
41
|
+
} catch {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function networkAddresses() {
|
|
46
|
+
const addresses = [];
|
|
47
|
+
for (const entries of Object.values(networkInterfaces())) {
|
|
48
|
+
for (const entry of entries ?? []) {
|
|
49
|
+
if (entry.family === "IPv4" && !entry.internal)
|
|
50
|
+
addresses.push(entry.address);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return addresses;
|
|
54
|
+
}
|
|
55
|
+
var isWildcard = (host) => host === "0.0.0.0" || host === "::";
|
|
56
|
+
var isLoopback = (host) => host === "localhost" || host === "127.0.0.1" || host === "::1";
|
|
57
|
+
function localUrl(host, port) {
|
|
58
|
+
return `http://${isWildcard(host) ? "localhost" : host}:${port}/`;
|
|
59
|
+
}
|
|
60
|
+
function printBanner(options) {
|
|
61
|
+
const { mode, host, port } = options;
|
|
62
|
+
const local = localUrl(host, port);
|
|
63
|
+
const network = isWildcard(host) ? networkAddresses().map((address) => `http://${address}:${port}/`) : [];
|
|
64
|
+
const elapsed = Math.round(performance.now() - options.startedAt);
|
|
65
|
+
const version = packageVersion();
|
|
66
|
+
const rows = [
|
|
67
|
+
`${green("\u25CF")} ${bold("Ready")} ${dim(`in ${elapsed} ms`)}`,
|
|
68
|
+
"",
|
|
69
|
+
`${green("\u279C")} ${bold("Local")} ${cyan(bold(local))}`,
|
|
70
|
+
...network.map(
|
|
71
|
+
(address) => `${green("\u279C")} ${bold("Network")} ${cyan(address)}`
|
|
72
|
+
)
|
|
73
|
+
];
|
|
74
|
+
if (!network.length && isLoopback(host))
|
|
75
|
+
rows.push(`${dim("\u279C")} ${dim("Network")} ${dim("use --host to expose")}`);
|
|
76
|
+
if (options.shortcuts)
|
|
77
|
+
rows.push(
|
|
78
|
+
"",
|
|
79
|
+
`${dim("\u279C")} ${dim("press")} ${bold("b")} ${dim("to open the browser,")} ${bold("q")} ${dim("to quit")}`
|
|
80
|
+
);
|
|
81
|
+
const meta = [
|
|
82
|
+
version && `noofpi ${version}`,
|
|
83
|
+
`vite ${viteVersion}`,
|
|
84
|
+
`node ${process.version}`,
|
|
85
|
+
mode
|
|
86
|
+
].filter(Boolean);
|
|
87
|
+
const lines = [
|
|
88
|
+
"",
|
|
89
|
+
...LOGO.map((line) => " " + gradient(line)),
|
|
90
|
+
"",
|
|
91
|
+
...rows.map((row) => " " + row),
|
|
92
|
+
"",
|
|
93
|
+
" " + dim(meta.join(" \xB7 ")),
|
|
94
|
+
""
|
|
95
|
+
];
|
|
96
|
+
console.log(lines.join("\n"));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
localUrl,
|
|
101
|
+
printBanner
|
|
102
|
+
};
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveI18n
|
|
3
|
+
} from "./chunk-ELXCFUA4.js";
|
|
4
|
+
import {
|
|
5
|
+
FETCH_MODES,
|
|
6
|
+
resolveSecurity,
|
|
7
|
+
toPublicRouteRules,
|
|
8
|
+
usesFetchMode,
|
|
9
|
+
validateRouteRules
|
|
10
|
+
} from "./chunk-FIJJ3EGL.js";
|
|
11
|
+
|
|
12
|
+
// src/build-preset.ts
|
|
13
|
+
var BUILD_PRESETS = [
|
|
14
|
+
"node",
|
|
15
|
+
"bun",
|
|
16
|
+
"docker",
|
|
17
|
+
"cloudflare-worker",
|
|
18
|
+
"cloudflare-pages",
|
|
19
|
+
"github-pages"
|
|
20
|
+
];
|
|
21
|
+
function assertBuildPreset(value, source) {
|
|
22
|
+
if (!BUILD_PRESETS.includes(value)) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`[noofpi] ${source} must be one of ${BUILD_PRESETS.join(", ")} (got "${String(value)}")`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/fonts/types.ts
|
|
31
|
+
var FONT_PROVIDERS = ["google", "local"];
|
|
32
|
+
|
|
33
|
+
// src/fonts/normalize.ts
|
|
34
|
+
var DISPLAYS = ["auto", "block", "swap", "fallback", "optional"];
|
|
35
|
+
var STYLES = ["normal", "italic"];
|
|
36
|
+
var ALIAS = /^[a-z0-9][a-z0-9-]*$/;
|
|
37
|
+
var UNSAFE_CSS = /[;{}\n\r]/;
|
|
38
|
+
function slugify(name) {
|
|
39
|
+
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
40
|
+
}
|
|
41
|
+
function weightOf(weight, where) {
|
|
42
|
+
const value = String(weight).trim().toLowerCase();
|
|
43
|
+
if (value === "normal") return "400";
|
|
44
|
+
if (value === "bold") return "700";
|
|
45
|
+
const parts = value.split(/\s+/);
|
|
46
|
+
const valid = (parts.length === 1 || parts.length === 2) && parts.every((part) => /^\d+$/.test(part) && +part >= 1 && +part <= 1e3);
|
|
47
|
+
if (!valid || parts.length === 2 && +parts[0] >= +parts[1]) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`[noofpi] ${where}: invalid weight "${String(weight)}" (use 1-1000, "normal", "bold" or a range like "100 900")`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return parts.join(" ");
|
|
53
|
+
}
|
|
54
|
+
function styleOf(style, where) {
|
|
55
|
+
if (!STYLES.includes(style)) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`[noofpi] ${where}: style must be "normal" or "italic" (got "${String(style)}")`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return style;
|
|
61
|
+
}
|
|
62
|
+
function list(value, fallback) {
|
|
63
|
+
const values = value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
64
|
+
return [...new Set(values.length ? values : [fallback])];
|
|
65
|
+
}
|
|
66
|
+
function normalizeFonts(families) {
|
|
67
|
+
if (families === void 0) return [];
|
|
68
|
+
if (!Array.isArray(families)) {
|
|
69
|
+
throw new Error("[noofpi] fonts.families must be an array");
|
|
70
|
+
}
|
|
71
|
+
const aliases = /* @__PURE__ */ new Set();
|
|
72
|
+
return families.map((input, index) => {
|
|
73
|
+
const where = `fonts.families[${index}]`;
|
|
74
|
+
if (!input || typeof input !== "object") {
|
|
75
|
+
throw new Error(`[noofpi] ${where} must be an object`);
|
|
76
|
+
}
|
|
77
|
+
if (!FONT_PROVIDERS.includes(input.provider)) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`[noofpi] ${where}.provider must be one of ${FONT_PROVIDERS.join(", ")} (got "${String(input.provider)}")`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const name = typeof input.name === "string" ? input.name.trim() : "";
|
|
83
|
+
if (!name) throw new Error(`[noofpi] ${where}.name is required`);
|
|
84
|
+
const label = `${where} ("${name}")`;
|
|
85
|
+
const display = input.display ?? "swap";
|
|
86
|
+
if (!DISPLAYS.includes(display)) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`[noofpi] ${label}: display must be one of ${DISPLAYS.join(", ")} (got "${String(display)}")`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const fallback = input.fallback ?? [];
|
|
92
|
+
if (!Array.isArray(fallback) || fallback.some((f) => typeof f !== "string" || UNSAFE_CSS.test(f))) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`[noofpi] ${label}: fallback must be an array of font names`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
const alias = input.alias ?? slugify(name);
|
|
98
|
+
if (!ALIAS.test(alias)) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`[noofpi] ${label}: alias "${alias}" must be kebab-case (set \`alias\` explicitly)`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (aliases.has(alias)) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`[noofpi] ${label}: alias "${alias}" is already used, set a unique \`alias\``
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
aliases.add(alias);
|
|
109
|
+
const resolved = {
|
|
110
|
+
provider: input.provider,
|
|
111
|
+
name,
|
|
112
|
+
display,
|
|
113
|
+
fallback,
|
|
114
|
+
alias,
|
|
115
|
+
weights: [],
|
|
116
|
+
styles: [],
|
|
117
|
+
subsets: [],
|
|
118
|
+
files: []
|
|
119
|
+
};
|
|
120
|
+
if (input.provider === "google") {
|
|
121
|
+
resolved.weights = list(input.weight, 400).map(
|
|
122
|
+
(w) => weightOf(w, label)
|
|
123
|
+
);
|
|
124
|
+
resolved.styles = list(input.style, "normal").map(
|
|
125
|
+
(s) => styleOf(s, label)
|
|
126
|
+
);
|
|
127
|
+
resolved.subsets = input.subsets ?? [];
|
|
128
|
+
} else {
|
|
129
|
+
if (Array.isArray(input.weight)) {
|
|
130
|
+
throw new Error(
|
|
131
|
+
`[noofpi] ${label}: local fonts take a single weight; give each file its own weight in \`src\``
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const weight = weightOf(input.weight ?? 400, label);
|
|
135
|
+
const style = styleOf(input.style ?? "normal", label);
|
|
136
|
+
const files = typeof input.src === "string" ? [{ src: input.src }] : input.src;
|
|
137
|
+
if (!Array.isArray(files) || files.length === 0) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
`[noofpi] ${label}: src is required (a file path or a list of files)`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
resolved.files = files.map((file, i) => {
|
|
143
|
+
if (!file || typeof file.src !== "string" || !file.src) {
|
|
144
|
+
throw new Error(`[noofpi] ${label}: src[${i}].src is required`);
|
|
145
|
+
}
|
|
146
|
+
const { weight: fileWeight, style: fileStyle } = file;
|
|
147
|
+
return {
|
|
148
|
+
src: file.src,
|
|
149
|
+
weight: fileWeight === void 0 ? weight : weightOf(fileWeight, label),
|
|
150
|
+
style: fileStyle === void 0 ? style : styleOf(fileStyle, label)
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return resolved;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/images.ts
|
|
159
|
+
var IMAGE_FORMATS = ["avif", "webp"];
|
|
160
|
+
function resolveImages(input = {}) {
|
|
161
|
+
const formats = input.formats ?? [...IMAGE_FORMATS];
|
|
162
|
+
for (const format of formats) {
|
|
163
|
+
if (!IMAGE_FORMATS.includes(format))
|
|
164
|
+
throw new Error(
|
|
165
|
+
`[noofpi] images.formats must only contain ${IMAGE_FORMATS.join(", ")} (got "${String(format)}")`
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
const widths = input.widths ?? [640, 1024, 1920];
|
|
169
|
+
if (widths.some((width) => !Number.isInteger(width) || width < 1))
|
|
170
|
+
throw new Error("[noofpi] images.widths must be positive integers");
|
|
171
|
+
const quality = input.quality ?? 75;
|
|
172
|
+
if (!Number.isInteger(quality) || quality < 1 || quality > 100)
|
|
173
|
+
throw new Error("[noofpi] images.quality must be an integer from 1 to 100");
|
|
174
|
+
return {
|
|
175
|
+
formats: [...new Set(formats)],
|
|
176
|
+
widths: [...new Set(widths)].sort((a, b) => a - b),
|
|
177
|
+
quality
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function variantWidths(imageWidth, widths) {
|
|
181
|
+
return [...widths.filter((width) => width < imageWidth), imageWidth];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/config.ts
|
|
185
|
+
function defineNoofpiConfig(config) {
|
|
186
|
+
return config;
|
|
187
|
+
}
|
|
188
|
+
function resolveConfig(input = {}) {
|
|
189
|
+
const mode = input.doofpi?.fetch ?? "lfetch";
|
|
190
|
+
if (!FETCH_MODES.includes(mode)) {
|
|
191
|
+
throw new Error(
|
|
192
|
+
`[noofpi] doofpi.fetch must be one of ${FETCH_MODES.join(", ")} (got "${String(mode)}")`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
const ssr = input.ssr ?? true;
|
|
196
|
+
if (mode === "sfetch" && !ssr) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
'[noofpi] doofpi.fetch "sfetch" only fetches on the server, so it requires ssr: true'
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
const routeRules = input.routeRules ?? {};
|
|
202
|
+
validateRouteRules(routeRules, ssr);
|
|
203
|
+
let url = input.doofpi?.url;
|
|
204
|
+
const remoteRule = Object.entries(routeRules).find(
|
|
205
|
+
([, rule]) => rule.fetch !== void 0 && rule.fetch !== "lfetch"
|
|
206
|
+
);
|
|
207
|
+
if (mode !== "lfetch" || remoteRule) {
|
|
208
|
+
if (!url)
|
|
209
|
+
throw new Error(
|
|
210
|
+
mode !== "lfetch" ? `[noofpi] doofpi.url is required when doofpi.fetch is "${mode}"` : `[noofpi] doofpi.url is required when routeRules["${remoteRule[0]}"].fetch is "${remoteRule[1].fetch}"`
|
|
211
|
+
);
|
|
212
|
+
try {
|
|
213
|
+
const parsed = new URL(url);
|
|
214
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
215
|
+
throw new Error();
|
|
216
|
+
url = parsed.origin;
|
|
217
|
+
} catch {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`[noofpi] doofpi.url must be an absolute http(s) URL (got "${url}")`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const root = input.doofpi?.root ?? "/doofpi";
|
|
224
|
+
if (!root.startsWith("/") || root.length < 2 || root.endsWith("/")) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`[noofpi] doofpi.root must start with "/" and not end with "/" (got "${root}")`
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
const security = resolveSecurity(input.security);
|
|
230
|
+
const preset = assertBuildPreset(
|
|
231
|
+
input.build?.preset ?? "node",
|
|
232
|
+
"build.preset"
|
|
233
|
+
);
|
|
234
|
+
return {
|
|
235
|
+
ssr,
|
|
236
|
+
routeRules,
|
|
237
|
+
head: input.head ?? {},
|
|
238
|
+
tailwind: input.tailwind ?? false,
|
|
239
|
+
autoImports: input.autoImports ?? true,
|
|
240
|
+
css: input.css,
|
|
241
|
+
fonts: normalizeFonts(input.fonts?.families),
|
|
242
|
+
images: resolveImages(input.images),
|
|
243
|
+
security,
|
|
244
|
+
i18n: resolveI18n(input.i18n),
|
|
245
|
+
doofpi: { fetch: mode, url, root },
|
|
246
|
+
devServer: {
|
|
247
|
+
port: input.devServer?.port ?? 3e3,
|
|
248
|
+
host: input.devServer?.host ?? "localhost"
|
|
249
|
+
},
|
|
250
|
+
build: { preset },
|
|
251
|
+
devtools: input.devtools ?? true,
|
|
252
|
+
vite: input.vite ?? {}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function toPublicConfig(config) {
|
|
256
|
+
const { fetch, url, root } = config.doofpi;
|
|
257
|
+
const direct = usesFetchMode(fetch, config.routeRules, "dfetch");
|
|
258
|
+
return {
|
|
259
|
+
ssr: config.ssr,
|
|
260
|
+
routeRules: toPublicRouteRules(config.routeRules),
|
|
261
|
+
head: config.head,
|
|
262
|
+
doofpi: { fetch, url: direct ? url : void 0, root },
|
|
263
|
+
devtools: config.devtools
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function toServerConfig(config) {
|
|
267
|
+
const { ssr, doofpi, routeRules, head, security } = config;
|
|
268
|
+
return { ssr, doofpi, routeRules, head, security };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export {
|
|
272
|
+
BUILD_PRESETS,
|
|
273
|
+
assertBuildPreset,
|
|
274
|
+
FONT_PROVIDERS,
|
|
275
|
+
variantWidths,
|
|
276
|
+
defineNoofpiConfig,
|
|
277
|
+
resolveConfig,
|
|
278
|
+
toPublicConfig,
|
|
279
|
+
toServerConfig
|
|
280
|
+
};
|