noofpi 0.0.0-stage → 1.1.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-63DMFZJY.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-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-NX6BO7UB.js +284 -0
- package/dist/chunk-SSJ2KKBZ.js +996 -0
- package/dist/chunk-WX2V6EYH.js +102 -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-USSN6KFV.js +149 -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-U6A3PBRI.js +61 -0
- package/dist/validation-ClXd_DAW.d.ts +159 -0
- package/package.json +101 -4
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// src/head.ts
|
|
2
|
+
var DEFAULT_TITLE = "noofpi";
|
|
3
|
+
var HEAD_TAG_ATTR = "data-noofpi-head";
|
|
4
|
+
var HEAD_ATTRS_ATTR = "data-noofpi-attrs";
|
|
5
|
+
var BASE_HTML_ATTRS = { lang: "en" };
|
|
6
|
+
var TITLE_SEPARATORS = /^[\s|\-–—·:•]+|[\s|\-–—·:•]+$/g;
|
|
7
|
+
var SAFE_ATTR_NAME = /^[^\s"'<>/=\u0000-\u001f\u007f]+$/;
|
|
8
|
+
var isSafeAttrName = (name) => SAFE_ATTR_NAME.test(name) && !/^on/i.test(name);
|
|
9
|
+
function normalizeAttrs(attrs) {
|
|
10
|
+
const result = {};
|
|
11
|
+
for (const [name, value] of Object.entries(attrs ?? {})) {
|
|
12
|
+
if (value === void 0 || value === null || value === false) continue;
|
|
13
|
+
if (!isSafeAttrName(name)) continue;
|
|
14
|
+
result[name] = value === true ? "" : String(value);
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
function tagKey(kind, tag) {
|
|
19
|
+
if (kind === "meta") {
|
|
20
|
+
if ("charset" in tag) return "charset";
|
|
21
|
+
for (const name of ["name", "property", "http-equiv", "itemprop"])
|
|
22
|
+
if (name in tag) return `${name}:${tag[name]}`;
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
if (tag.rel === "canonical") return "canonical";
|
|
26
|
+
return tag.rel && tag.href ? `${tag.rel}|${tag.href}|${tag.hreflang ?? ""}` : void 0;
|
|
27
|
+
}
|
|
28
|
+
function mergeTags(kind, lists) {
|
|
29
|
+
const tags = /* @__PURE__ */ new Map();
|
|
30
|
+
let anonymous = 0;
|
|
31
|
+
for (const list of lists)
|
|
32
|
+
for (const raw of list ?? []) {
|
|
33
|
+
const tag = normalizeAttrs(raw);
|
|
34
|
+
tags.set(tagKey(kind, tag) ?? `#${anonymous++}`, tag);
|
|
35
|
+
}
|
|
36
|
+
return [...tags.values()];
|
|
37
|
+
}
|
|
38
|
+
function resolveTitle(template, title) {
|
|
39
|
+
if (title)
|
|
40
|
+
return template?.includes("%s") ? template.split("%s").join(title) : title;
|
|
41
|
+
if (!template) return DEFAULT_TITLE;
|
|
42
|
+
return template.split("%s").join("").replace(TITLE_SEPARATORS, "") || DEFAULT_TITLE;
|
|
43
|
+
}
|
|
44
|
+
function resolveHead(defaults, entries = []) {
|
|
45
|
+
const all = [defaults ?? {}, ...entries];
|
|
46
|
+
const pageTitle = entries.map((entry) => entry.title).filter(Boolean).pop();
|
|
47
|
+
return {
|
|
48
|
+
title: resolveTitle(defaults?.title, pageTitle),
|
|
49
|
+
meta: mergeTags(
|
|
50
|
+
"meta",
|
|
51
|
+
all.map((input) => input.meta)
|
|
52
|
+
),
|
|
53
|
+
link: mergeTags(
|
|
54
|
+
"link",
|
|
55
|
+
all.map((input) => input.link)
|
|
56
|
+
),
|
|
57
|
+
htmlAttrs: Object.assign(
|
|
58
|
+
{ ...BASE_HTML_ATTRS },
|
|
59
|
+
...all.map((input) => normalizeAttrs(input.htmlAttrs))
|
|
60
|
+
),
|
|
61
|
+
bodyAttrs: Object.assign(
|
|
62
|
+
{},
|
|
63
|
+
...all.map((input) => normalizeAttrs(input.bodyAttrs))
|
|
64
|
+
)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
var escapeText = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
68
|
+
var escapeAttr = (value) => escapeText(value).replace(/"/g, """);
|
|
69
|
+
var renderAttrs = (attrs) => Object.entries(attrs).map(([name, value]) => `${name}="${escapeAttr(value)}"`).join(" ");
|
|
70
|
+
var ATTRIBUTE = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
|
|
71
|
+
function mergeTagAttrs(html, tag, attrs) {
|
|
72
|
+
return html.replace(
|
|
73
|
+
new RegExp(`<${tag}\\b([^>]*)>`, "i"),
|
|
74
|
+
(whole, rest) => {
|
|
75
|
+
const existing = /* @__PURE__ */ new Map();
|
|
76
|
+
for (const match of rest.matchAll(ATTRIBUTE))
|
|
77
|
+
existing.set(
|
|
78
|
+
match[1].toLowerCase(),
|
|
79
|
+
match[2] ?? match[3] ?? match[4] ?? ""
|
|
80
|
+
);
|
|
81
|
+
existing.delete(HEAD_ATTRS_ATTR);
|
|
82
|
+
const changed = Object.entries(attrs).filter(
|
|
83
|
+
([name, value]) => existing.get(name.toLowerCase()) !== value
|
|
84
|
+
);
|
|
85
|
+
if (!changed.length) return whole;
|
|
86
|
+
const kept = [...existing].filter(
|
|
87
|
+
([name]) => !changed.some(([changedName]) => changedName.toLowerCase() === name)
|
|
88
|
+
);
|
|
89
|
+
const merged = {
|
|
90
|
+
...Object.fromEntries(kept),
|
|
91
|
+
...Object.fromEntries(changed),
|
|
92
|
+
[HEAD_ATTRS_ATTR]: changed.map(([name]) => name).join(" ")
|
|
93
|
+
};
|
|
94
|
+
return `<${tag} ${renderAttrs(merged)}>`;
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
function applyHead(html, head) {
|
|
99
|
+
let result = html;
|
|
100
|
+
const title = `<title>${escapeText(head.title)}</title>`;
|
|
101
|
+
if (/<title>[\s\S]*?<\/title>/i.test(result))
|
|
102
|
+
result = result.replace(/<title>[\s\S]*?<\/title>/i, () => title);
|
|
103
|
+
else result = result.replace("</head>", () => ` ${title}
|
|
104
|
+
</head>`);
|
|
105
|
+
if (head.meta.some((tag) => "charset" in tag))
|
|
106
|
+
result = result.replace(/\s*<meta\s+charset=[^>]*>/i, "");
|
|
107
|
+
if (head.meta.some((tag) => tag.name === "viewport"))
|
|
108
|
+
result = result.replace(/\s*<meta\s+name="viewport"[^>]*>/i, "");
|
|
109
|
+
const tags = [
|
|
110
|
+
...head.meta.map((attrs) => ["meta", attrs]),
|
|
111
|
+
...head.link.map((attrs) => ["link", attrs])
|
|
112
|
+
].map(
|
|
113
|
+
([name, attrs]) => ` <${name} ${renderAttrs({ ...attrs, [HEAD_TAG_ATTR]: "" })} />
|
|
114
|
+
`
|
|
115
|
+
);
|
|
116
|
+
if (tags.length)
|
|
117
|
+
result = result.replace("</head>", () => tags.join("") + " </head>");
|
|
118
|
+
result = mergeTagAttrs(result, "html", head.htmlAttrs);
|
|
119
|
+
if (Object.keys(head.bodyAttrs).length)
|
|
120
|
+
result = mergeTagAttrs(result, "body", head.bodyAttrs);
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export {
|
|
125
|
+
HEAD_TAG_ATTR,
|
|
126
|
+
HEAD_ATTRS_ATTR,
|
|
127
|
+
resolveHead,
|
|
128
|
+
applyHead
|
|
129
|
+
};
|
|
@@ -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,284 @@
|
|
|
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 isCloudflarePreset(preset) {
|
|
22
|
+
return preset === "cloudflare-worker" || preset === "cloudflare-pages";
|
|
23
|
+
}
|
|
24
|
+
function assertBuildPreset(value, source) {
|
|
25
|
+
if (!BUILD_PRESETS.includes(value)) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`[noofpi] ${source} must be one of ${BUILD_PRESETS.join(", ")} (got "${String(value)}")`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/fonts/types.ts
|
|
34
|
+
var FONT_PROVIDERS = ["google", "local"];
|
|
35
|
+
|
|
36
|
+
// src/fonts/normalize.ts
|
|
37
|
+
var DISPLAYS = ["auto", "block", "swap", "fallback", "optional"];
|
|
38
|
+
var STYLES = ["normal", "italic"];
|
|
39
|
+
var ALIAS = /^[a-z0-9][a-z0-9-]*$/;
|
|
40
|
+
var UNSAFE_CSS = /[;{}\n\r]/;
|
|
41
|
+
function slugify(name) {
|
|
42
|
+
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
43
|
+
}
|
|
44
|
+
function weightOf(weight, where) {
|
|
45
|
+
const value = String(weight).trim().toLowerCase();
|
|
46
|
+
if (value === "normal") return "400";
|
|
47
|
+
if (value === "bold") return "700";
|
|
48
|
+
const parts = value.split(/\s+/);
|
|
49
|
+
const valid = (parts.length === 1 || parts.length === 2) && parts.every((part) => /^\d+$/.test(part) && +part >= 1 && +part <= 1e3);
|
|
50
|
+
if (!valid || parts.length === 2 && +parts[0] >= +parts[1]) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`[noofpi] ${where}: invalid weight "${String(weight)}" (use 1-1000, "normal", "bold" or a range like "100 900")`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return parts.join(" ");
|
|
56
|
+
}
|
|
57
|
+
function styleOf(style, where) {
|
|
58
|
+
if (!STYLES.includes(style)) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`[noofpi] ${where}: style must be "normal" or "italic" (got "${String(style)}")`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return style;
|
|
64
|
+
}
|
|
65
|
+
function list(value, fallback) {
|
|
66
|
+
const values = value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
67
|
+
return [...new Set(values.length ? values : [fallback])];
|
|
68
|
+
}
|
|
69
|
+
function normalizeFonts(families) {
|
|
70
|
+
if (families === void 0) return [];
|
|
71
|
+
if (!Array.isArray(families)) {
|
|
72
|
+
throw new Error("[noofpi] fonts.families must be an array");
|
|
73
|
+
}
|
|
74
|
+
const aliases = /* @__PURE__ */ new Set();
|
|
75
|
+
return families.map((input, index) => {
|
|
76
|
+
const where = `fonts.families[${index}]`;
|
|
77
|
+
if (!input || typeof input !== "object") {
|
|
78
|
+
throw new Error(`[noofpi] ${where} must be an object`);
|
|
79
|
+
}
|
|
80
|
+
if (!FONT_PROVIDERS.includes(input.provider)) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`[noofpi] ${where}.provider must be one of ${FONT_PROVIDERS.join(", ")} (got "${String(input.provider)}")`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
const name = typeof input.name === "string" ? input.name.trim() : "";
|
|
86
|
+
if (!name) throw new Error(`[noofpi] ${where}.name is required`);
|
|
87
|
+
const label = `${where} ("${name}")`;
|
|
88
|
+
const display = input.display ?? "swap";
|
|
89
|
+
if (!DISPLAYS.includes(display)) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`[noofpi] ${label}: display must be one of ${DISPLAYS.join(", ")} (got "${String(display)}")`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const fallback = input.fallback ?? [];
|
|
95
|
+
if (!Array.isArray(fallback) || fallback.some((f) => typeof f !== "string" || UNSAFE_CSS.test(f))) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`[noofpi] ${label}: fallback must be an array of font names`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
const alias = input.alias ?? slugify(name);
|
|
101
|
+
if (!ALIAS.test(alias)) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`[noofpi] ${label}: alias "${alias}" must be kebab-case (set \`alias\` explicitly)`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (aliases.has(alias)) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`[noofpi] ${label}: alias "${alias}" is already used, set a unique \`alias\``
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
aliases.add(alias);
|
|
112
|
+
const resolved = {
|
|
113
|
+
provider: input.provider,
|
|
114
|
+
name,
|
|
115
|
+
display,
|
|
116
|
+
fallback,
|
|
117
|
+
alias,
|
|
118
|
+
weights: [],
|
|
119
|
+
styles: [],
|
|
120
|
+
subsets: [],
|
|
121
|
+
files: []
|
|
122
|
+
};
|
|
123
|
+
if (input.provider === "google") {
|
|
124
|
+
resolved.weights = list(input.weight, 400).map(
|
|
125
|
+
(w) => weightOf(w, label)
|
|
126
|
+
);
|
|
127
|
+
resolved.styles = list(input.style, "normal").map(
|
|
128
|
+
(s) => styleOf(s, label)
|
|
129
|
+
);
|
|
130
|
+
resolved.subsets = input.subsets ?? [];
|
|
131
|
+
} else {
|
|
132
|
+
if (Array.isArray(input.weight)) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`[noofpi] ${label}: local fonts take a single weight; give each file its own weight in \`src\``
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
const weight = weightOf(input.weight ?? 400, label);
|
|
138
|
+
const style = styleOf(input.style ?? "normal", label);
|
|
139
|
+
const files = typeof input.src === "string" ? [{ src: input.src }] : input.src;
|
|
140
|
+
if (!Array.isArray(files) || files.length === 0) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`[noofpi] ${label}: src is required (a file path or a list of files)`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
resolved.files = files.map((file, i) => {
|
|
146
|
+
if (!file || typeof file.src !== "string" || !file.src) {
|
|
147
|
+
throw new Error(`[noofpi] ${label}: src[${i}].src is required`);
|
|
148
|
+
}
|
|
149
|
+
const { weight: fileWeight, style: fileStyle } = file;
|
|
150
|
+
return {
|
|
151
|
+
src: file.src,
|
|
152
|
+
weight: fileWeight === void 0 ? weight : weightOf(fileWeight, label),
|
|
153
|
+
style: fileStyle === void 0 ? style : styleOf(fileStyle, label)
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return resolved;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/images.ts
|
|
162
|
+
var IMAGE_FORMATS = ["avif", "webp"];
|
|
163
|
+
function resolveImages(input = {}) {
|
|
164
|
+
const formats = input.formats ?? [...IMAGE_FORMATS];
|
|
165
|
+
for (const format of formats) {
|
|
166
|
+
if (!IMAGE_FORMATS.includes(format))
|
|
167
|
+
throw new Error(
|
|
168
|
+
`[noofpi] images.formats must only contain ${IMAGE_FORMATS.join(", ")} (got "${String(format)}")`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
const widths = input.widths ?? [640, 1024, 1920];
|
|
172
|
+
if (widths.some((width) => !Number.isInteger(width) || width < 1))
|
|
173
|
+
throw new Error("[noofpi] images.widths must be positive integers");
|
|
174
|
+
const quality = input.quality ?? 75;
|
|
175
|
+
if (!Number.isInteger(quality) || quality < 1 || quality > 100)
|
|
176
|
+
throw new Error("[noofpi] images.quality must be an integer from 1 to 100");
|
|
177
|
+
return {
|
|
178
|
+
formats: [...new Set(formats)],
|
|
179
|
+
widths: [...new Set(widths)].sort((a, b) => a - b),
|
|
180
|
+
quality
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function variantWidths(imageWidth, widths) {
|
|
184
|
+
return [...widths.filter((width) => width < imageWidth), imageWidth];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/config.ts
|
|
188
|
+
function defineNoofpiConfig(config) {
|
|
189
|
+
return config;
|
|
190
|
+
}
|
|
191
|
+
function resolveConfig(input = {}) {
|
|
192
|
+
const mode = input.doofpi?.fetch ?? "lfetch";
|
|
193
|
+
if (!FETCH_MODES.includes(mode)) {
|
|
194
|
+
throw new Error(
|
|
195
|
+
`[noofpi] doofpi.fetch must be one of ${FETCH_MODES.join(", ")} (got "${String(mode)}")`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
const ssr = input.ssr ?? true;
|
|
199
|
+
if (mode === "sfetch" && !ssr) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
'[noofpi] doofpi.fetch "sfetch" only fetches on the server, so it requires ssr: true'
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
const routeRules = input.routeRules ?? {};
|
|
205
|
+
validateRouteRules(routeRules, ssr);
|
|
206
|
+
let url = input.doofpi?.url;
|
|
207
|
+
const remoteRule = Object.entries(routeRules).find(
|
|
208
|
+
([, rule]) => rule.fetch !== void 0 && rule.fetch !== "lfetch"
|
|
209
|
+
);
|
|
210
|
+
if (mode !== "lfetch" || remoteRule) {
|
|
211
|
+
if (!url)
|
|
212
|
+
throw new Error(
|
|
213
|
+
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}"`
|
|
214
|
+
);
|
|
215
|
+
try {
|
|
216
|
+
const parsed = new URL(url);
|
|
217
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
218
|
+
throw new Error();
|
|
219
|
+
url = parsed.origin;
|
|
220
|
+
} catch {
|
|
221
|
+
throw new Error(
|
|
222
|
+
`[noofpi] doofpi.url must be an absolute http(s) URL (got "${url}")`
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const root = input.doofpi?.root ?? "/doofpi";
|
|
227
|
+
if (!root.startsWith("/") || root.length < 2 || root.endsWith("/")) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
`[noofpi] doofpi.root must start with "/" and not end with "/" (got "${root}")`
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
const security = resolveSecurity(input.security);
|
|
233
|
+
const preset = assertBuildPreset(
|
|
234
|
+
input.build?.preset ?? "node",
|
|
235
|
+
"build.preset"
|
|
236
|
+
);
|
|
237
|
+
return {
|
|
238
|
+
ssr,
|
|
239
|
+
routeRules,
|
|
240
|
+
head: input.head ?? {},
|
|
241
|
+
tailwind: input.tailwind ?? false,
|
|
242
|
+
autoImports: input.autoImports ?? true,
|
|
243
|
+
css: input.css,
|
|
244
|
+
fonts: normalizeFonts(input.fonts?.families),
|
|
245
|
+
images: resolveImages(input.images),
|
|
246
|
+
security,
|
|
247
|
+
i18n: resolveI18n(input.i18n),
|
|
248
|
+
doofpi: { fetch: mode, url, root },
|
|
249
|
+
devServer: {
|
|
250
|
+
port: input.devServer?.port ?? 3e3,
|
|
251
|
+
host: input.devServer?.host ?? "localhost"
|
|
252
|
+
},
|
|
253
|
+
build: { preset },
|
|
254
|
+
devtools: input.devtools ?? true,
|
|
255
|
+
vite: input.vite ?? {}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function toPublicConfig(config) {
|
|
259
|
+
const { fetch, url, root } = config.doofpi;
|
|
260
|
+
const direct = usesFetchMode(fetch, config.routeRules, "dfetch");
|
|
261
|
+
return {
|
|
262
|
+
ssr: config.ssr,
|
|
263
|
+
routeRules: toPublicRouteRules(config.routeRules),
|
|
264
|
+
head: config.head,
|
|
265
|
+
doofpi: { fetch, url: direct ? url : void 0, root },
|
|
266
|
+
devtools: config.devtools
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function toServerConfig(config) {
|
|
270
|
+
const { ssr, doofpi, routeRules, head, security } = config;
|
|
271
|
+
return { ssr, doofpi, routeRules, head, security };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export {
|
|
275
|
+
BUILD_PRESETS,
|
|
276
|
+
isCloudflarePreset,
|
|
277
|
+
assertBuildPreset,
|
|
278
|
+
FONT_PROVIDERS,
|
|
279
|
+
variantWidths,
|
|
280
|
+
defineNoofpiConfig,
|
|
281
|
+
resolveConfig,
|
|
282
|
+
toPublicConfig,
|
|
283
|
+
toServerConfig
|
|
284
|
+
};
|