@pyreon/zero 0.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 +53 -0
- package/lib/cache.js +80 -0
- package/lib/cache.js.map +1 -0
- package/lib/client.js +58 -0
- package/lib/client.js.map +1 -0
- package/lib/config.js +35 -0
- package/lib/config.js.map +1 -0
- package/lib/font.js +251 -0
- package/lib/font.js.map +1 -0
- package/lib/fs-router-BkbIWqek.js +30 -0
- package/lib/fs-router-BkbIWqek.js.map +1 -0
- package/lib/fs-router-jfd1QGLB.js +261 -0
- package/lib/fs-router-jfd1QGLB.js.map +1 -0
- package/lib/image-plugin.js +289 -0
- package/lib/image-plugin.js.map +1 -0
- package/lib/image.js +113 -0
- package/lib/image.js.map +1 -0
- package/lib/index.js +1665 -0
- package/lib/index.js.map +1 -0
- package/lib/link.js +186 -0
- package/lib/link.js.map +1 -0
- package/lib/script.js +102 -0
- package/lib/script.js.map +1 -0
- package/lib/seo.js +136 -0
- package/lib/seo.js.map +1 -0
- package/lib/theme.js +165 -0
- package/lib/theme.js.map +1 -0
- package/lib/types/adapters/bun.d.ts +6 -0
- package/lib/types/adapters/bun.d.ts.map +1 -0
- package/lib/types/adapters/index.d.ts +10 -0
- package/lib/types/adapters/index.d.ts.map +1 -0
- package/lib/types/adapters/node.d.ts +6 -0
- package/lib/types/adapters/node.d.ts.map +1 -0
- package/lib/types/adapters/static.d.ts +7 -0
- package/lib/types/adapters/static.d.ts.map +1 -0
- package/lib/types/app.d.ts +24 -0
- package/lib/types/app.d.ts.map +1 -0
- package/lib/types/cache.d.ts +54 -0
- package/lib/types/cache.d.ts.map +1 -0
- package/lib/types/client.d.ts +19 -0
- package/lib/types/client.d.ts.map +1 -0
- package/lib/types/config.d.ts +18 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/entry-server.d.ts +26 -0
- package/lib/types/entry-server.d.ts.map +1 -0
- package/lib/types/font.d.ts +119 -0
- package/lib/types/font.d.ts.map +1 -0
- package/lib/types/fs-router.d.ts +33 -0
- package/lib/types/fs-router.d.ts.map +1 -0
- package/lib/types/image-plugin.d.ts +79 -0
- package/lib/types/image-plugin.d.ts.map +1 -0
- package/lib/types/image.d.ts +50 -0
- package/lib/types/image.d.ts.map +1 -0
- package/lib/types/index.d.ts +27 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/isr.d.ts +9 -0
- package/lib/types/isr.d.ts.map +1 -0
- package/lib/types/link.d.ts +116 -0
- package/lib/types/link.d.ts.map +1 -0
- package/lib/types/script.d.ts +34 -0
- package/lib/types/script.d.ts.map +1 -0
- package/lib/types/seo.d.ts +88 -0
- package/lib/types/seo.d.ts.map +1 -0
- package/lib/types/theme.d.ts +38 -0
- package/lib/types/theme.d.ts.map +1 -0
- package/lib/types/types.d.ts +104 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/utils/use-intersection-observer.d.ts +10 -0
- package/lib/types/utils/use-intersection-observer.d.ts.map +1 -0
- package/lib/types/utils/with-headers.d.ts +6 -0
- package/lib/types/utils/with-headers.d.ts.map +1 -0
- package/lib/types/vite-plugin.d.ts +17 -0
- package/lib/types/vite-plugin.d.ts.map +1 -0
- package/package.json +100 -0
- package/src/adapters/bun.ts +65 -0
- package/src/adapters/index.ts +29 -0
- package/src/adapters/node.ts +113 -0
- package/src/adapters/static.ts +17 -0
- package/src/app.ts +62 -0
- package/src/cache.ts +149 -0
- package/src/client.ts +43 -0
- package/src/config.ts +36 -0
- package/src/entry-server.ts +51 -0
- package/src/font.ts +461 -0
- package/src/fs-router.ts +380 -0
- package/src/image-plugin.ts +452 -0
- package/src/image.tsx +167 -0
- package/src/index.ts +119 -0
- package/src/isr.ts +95 -0
- package/src/link.tsx +266 -0
- package/src/script.tsx +133 -0
- package/src/seo.ts +281 -0
- package/src/sharp.d.ts +20 -0
- package/src/theme.tsx +162 -0
- package/src/types.ts +130 -0
- package/src/utils/use-intersection-observer.ts +36 -0
- package/src/utils/with-headers.ts +16 -0
- package/src/vite-plugin.ts +92 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) {
|
|
6
|
+
__defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
if (!no_symbols) {
|
|
12
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/fs-router.ts
|
|
19
|
+
var fs_router_exports = /* @__PURE__ */ __exportAll({
|
|
20
|
+
filePathToUrlPath: () => filePathToUrlPath,
|
|
21
|
+
generateRouteModule: () => generateRouteModule,
|
|
22
|
+
parseFileRoutes: () => parseFileRoutes,
|
|
23
|
+
scanRouteFiles: () => scanRouteFiles
|
|
24
|
+
});
|
|
25
|
+
const ROUTE_EXTENSIONS = [
|
|
26
|
+
".tsx",
|
|
27
|
+
".jsx",
|
|
28
|
+
".ts",
|
|
29
|
+
".js"
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* Parse a set of file paths (relative to routes dir) into FileRoute objects.
|
|
33
|
+
*
|
|
34
|
+
* @param files Array of file paths like ["index.tsx", "users/[id].tsx"]
|
|
35
|
+
* @param defaultMode Default rendering mode from config
|
|
36
|
+
*/
|
|
37
|
+
function parseFileRoutes(files, defaultMode = "ssr") {
|
|
38
|
+
return files.filter((f) => ROUTE_EXTENSIONS.some((ext) => f.endsWith(ext))).map((filePath) => parseFilePath(filePath, defaultMode)).sort(sortRoutes);
|
|
39
|
+
}
|
|
40
|
+
function parseFilePath(filePath, defaultMode) {
|
|
41
|
+
let route = filePath;
|
|
42
|
+
for (const ext of ROUTE_EXTENSIONS) if (route.endsWith(ext)) {
|
|
43
|
+
route = route.slice(0, -ext.length);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
const fileName = getFileName(route);
|
|
47
|
+
const isLayout = fileName === "_layout";
|
|
48
|
+
const isError = fileName === "_error";
|
|
49
|
+
const isLoading = fileName === "_loading";
|
|
50
|
+
const isCatchAll = route.includes("[...");
|
|
51
|
+
const parts = route.split("/");
|
|
52
|
+
parts.pop();
|
|
53
|
+
const dirPath = parts.filter((s) => !(s.startsWith("(") && s.endsWith(")"))).join("/");
|
|
54
|
+
const urlPath = filePathToUrlPath(route);
|
|
55
|
+
return {
|
|
56
|
+
filePath,
|
|
57
|
+
urlPath,
|
|
58
|
+
dirPath,
|
|
59
|
+
depth: urlPath === "/" ? 0 : urlPath.split("/").filter(Boolean).length,
|
|
60
|
+
isLayout,
|
|
61
|
+
isError,
|
|
62
|
+
isLoading,
|
|
63
|
+
isCatchAll,
|
|
64
|
+
renderMode: defaultMode
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Convert a file path (without extension) to a URL path pattern.
|
|
69
|
+
*
|
|
70
|
+
* Examples:
|
|
71
|
+
* "index" → "/"
|
|
72
|
+
* "about" → "/about"
|
|
73
|
+
* "users/index" → "/users"
|
|
74
|
+
* "users/[id]" → "/users/:id"
|
|
75
|
+
* "blog/[...slug]" → "/blog/:slug*"
|
|
76
|
+
* "(auth)/login" → "/login" (group stripped)
|
|
77
|
+
* "_layout" → "/" (layout marker)
|
|
78
|
+
*/
|
|
79
|
+
function filePathToUrlPath(filePath) {
|
|
80
|
+
const segments = filePath.split("/");
|
|
81
|
+
const urlSegments = [];
|
|
82
|
+
for (const seg of segments) {
|
|
83
|
+
if (seg.startsWith("(") && seg.endsWith(")")) continue;
|
|
84
|
+
if (seg === "_layout" || seg === "_error" || seg === "_loading") continue;
|
|
85
|
+
if (seg === "index") continue;
|
|
86
|
+
const catchAll = seg.match(/^\[\.\.\.(\w+)\]$/);
|
|
87
|
+
if (catchAll) {
|
|
88
|
+
urlSegments.push(`:${catchAll[1]}*`);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const dynamic = seg.match(/^\[(\w+)\]$/);
|
|
92
|
+
if (dynamic) {
|
|
93
|
+
urlSegments.push(`:${dynamic[1]}`);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
urlSegments.push(seg);
|
|
97
|
+
}
|
|
98
|
+
return `/${urlSegments.join("/")}` || "/";
|
|
99
|
+
}
|
|
100
|
+
/** Sort routes: static before dynamic, catch-all last. */
|
|
101
|
+
function sortRoutes(a, b) {
|
|
102
|
+
if (a.isCatchAll !== b.isCatchAll) return a.isCatchAll ? 1 : -1;
|
|
103
|
+
if (a.isLayout !== b.isLayout) return a.isLayout ? -1 : 1;
|
|
104
|
+
const aDynamic = a.urlPath.includes(":");
|
|
105
|
+
if (aDynamic !== b.urlPath.includes(":")) return aDynamic ? 1 : -1;
|
|
106
|
+
return a.urlPath.localeCompare(b.urlPath);
|
|
107
|
+
}
|
|
108
|
+
function getFileName(filePath) {
|
|
109
|
+
const parts = filePath.split("/");
|
|
110
|
+
return parts[parts.length - 1] ?? "";
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Group flat file routes into a directory tree.
|
|
114
|
+
*/
|
|
115
|
+
function getOrCreateChild(node, segment) {
|
|
116
|
+
let child = node.children.get(segment);
|
|
117
|
+
if (!child) {
|
|
118
|
+
child = {
|
|
119
|
+
pages: [],
|
|
120
|
+
children: /* @__PURE__ */ new Map()
|
|
121
|
+
};
|
|
122
|
+
node.children.set(segment, child);
|
|
123
|
+
}
|
|
124
|
+
return child;
|
|
125
|
+
}
|
|
126
|
+
function resolveNode(root, dirPath) {
|
|
127
|
+
let node = root;
|
|
128
|
+
if (dirPath) for (const segment of dirPath.split("/")) node = getOrCreateChild(node, segment);
|
|
129
|
+
return node;
|
|
130
|
+
}
|
|
131
|
+
function placeRoute(node, route) {
|
|
132
|
+
if (route.isLayout) node.layout = route;
|
|
133
|
+
else if (route.isError) node.error = route;
|
|
134
|
+
else if (route.isLoading) node.loading = route;
|
|
135
|
+
else node.pages.push(route);
|
|
136
|
+
}
|
|
137
|
+
function buildRouteTree(routes) {
|
|
138
|
+
const root = {
|
|
139
|
+
pages: [],
|
|
140
|
+
children: /* @__PURE__ */ new Map()
|
|
141
|
+
};
|
|
142
|
+
for (const route of routes) placeRoute(resolveNode(root, route.dirPath), route);
|
|
143
|
+
return root;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Generate a virtual module that exports a nested route tree.
|
|
147
|
+
* Wires up layouts as parent routes with children, loaders, guards,
|
|
148
|
+
* error/loading components, middleware, and meta from route module exports.
|
|
149
|
+
*/
|
|
150
|
+
function generateRouteModule(files, routesDir) {
|
|
151
|
+
const tree = buildRouteTree(parseFileRoutes(files));
|
|
152
|
+
const imports = [];
|
|
153
|
+
let importCounter = 0;
|
|
154
|
+
function nextImport(filePath, exportName = "default") {
|
|
155
|
+
const name = `_${importCounter++}`;
|
|
156
|
+
const fullPath = `${routesDir}/${filePath}`;
|
|
157
|
+
if (exportName === "default") imports.push(`import ${name} from "${fullPath}"`);
|
|
158
|
+
else imports.push(`import { ${exportName} as ${name} } from "${fullPath}"`);
|
|
159
|
+
return name;
|
|
160
|
+
}
|
|
161
|
+
function nextLazy(filePath, loadingName, errorName) {
|
|
162
|
+
const name = `_${importCounter++}`;
|
|
163
|
+
const fullPath = `${routesDir}/${filePath}`;
|
|
164
|
+
const opts = [];
|
|
165
|
+
if (loadingName) opts.push(`loading: ${loadingName}`);
|
|
166
|
+
if (errorName) opts.push(`error: ${errorName}`);
|
|
167
|
+
const optsStr = opts.length > 0 ? `, { ${opts.join(", ")} }` : "";
|
|
168
|
+
imports.push(`const ${name} = lazy(() => import("${fullPath}")${optsStr})`);
|
|
169
|
+
return name;
|
|
170
|
+
}
|
|
171
|
+
function nextModuleImport(filePath) {
|
|
172
|
+
const name = `_m${importCounter++}`;
|
|
173
|
+
const fullPath = `${routesDir}/${filePath}`;
|
|
174
|
+
imports.push(`import * as ${name} from "${fullPath}"`);
|
|
175
|
+
return name;
|
|
176
|
+
}
|
|
177
|
+
function generatePageRoute(page, indent, loadingName, errorName) {
|
|
178
|
+
const mod = nextModuleImport(page.filePath);
|
|
179
|
+
const comp = nextLazy(page.filePath, loadingName, errorName);
|
|
180
|
+
const props = [
|
|
181
|
+
`${indent} path: ${JSON.stringify(page.urlPath)}`,
|
|
182
|
+
`${indent} component: ${comp}`,
|
|
183
|
+
`${indent} loader: ${mod}.loader`,
|
|
184
|
+
`${indent} beforeEnter: ${mod}.guard`,
|
|
185
|
+
`${indent} meta: ${mod}.meta`
|
|
186
|
+
];
|
|
187
|
+
if (errorName) props.push(`${indent} errorComponent: ${mod}.error || ${errorName}`);
|
|
188
|
+
else props.push(`${indent} errorComponent: ${mod}.error`);
|
|
189
|
+
return `${indent}{\n${props.join(",\n")}\n${indent}}`;
|
|
190
|
+
}
|
|
191
|
+
function wrapWithLayout(node, children, indent, errorName) {
|
|
192
|
+
const layout = node.layout;
|
|
193
|
+
const layoutMod = nextModuleImport(layout.filePath);
|
|
194
|
+
const layoutComp = nextImport(layout.filePath, "layout");
|
|
195
|
+
const props = [
|
|
196
|
+
`${indent}path: ${JSON.stringify(layout.urlPath)}`,
|
|
197
|
+
`${indent}component: ${layoutComp}`,
|
|
198
|
+
`${indent}loader: ${layoutMod}.loader`,
|
|
199
|
+
`${indent}beforeEnter: ${layoutMod}.guard`,
|
|
200
|
+
`${indent}meta: ${layoutMod}.meta`
|
|
201
|
+
];
|
|
202
|
+
if (errorName) props.push(`${indent}errorComponent: ${errorName}`);
|
|
203
|
+
if (children.length > 0) props.push(`${indent}children: [\n${children.join(",\n")}\n${indent}]`);
|
|
204
|
+
return `${indent}{\n${props.map((p) => ` ${p}`).join(",\n")}\n${indent}}`;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Generate route definitions for a tree node.
|
|
208
|
+
*/
|
|
209
|
+
function generateNode(node, depth) {
|
|
210
|
+
const indent = " ".repeat(depth + 1);
|
|
211
|
+
const errorName = node.error ? nextImport(node.error.filePath) : void 0;
|
|
212
|
+
const loadingName = node.loading ? nextImport(node.loading.filePath) : void 0;
|
|
213
|
+
const childRouteDefs = [];
|
|
214
|
+
for (const [, childNode] of node.children) childRouteDefs.push(...generateNode(childNode, depth + 1));
|
|
215
|
+
const allChildren = [...node.pages.map((page) => generatePageRoute(page, indent, loadingName, errorName)), ...childRouteDefs];
|
|
216
|
+
if (node.layout) return [wrapWithLayout(node, allChildren, indent, errorName)];
|
|
217
|
+
return allChildren;
|
|
218
|
+
}
|
|
219
|
+
const routeDefs = generateNode(tree, 0);
|
|
220
|
+
return [
|
|
221
|
+
`import { lazy } from "@pyreon/router"`,
|
|
222
|
+
"",
|
|
223
|
+
...imports,
|
|
224
|
+
"",
|
|
225
|
+
`function clean(routes) {`,
|
|
226
|
+
` return routes.map(r => {`,
|
|
227
|
+
` const c = {}`,
|
|
228
|
+
` for (const k in r) if (r[k] !== undefined) c[k] = r[k]`,
|
|
229
|
+
` if (c.children) c.children = clean(c.children)`,
|
|
230
|
+
` return c`,
|
|
231
|
+
` })`,
|
|
232
|
+
`}`,
|
|
233
|
+
"",
|
|
234
|
+
`export const routes = clean([`,
|
|
235
|
+
routeDefs.join(",\n"),
|
|
236
|
+
`])`
|
|
237
|
+
].join("\n");
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Scan a directory for route files.
|
|
241
|
+
* Returns paths relative to the routes directory.
|
|
242
|
+
*/
|
|
243
|
+
async function scanRouteFiles(routesDir) {
|
|
244
|
+
const { readdir } = await import("node:fs/promises");
|
|
245
|
+
const { join, relative } = await import("node:path");
|
|
246
|
+
const files = [];
|
|
247
|
+
async function walk(dir) {
|
|
248
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
249
|
+
for (const entry of entries) {
|
|
250
|
+
const fullPath = join(dir, entry.name);
|
|
251
|
+
if (entry.isDirectory()) await walk(fullPath);
|
|
252
|
+
else if (ROUTE_EXTENSIONS.some((ext) => entry.name.endsWith(ext))) files.push(relative(routesDir, fullPath));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
await walk(routesDir);
|
|
256
|
+
return files;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
//#endregion
|
|
260
|
+
export { scanRouteFiles as a, parseFileRoutes as i, fs_router_exports as n, generateRouteModule as r, filePathToUrlPath as t };
|
|
261
|
+
//# sourceMappingURL=fs-router-jfd1QGLB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-router-jfd1QGLB.js","names":[],"sources":["../src/fs-router.ts"],"sourcesContent":["import type { FileRoute, RenderMode } from './types'\n\n// ─── File-system route conventions ──────────────────────────────────────────\n//\n// src/routes/\n// _layout.tsx → layout for all routes\n// index.tsx → /\n// about.tsx → /about\n// users/\n// _layout.tsx → layout for /users/*\n// _loading.tsx → loading fallback for /users/*\n// _error.tsx → error boundary for /users/*\n// index.tsx → /users\n// [id].tsx → /users/:id\n// [id]/\n// settings.tsx → /users/:id/settings\n// blog/\n// [...slug].tsx → /blog/* (catch-all)\n//\n// Conventions:\n// [param] → dynamic segment → :param\n// [...param] → catch-all → :param*\n// _layout → layout wrapper (not a route itself)\n// _error → error component\n// _loading → loading component\n// (group) → route group (directory ignored in URL)\n\nconst ROUTE_EXTENSIONS = ['.tsx', '.jsx', '.ts', '.js']\n\n/**\n * Parse a set of file paths (relative to routes dir) into FileRoute objects.\n *\n * @param files Array of file paths like [\"index.tsx\", \"users/[id].tsx\"]\n * @param defaultMode Default rendering mode from config\n */\nexport function parseFileRoutes(\n files: string[],\n defaultMode: RenderMode = 'ssr',\n): FileRoute[] {\n return files\n .filter((f) => ROUTE_EXTENSIONS.some((ext) => f.endsWith(ext)))\n .map((filePath) => parseFilePath(filePath, defaultMode))\n .sort(sortRoutes)\n}\n\nfunction parseFilePath(filePath: string, defaultMode: RenderMode): FileRoute {\n // Remove extension\n let route = filePath\n for (const ext of ROUTE_EXTENSIONS) {\n if (route.endsWith(ext)) {\n route = route.slice(0, -ext.length)\n break\n }\n }\n\n const fileName = getFileName(route)\n const isLayout = fileName === '_layout'\n const isError = fileName === '_error'\n const isLoading = fileName === '_loading'\n const isCatchAll = route.includes('[...')\n\n // Get directory path (strip groups for consistent grouping)\n const parts = route.split('/')\n parts.pop() // remove filename\n const dirPath = parts\n .filter((s) => !(s.startsWith('(') && s.endsWith(')')))\n .join('/')\n\n // Convert file path to URL pattern\n const urlPath = filePathToUrlPath(route)\n const depth = urlPath === '/' ? 0 : urlPath.split('/').filter(Boolean).length\n\n return {\n filePath,\n urlPath,\n dirPath,\n depth,\n isLayout,\n isError,\n isLoading,\n isCatchAll,\n renderMode: defaultMode,\n }\n}\n\n/**\n * Convert a file path (without extension) to a URL path pattern.\n *\n * Examples:\n * \"index\" → \"/\"\n * \"about\" → \"/about\"\n * \"users/index\" → \"/users\"\n * \"users/[id]\" → \"/users/:id\"\n * \"blog/[...slug]\" → \"/blog/:slug*\"\n * \"(auth)/login\" → \"/login\" (group stripped)\n * \"_layout\" → \"/\" (layout marker)\n */\nexport function filePathToUrlPath(filePath: string): string {\n const segments = filePath.split('/')\n const urlSegments: string[] = []\n\n for (const seg of segments) {\n // Skip route groups \"(name)\"\n if (seg.startsWith('(') && seg.endsWith(')')) continue\n\n // Skip special files\n if (seg === '_layout' || seg === '_error' || seg === '_loading') continue\n\n // \"index\" maps to the parent path\n if (seg === 'index') continue\n\n // Catch-all: [...param] → :param*\n const catchAll = seg.match(/^\\[\\.\\.\\.(\\w+)\\]$/)\n if (catchAll) {\n urlSegments.push(`:${catchAll[1]}*`)\n continue\n }\n\n // Dynamic: [param] → :param\n const dynamic = seg.match(/^\\[(\\w+)\\]$/)\n if (dynamic) {\n urlSegments.push(`:${dynamic[1]}`)\n continue\n }\n\n urlSegments.push(seg)\n }\n\n const path = `/${urlSegments.join('/')}`\n return path || '/'\n}\n\n/** Sort routes: static before dynamic, catch-all last. */\nfunction sortRoutes(a: FileRoute, b: FileRoute): number {\n // Catch-all routes go last\n if (a.isCatchAll !== b.isCatchAll) return a.isCatchAll ? 1 : -1\n // Layouts go first within same depth\n if (a.isLayout !== b.isLayout) return a.isLayout ? -1 : 1\n // Static segments before dynamic\n const aDynamic = a.urlPath.includes(':')\n const bDynamic = b.urlPath.includes(':')\n if (aDynamic !== bDynamic) return aDynamic ? 1 : -1\n // Alphabetical\n return a.urlPath.localeCompare(b.urlPath)\n}\n\nfunction getFileName(filePath: string): string {\n const parts = filePath.split('/')\n return parts[parts.length - 1] ?? ''\n}\n\n// ─── Route generation (for Vite plugin) ─────────────────────────────────────\n\n/** Internal tree node for building nested route structures. */\ninterface RouteNode {\n /** Page routes at this directory level. */\n pages: FileRoute[]\n /** Layout file for this directory (if any). */\n layout?: FileRoute\n /** Error boundary file (if any). */\n error?: FileRoute\n /** Loading fallback file (if any). */\n loading?: FileRoute\n /** Child directories. */\n children: Map<string, RouteNode>\n}\n\n/**\n * Group flat file routes into a directory tree.\n */\nfunction getOrCreateChild(node: RouteNode, segment: string): RouteNode {\n let child = node.children.get(segment)\n if (!child) {\n child = { pages: [], children: new Map() }\n node.children.set(segment, child)\n }\n return child\n}\n\nfunction resolveNode(root: RouteNode, dirPath: string): RouteNode {\n let node = root\n if (dirPath) {\n for (const segment of dirPath.split('/')) {\n node = getOrCreateChild(node, segment)\n }\n }\n return node\n}\n\nfunction placeRoute(node: RouteNode, route: FileRoute) {\n if (route.isLayout) node.layout = route\n else if (route.isError) node.error = route\n else if (route.isLoading) node.loading = route\n else node.pages.push(route)\n}\n\nfunction buildRouteTree(routes: FileRoute[]): RouteNode {\n const root: RouteNode = { pages: [], children: new Map() }\n for (const route of routes) {\n placeRoute(resolveNode(root, route.dirPath), route)\n }\n return root\n}\n\n/**\n * Generate a virtual module that exports a nested route tree.\n * Wires up layouts as parent routes with children, loaders, guards,\n * error/loading components, middleware, and meta from route module exports.\n */\nexport function generateRouteModule(\n files: string[],\n routesDir: string,\n): string {\n const routes = parseFileRoutes(files)\n const tree = buildRouteTree(routes)\n const imports: string[] = []\n let importCounter = 0\n\n function nextImport(filePath: string, exportName = 'default'): string {\n const name = `_${importCounter++}`\n const fullPath = `${routesDir}/${filePath}`\n if (exportName === 'default') {\n imports.push(`import ${name} from \"${fullPath}\"`)\n } else {\n imports.push(`import { ${exportName} as ${name} } from \"${fullPath}\"`)\n }\n return name\n }\n\n function nextLazy(\n filePath: string,\n loadingName?: string,\n errorName?: string,\n ): string {\n const name = `_${importCounter++}`\n const fullPath = `${routesDir}/${filePath}`\n const opts: string[] = []\n if (loadingName) opts.push(`loading: ${loadingName}`)\n if (errorName) opts.push(`error: ${errorName}`)\n const optsStr = opts.length > 0 ? `, { ${opts.join(', ')} }` : ''\n imports.push(`const ${name} = lazy(() => import(\"${fullPath}\")${optsStr})`)\n return name\n }\n\n function nextModuleImport(filePath: string): string {\n const name = `_m${importCounter++}`\n const fullPath = `${routesDir}/${filePath}`\n imports.push(`import * as ${name} from \"${fullPath}\"`)\n return name\n }\n\n function generatePageRoute(\n page: FileRoute,\n indent: string,\n loadingName: string | undefined,\n errorName: string | undefined,\n ): string {\n const mod = nextModuleImport(page.filePath)\n const comp = nextLazy(page.filePath, loadingName, errorName)\n\n const props: string[] = [\n `${indent} path: ${JSON.stringify(page.urlPath)}`,\n `${indent} component: ${comp}`,\n `${indent} loader: ${mod}.loader`,\n `${indent} beforeEnter: ${mod}.guard`,\n `${indent} meta: ${mod}.meta`,\n ]\n\n if (errorName) {\n props.push(`${indent} errorComponent: ${mod}.error || ${errorName}`)\n } else {\n props.push(`${indent} errorComponent: ${mod}.error`)\n }\n\n return `${indent}{\\n${props.join(',\\n')}\\n${indent}}`\n }\n\n function wrapWithLayout(\n node: RouteNode,\n children: string[],\n indent: string,\n errorName: string | undefined,\n ): string {\n const layout = node.layout as FileRoute\n const layoutMod = nextModuleImport(layout.filePath)\n const layoutComp = nextImport(layout.filePath, 'layout')\n\n const props: string[] = [\n `${indent}path: ${JSON.stringify(layout.urlPath)}`,\n `${indent}component: ${layoutComp}`,\n `${indent}loader: ${layoutMod}.loader`,\n `${indent}beforeEnter: ${layoutMod}.guard`,\n `${indent}meta: ${layoutMod}.meta`,\n ]\n if (errorName) {\n props.push(`${indent}errorComponent: ${errorName}`)\n }\n if (children.length > 0) {\n props.push(`${indent}children: [\\n${children.join(',\\n')}\\n${indent}]`)\n }\n\n return `${indent}{\\n${props.map((p) => ` ${p}`).join(',\\n')}\\n${indent}}`\n }\n\n /**\n * Generate route definitions for a tree node.\n */\n function generateNode(node: RouteNode, depth: number): string[] {\n const indent = ' '.repeat(depth + 1)\n\n const errorName = node.error ? nextImport(node.error.filePath) : undefined\n const loadingName = node.loading\n ? nextImport(node.loading.filePath)\n : undefined\n\n const childRouteDefs: string[] = []\n for (const [, childNode] of node.children) {\n childRouteDefs.push(...generateNode(childNode, depth + 1))\n }\n\n const pageRouteDefs = node.pages.map((page) =>\n generatePageRoute(page, indent, loadingName, errorName),\n )\n\n const allChildren = [...pageRouteDefs, ...childRouteDefs]\n\n if (node.layout) {\n return [wrapWithLayout(node, allChildren, indent, errorName)]\n }\n return allChildren\n }\n\n const routeDefs = generateNode(tree, 0)\n\n return [\n `import { lazy } from \"@pyreon/router\"`,\n '',\n ...imports,\n '',\n // Filter out undefined properties at runtime\n `function clean(routes) {`,\n ` return routes.map(r => {`,\n ` const c = {}`,\n ` for (const k in r) if (r[k] !== undefined) c[k] = r[k]`,\n ` if (c.children) c.children = clean(c.children)`,\n ` return c`,\n ` })`,\n `}`,\n '',\n `export const routes = clean([`,\n routeDefs.join(',\\n'),\n `])`,\n ].join('\\n')\n}\n\n/**\n * Scan a directory for route files.\n * Returns paths relative to the routes directory.\n */\nexport async function scanRouteFiles(routesDir: string): Promise<string[]> {\n const { readdir } = await import('node:fs/promises')\n const { join, relative } = await import('node:path')\n\n const files: string[] = []\n\n async function walk(dir: string) {\n const entries = await readdir(dir, { withFileTypes: true })\n for (const entry of entries) {\n const fullPath = join(dir, entry.name)\n if (entry.isDirectory()) {\n await walk(fullPath)\n } else if (ROUTE_EXTENSIONS.some((ext) => entry.name.endsWith(ext))) {\n files.push(relative(routesDir, fullPath))\n }\n }\n }\n\n await walk(routesDir)\n return files\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,mBAAmB;CAAC;CAAQ;CAAQ;CAAO;CAAM;;;;;;;AAQvD,SAAgB,gBACd,OACA,cAA0B,OACb;AACb,QAAO,MACJ,QAAQ,MAAM,iBAAiB,MAAM,QAAQ,EAAE,SAAS,IAAI,CAAC,CAAC,CAC9D,KAAK,aAAa,cAAc,UAAU,YAAY,CAAC,CACvD,KAAK,WAAW;;AAGrB,SAAS,cAAc,UAAkB,aAAoC;CAE3E,IAAI,QAAQ;AACZ,MAAK,MAAM,OAAO,iBAChB,KAAI,MAAM,SAAS,IAAI,EAAE;AACvB,UAAQ,MAAM,MAAM,GAAG,CAAC,IAAI,OAAO;AACnC;;CAIJ,MAAM,WAAW,YAAY,MAAM;CACnC,MAAM,WAAW,aAAa;CAC9B,MAAM,UAAU,aAAa;CAC7B,MAAM,YAAY,aAAa;CAC/B,MAAM,aAAa,MAAM,SAAS,OAAO;CAGzC,MAAM,QAAQ,MAAM,MAAM,IAAI;AAC9B,OAAM,KAAK;CACX,MAAM,UAAU,MACb,QAAQ,MAAM,EAAE,EAAE,WAAW,IAAI,IAAI,EAAE,SAAS,IAAI,EAAE,CACtD,KAAK,IAAI;CAGZ,MAAM,UAAU,kBAAkB,MAAM;AAGxC,QAAO;EACL;EACA;EACA;EACA,OANY,YAAY,MAAM,IAAI,QAAQ,MAAM,IAAI,CAAC,OAAO,QAAQ,CAAC;EAOrE;EACA;EACA;EACA;EACA,YAAY;EACb;;;;;;;;;;;;;;AAeH,SAAgB,kBAAkB,UAA0B;CAC1D,MAAM,WAAW,SAAS,MAAM,IAAI;CACpC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MAAM,SAAS,GAAG;EACjE,MAAM,cAAc,KAAK,UACrB,WAAW,KAAK,QAAQ,SAAS,GACjC;EAEJ,MAAM,iBAA2B,EAAE;AACnC,OAAK,MAAM,GAAG,cAAc,KAAK,SAC/B,gBAAe,KAAK,GAAG,aAAa,WAAW,QAAQ,EAAE,CAAC;EAO5D,MAAM,cAAc,CAAC,GAJC,KAAK,MAAM,KAAK,SACpC,kBAAkB,MAAM,QAAQ,aAAa,UAAU,CACxD,EAEsC,GAAG,eAAe;AAEzD,MAAI,KAAK,OACP,QAAO,CAAC,eAAe,MAAM,aAAa,QAAQ,UAAU,CAAC;AAE/D,SAAO;;CAGT,MAAM,YAAY,aAAa,MAAM,EAAE;AAEvC,QAAO;EACL;EACA;EACA,GAAG;EACH;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,UAAU,KAAK,MAAM;EACrB;EACD,CAAC,KAAK,KAAK;;;;;;AAOd,eAAsB,eAAe,WAAsC;CACzE,MAAM,EAAE,YAAY,MAAM,OAAO;CACjC,MAAM,EAAE,MAAM,aAAa,MAAM,OAAO;CAExC,MAAM,QAAkB,EAAE;CAE1B,eAAe,KAAK,KAAa;EAC/B,MAAM,UAAU,MAAM,QAAQ,KAAK,EAAE,eAAe,MAAM,CAAC;AAC3D,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,WAAW,KAAK,KAAK,MAAM,KAAK;AACtC,OAAI,MAAM,aAAa,CACrB,OAAM,KAAK,SAAS;YACX,iBAAiB,MAAM,QAAQ,MAAM,KAAK,SAAS,IAAI,CAAC,CACjE,OAAM,KAAK,SAAS,WAAW,SAAS,CAAC;;;AAK/C,OAAM,KAAK,UAAU;AACrB,QAAO"}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { basename, extname, join } from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region src/image-plugin.ts
|
|
6
|
+
let sharpWarned = false;
|
|
7
|
+
function warnSharpMissing() {
|
|
8
|
+
if (sharpWarned) return;
|
|
9
|
+
sharpWarned = true;
|
|
10
|
+
console.warn("\n[zero:image] sharp not installed — images will not be optimized. Install for full support: bun add -D sharp\n");
|
|
11
|
+
}
|
|
12
|
+
const IMAGE_EXT_RE = /\.(jpe?g|png|webp|avif)$/i;
|
|
13
|
+
/**
|
|
14
|
+
* Zero image processing Vite plugin.
|
|
15
|
+
*
|
|
16
|
+
* Transforms image imports with query params into optimized responsive images:
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // vite.config.ts
|
|
20
|
+
* import { imagePlugin } from "@pyreon/zero/image-plugin"
|
|
21
|
+
*
|
|
22
|
+
* export default {
|
|
23
|
+
* plugins: [
|
|
24
|
+
* pyreon(),
|
|
25
|
+
* zero(),
|
|
26
|
+
* imagePlugin({ widths: [480, 960, 1440], quality: 85 }),
|
|
27
|
+
* ],
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // In a component — import with ?optimize
|
|
32
|
+
* import hero from "./images/hero.jpg?optimize"
|
|
33
|
+
* // hero = { src, srcset, width, height, placeholder }
|
|
34
|
+
*
|
|
35
|
+
* <Image {...hero} alt="Hero" priority />
|
|
36
|
+
*/
|
|
37
|
+
function imagePlugin(config = {}) {
|
|
38
|
+
const defaultWidths = config.widths ?? [
|
|
39
|
+
640,
|
|
40
|
+
1024,
|
|
41
|
+
1920
|
|
42
|
+
];
|
|
43
|
+
const defaultFormats = config.formats ?? ["webp"];
|
|
44
|
+
const quality = config.quality ?? 80;
|
|
45
|
+
const placeholderSize = config.placeholderSize ?? 16;
|
|
46
|
+
const outSubDir = config.outDir ?? "assets/img";
|
|
47
|
+
const include = config.include ?? IMAGE_EXT_RE;
|
|
48
|
+
let root = "";
|
|
49
|
+
let outDir = "";
|
|
50
|
+
let isBuild = false;
|
|
51
|
+
return {
|
|
52
|
+
name: "pyreon-zero-images",
|
|
53
|
+
enforce: "pre",
|
|
54
|
+
configResolved(resolvedConfig) {
|
|
55
|
+
root = resolvedConfig.root;
|
|
56
|
+
outDir = resolvedConfig.build.outDir;
|
|
57
|
+
isBuild = resolvedConfig.command === "build";
|
|
58
|
+
},
|
|
59
|
+
async resolveId(id) {
|
|
60
|
+
if (id.includes("?optimize") && include.test(id.split("?")[0])) return `\0virtual:zero-image:${id}`;
|
|
61
|
+
return null;
|
|
62
|
+
},
|
|
63
|
+
async load(id) {
|
|
64
|
+
if (!id.startsWith("\0virtual:zero-image:")) return null;
|
|
65
|
+
const rawPath = id.replace("\0virtual:zero-image:", "").split("?")[0] ?? id;
|
|
66
|
+
const absPath = rawPath.startsWith("/") ? join(root, "public", rawPath) : rawPath;
|
|
67
|
+
if (!isBuild) {
|
|
68
|
+
const result = await loadDevImage(absPath, rawPath, placeholderSize);
|
|
69
|
+
return `export default ${JSON.stringify(result)}`;
|
|
70
|
+
}
|
|
71
|
+
const processed = await processImage(absPath, {
|
|
72
|
+
widths: defaultWidths,
|
|
73
|
+
formats: defaultFormats,
|
|
74
|
+
quality,
|
|
75
|
+
placeholderSize,
|
|
76
|
+
outSubDir,
|
|
77
|
+
outDir: join(root, outDir)
|
|
78
|
+
});
|
|
79
|
+
await emitProcessedSources(processed, outSubDir, this);
|
|
80
|
+
rebuildFormatSrcsets(processed, absPath);
|
|
81
|
+
return `export default ${JSON.stringify(processed)}`;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
async function loadDevImage(absPath, rawPath, placeholderSize) {
|
|
86
|
+
const metadata = await getImageMetadata(absPath);
|
|
87
|
+
const publicPath = rawPath.startsWith("/") ? rawPath : `/@fs/${absPath}`;
|
|
88
|
+
return {
|
|
89
|
+
src: publicPath,
|
|
90
|
+
srcset: "",
|
|
91
|
+
width: metadata.width,
|
|
92
|
+
height: metadata.height,
|
|
93
|
+
placeholder: await generateBlurPlaceholder(absPath, placeholderSize),
|
|
94
|
+
formats: [],
|
|
95
|
+
sources: [{
|
|
96
|
+
src: publicPath,
|
|
97
|
+
width: metadata.width,
|
|
98
|
+
format: "original"
|
|
99
|
+
}]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async function emitProcessedSources(processed, outSubDir, ctx) {
|
|
103
|
+
for (const source of processed.sources) {
|
|
104
|
+
const fileName = join(outSubDir, basename(source.src));
|
|
105
|
+
const content = await readFile(source.src);
|
|
106
|
+
ctx.emitFile({
|
|
107
|
+
type: "asset",
|
|
108
|
+
fileName,
|
|
109
|
+
source: content
|
|
110
|
+
});
|
|
111
|
+
source.src = `/${fileName}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function rebuildFormatSrcsets(processed, fallbackPath) {
|
|
115
|
+
const formatGroups = /* @__PURE__ */ new Map();
|
|
116
|
+
for (const s of processed.sources) {
|
|
117
|
+
let group = formatGroups.get(s.format);
|
|
118
|
+
if (!group) {
|
|
119
|
+
group = [];
|
|
120
|
+
formatGroups.set(s.format, group);
|
|
121
|
+
}
|
|
122
|
+
group.push(`${s.src} ${s.width}w`);
|
|
123
|
+
}
|
|
124
|
+
processed.formats = [...formatGroups.entries()].map(([fmt, entries]) => ({
|
|
125
|
+
type: `image/${fmt}`,
|
|
126
|
+
srcset: entries.join(", ")
|
|
127
|
+
}));
|
|
128
|
+
processed.srcset = processed.formats.at(-1)?.srcset ?? "";
|
|
129
|
+
processed.src = processed.sources.at(-1)?.src ?? fallbackPath;
|
|
130
|
+
}
|
|
131
|
+
async function processImage(absPath, opts) {
|
|
132
|
+
const metadata = await getImageMetadata(absPath);
|
|
133
|
+
const name = basename(absPath, extname(absPath));
|
|
134
|
+
const sources = [];
|
|
135
|
+
const processedDir = join(opts.outDir, opts.outSubDir);
|
|
136
|
+
if (!existsSync(processedDir)) await mkdir(processedDir, { recursive: true });
|
|
137
|
+
for (const format of opts.formats) for (const targetWidth of opts.widths) {
|
|
138
|
+
const width = Math.min(targetWidth, metadata.width);
|
|
139
|
+
const outPath = join(processedDir, `${name}-${width}.${format}`);
|
|
140
|
+
await resizeImage(absPath, outPath, width, format, opts.quality);
|
|
141
|
+
sources.push({
|
|
142
|
+
src: outPath,
|
|
143
|
+
width,
|
|
144
|
+
format
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const formatGroups = /* @__PURE__ */ new Map();
|
|
148
|
+
for (const s of sources) {
|
|
149
|
+
let group = formatGroups.get(s.format);
|
|
150
|
+
if (!group) {
|
|
151
|
+
group = [];
|
|
152
|
+
formatGroups.set(s.format, group);
|
|
153
|
+
}
|
|
154
|
+
group.push({
|
|
155
|
+
src: s.src,
|
|
156
|
+
width: s.width
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const formats = [...formatGroups.entries()].map(([fmt, group]) => ({
|
|
160
|
+
type: `image/${fmt === "jpeg" ? "jpeg" : fmt}`,
|
|
161
|
+
srcset: group.map((s) => `${s.src} ${s.width}w`).join(", ")
|
|
162
|
+
}));
|
|
163
|
+
const fallbackFormat = formats[formats.length - 1];
|
|
164
|
+
const fallbackSources = formatGroups.get([...formatGroups.keys()].pop());
|
|
165
|
+
const placeholder = await generateBlurPlaceholder(absPath, opts.placeholderSize);
|
|
166
|
+
return {
|
|
167
|
+
src: fallbackSources[fallbackSources.length - 1]?.src ?? absPath,
|
|
168
|
+
srcset: fallbackFormat?.srcset ?? "",
|
|
169
|
+
width: metadata.width,
|
|
170
|
+
height: metadata.height,
|
|
171
|
+
placeholder,
|
|
172
|
+
formats,
|
|
173
|
+
sources
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Read basic image metadata.
|
|
178
|
+
* Uses minimal binary header parsing — no external dependencies.
|
|
179
|
+
*/
|
|
180
|
+
async function getImageMetadata(absPath) {
|
|
181
|
+
const buffer = await readFile(absPath);
|
|
182
|
+
const ext = extname(absPath).toLowerCase();
|
|
183
|
+
if (ext === ".png") return {
|
|
184
|
+
width: buffer.readUInt32BE(16),
|
|
185
|
+
height: buffer.readUInt32BE(20),
|
|
186
|
+
format: "png"
|
|
187
|
+
};
|
|
188
|
+
if (ext === ".jpg" || ext === ".jpeg") return {
|
|
189
|
+
...parseJpegDimensions(buffer),
|
|
190
|
+
format: "jpeg"
|
|
191
|
+
};
|
|
192
|
+
if (ext === ".webp") return {
|
|
193
|
+
...parseWebPDimensions(buffer),
|
|
194
|
+
format: "webp"
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
width: 0,
|
|
198
|
+
height: 0,
|
|
199
|
+
format: ext.slice(1)
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/** @internal Exported for testing */
|
|
203
|
+
function parseJpegDimensions(buffer) {
|
|
204
|
+
let offset = 2;
|
|
205
|
+
while (offset < buffer.length) {
|
|
206
|
+
if (buffer[offset] !== 255) break;
|
|
207
|
+
const marker = buffer[offset + 1];
|
|
208
|
+
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
209
|
+
const height = buffer.readUInt16BE(offset + 5);
|
|
210
|
+
return {
|
|
211
|
+
width: buffer.readUInt16BE(offset + 7),
|
|
212
|
+
height
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const length = buffer.readUInt16BE(offset + 2);
|
|
216
|
+
offset += 2 + length;
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
width: 0,
|
|
220
|
+
height: 0
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/** @internal Exported for testing */
|
|
224
|
+
function parseWebPDimensions(buffer) {
|
|
225
|
+
const chunk = buffer.toString("ascii", 12, 16);
|
|
226
|
+
if (chunk === "VP8 ") return {
|
|
227
|
+
width: buffer.readUInt16LE(26) & 16383,
|
|
228
|
+
height: buffer.readUInt16LE(28) & 16383
|
|
229
|
+
};
|
|
230
|
+
if (chunk === "VP8L") {
|
|
231
|
+
const bits = buffer.readUInt32LE(21);
|
|
232
|
+
return {
|
|
233
|
+
width: (bits & 16383) + 1,
|
|
234
|
+
height: (bits >> 14 & 16383) + 1
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
if (chunk === "VP8X") return {
|
|
238
|
+
width: 1 + ((buffer[24] | buffer[25] << 8 | buffer[26] << 16) & 16777215),
|
|
239
|
+
height: 1 + ((buffer[27] | buffer[28] << 8 | buffer[29] << 16) & 16777215)
|
|
240
|
+
};
|
|
241
|
+
return {
|
|
242
|
+
width: 0,
|
|
243
|
+
height: 0
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Resize an image using native platform capabilities.
|
|
248
|
+
* Uses sharp if available, falls back to canvas API.
|
|
249
|
+
*/
|
|
250
|
+
async function resizeImage(input, output, width, format, quality) {
|
|
251
|
+
try {
|
|
252
|
+
let pipeline = (await import("sharp").then((m) => m.default ?? m))(input).resize(width);
|
|
253
|
+
switch (format) {
|
|
254
|
+
case "webp":
|
|
255
|
+
pipeline = pipeline.webp({ quality });
|
|
256
|
+
break;
|
|
257
|
+
case "avif":
|
|
258
|
+
pipeline = pipeline.avif({ quality });
|
|
259
|
+
break;
|
|
260
|
+
case "jpeg":
|
|
261
|
+
pipeline = pipeline.jpeg({
|
|
262
|
+
quality,
|
|
263
|
+
mozjpeg: true
|
|
264
|
+
});
|
|
265
|
+
break;
|
|
266
|
+
case "png":
|
|
267
|
+
pipeline = pipeline.png({ compressionLevel: 9 });
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
await pipeline.toFile(output);
|
|
271
|
+
} catch {
|
|
272
|
+
warnSharpMissing();
|
|
273
|
+
await writeFile(output, await readFile(input));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Generate a tiny blur placeholder as a base64 data URI.
|
|
278
|
+
*/
|
|
279
|
+
async function generateBlurPlaceholder(input, size) {
|
|
280
|
+
try {
|
|
281
|
+
return `data:image/webp;base64,${(await (await import("sharp").then((m) => m.default ?? m))(input).resize(size, size, { fit: "inside" }).blur(2).webp({ quality: 20 }).toBuffer()).toString("base64")}`;
|
|
282
|
+
} catch {
|
|
283
|
+
return "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1' height='1'%3E%3C/svg%3E";
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
//#endregion
|
|
288
|
+
export { imagePlugin, parseJpegDimensions, parseWebPDimensions };
|
|
289
|
+
//# sourceMappingURL=image-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-plugin.js","names":[],"sources":["../src/image-plugin.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { mkdir, readFile, writeFile } from 'node:fs/promises'\nimport { basename, extname, join } from 'node:path'\nimport type { Plugin } from 'vite'\n\nlet sharpWarned = false\nfunction warnSharpMissing() {\n if (sharpWarned) return\n sharpWarned = true\n // biome-ignore lint/suspicious/noConsole: intentional build-time warning\n console.warn(\n '\\n[zero:image] sharp not installed — images will not be optimized. Install for full support: bun add -D sharp\\n',\n )\n}\n\n// ─── Image processing Vite plugin ──────────────────────────────────────────\n//\n// Processes images at build time:\n// - Generates multiple sizes for responsive srcset\n// - Converts to modern formats (WebP, AVIF)\n// - Creates tiny blur placeholders (base64 inline)\n// - Outputs optimized images to the build directory\n//\n// Usage in code:\n// import heroImg from \"./hero.jpg?optimize\"\n// // → { src, srcset, width, height, placeholder }\n//\n// Or use the component helper:\n// import { Image } from \"@pyreon/zero/image\"\n// <Image src=\"/hero.jpg\" width={1920} height={1080} optimize />\n\nexport interface ImagePluginConfig {\n /** Output directory for processed images. Default: \"assets/img\" */\n outDir?: string\n /** Default widths for responsive images. Default: [640, 1024, 1920] */\n widths?: number[]\n /** Output formats. Default: [\"webp\"] */\n formats?: ImageFormat[]\n /** Quality for lossy formats (1-100). Default: 80 */\n quality?: number\n /** Blur placeholder size in px. Default: 16 */\n placeholderSize?: number\n /** File patterns to process. Default: /\\.(jpe?g|png|webp|avif)$/i */\n include?: RegExp\n}\n\nexport type ImageFormat = 'webp' | 'avif' | 'jpeg' | 'png'\n\n/** Per-format source set for <picture> <source> elements. */\nexport interface FormatSource {\n /** MIME type. e.g. \"image/webp\", \"image/avif\" */\n type: string\n /** srcset string for this format. e.g. \"/img-640.webp 640w, /img-1920.webp 1920w\" */\n srcset: string\n}\n\nexport interface ProcessedImage {\n /** Fallback source path (last format, largest width). */\n src: string\n /** Fallback srcset string (last format). */\n srcset: string\n /** Intrinsic width. */\n width: number\n /** Intrinsic height. */\n height: number\n /** Base64 blur placeholder data URI. */\n placeholder: string\n /** Per-format source sets for <picture> element. Ordered by priority (best format first). */\n formats: FormatSource[]\n /** Flat list of all sources. */\n sources: Array<{ src: string; width: number; format: string }>\n}\n\nconst IMAGE_EXT_RE = /\\.(jpe?g|png|webp|avif)$/i\n\n/**\n * Zero image processing Vite plugin.\n *\n * Transforms image imports with query params into optimized responsive images:\n *\n * @example\n * // vite.config.ts\n * import { imagePlugin } from \"@pyreon/zero/image-plugin\"\n *\n * export default {\n * plugins: [\n * pyreon(),\n * zero(),\n * imagePlugin({ widths: [480, 960, 1440], quality: 85 }),\n * ],\n * }\n *\n * @example\n * // In a component — import with ?optimize\n * import hero from \"./images/hero.jpg?optimize\"\n * // hero = { src, srcset, width, height, placeholder }\n *\n * <Image {...hero} alt=\"Hero\" priority />\n */\nexport function imagePlugin(config: ImagePluginConfig = {}): Plugin {\n const defaultWidths = config.widths ?? [640, 1024, 1920]\n const defaultFormats = config.formats ?? ['webp']\n const quality = config.quality ?? 80\n const placeholderSize = config.placeholderSize ?? 16\n const outSubDir = config.outDir ?? 'assets/img'\n const include = config.include ?? IMAGE_EXT_RE\n\n let root = ''\n let outDir = ''\n let isBuild = false\n\n return {\n name: 'pyreon-zero-images',\n enforce: 'pre',\n\n configResolved(resolvedConfig) {\n root = resolvedConfig.root\n outDir = resolvedConfig.build.outDir\n isBuild = resolvedConfig.command === 'build'\n },\n\n async resolveId(id) {\n // Handle ?optimize query on image imports\n if (id.includes('?optimize') && include.test(id.split('?')[0]!)) {\n return `\\0virtual:zero-image:${id}`\n }\n return null\n },\n\n async load(id) {\n if (!id.startsWith('\\0virtual:zero-image:')) return null\n\n const rawPath =\n id.replace('\\0virtual:zero-image:', '').split('?')[0] ?? id\n const absPath = rawPath.startsWith('/')\n ? join(root, 'public', rawPath)\n : rawPath\n\n if (!isBuild) {\n const result = await loadDevImage(absPath, rawPath, placeholderSize)\n return `export default ${JSON.stringify(result)}`\n }\n\n const processed = await processImage(absPath, {\n widths: defaultWidths,\n formats: defaultFormats,\n quality,\n placeholderSize,\n outSubDir,\n outDir: join(root, outDir),\n })\n\n await emitProcessedSources(processed, outSubDir, this)\n rebuildFormatSrcsets(processed, absPath)\n\n return `export default ${JSON.stringify(processed)}`\n },\n }\n}\n\nasync function loadDevImage(\n absPath: string,\n rawPath: string,\n placeholderSize: number,\n): Promise<ProcessedImage> {\n const metadata = await getImageMetadata(absPath)\n const publicPath = rawPath.startsWith('/') ? rawPath : `/@fs/${absPath}`\n\n return {\n src: publicPath,\n srcset: '',\n width: metadata.width,\n height: metadata.height,\n placeholder: await generateBlurPlaceholder(absPath, placeholderSize),\n formats: [],\n sources: [{ src: publicPath, width: metadata.width, format: 'original' }],\n }\n}\n\nasync function emitProcessedSources(\n processed: ProcessedImage,\n outSubDir: string,\n ctx: {\n emitFile: (f: {\n type: 'asset'\n fileName: string\n source: Uint8Array\n }) => void\n },\n) {\n for (const source of processed.sources) {\n const fileName = join(outSubDir, basename(source.src))\n const content = await readFile(source.src)\n ctx.emitFile({ type: 'asset', fileName, source: content })\n source.src = `/${fileName}`\n }\n}\n\nfunction rebuildFormatSrcsets(processed: ProcessedImage, fallbackPath: string) {\n const formatGroups = new Map<string, string[]>()\n for (const s of processed.sources) {\n let group = formatGroups.get(s.format)\n if (!group) {\n group = []\n formatGroups.set(s.format, group)\n }\n group.push(`${s.src} ${s.width}w`)\n }\n processed.formats = [...formatGroups.entries()].map(([fmt, entries]) => ({\n type: `image/${fmt}`,\n srcset: entries.join(', '),\n }))\n\n const lastFormat = processed.formats.at(-1)\n processed.srcset = lastFormat?.srcset ?? ''\n processed.src = processed.sources.at(-1)?.src ?? fallbackPath\n}\n\n// ─── Image processing utilities ─────────────────────────────────────────────\n\ninterface ProcessOptions {\n widths: number[]\n formats: ImageFormat[]\n quality: number\n placeholderSize: number\n outSubDir: string\n outDir: string\n}\n\nasync function processImage(\n absPath: string,\n opts: ProcessOptions,\n): Promise<ProcessedImage> {\n const metadata = await getImageMetadata(absPath)\n const ext = extname(absPath)\n const name = basename(absPath, ext)\n const sources: Array<{ src: string; width: number; format: string }> = []\n\n // Ensure output directory exists\n const processedDir = join(opts.outDir, opts.outSubDir)\n if (!existsSync(processedDir)) {\n await mkdir(processedDir, { recursive: true })\n }\n\n // Generate resized variants — iterate formats first so sources are grouped by format\n for (const format of opts.formats) {\n for (const targetWidth of opts.widths) {\n // Don't upscale\n const width = Math.min(targetWidth, metadata.width)\n const outName = `${name}-${width}.${format}`\n const outPath = join(processedDir, outName)\n\n await resizeImage(absPath, outPath, width, format, opts.quality)\n sources.push({ src: outPath, width, format })\n }\n }\n\n // Build per-format source sets for <picture>\n const formatGroups = new Map<string, Array<{ src: string; width: number }>>()\n for (const s of sources) {\n let group = formatGroups.get(s.format)\n if (!group) {\n group = []\n formatGroups.set(s.format, group)\n }\n group.push({ src: s.src, width: s.width })\n }\n\n const formats: FormatSource[] = [...formatGroups.entries()].map(\n ([fmt, group]) => ({\n type: `image/${fmt === 'jpeg' ? 'jpeg' : fmt}`,\n srcset: group.map((s) => `${s.src} ${s.width}w`).join(', '),\n }),\n )\n\n // Fallback: last format's srcset\n const fallbackFormat = formats[formats.length - 1]\n const fallbackSources = formatGroups.get([...formatGroups.keys()].pop()!)!\n\n // Generate blur placeholder\n const placeholder = await generateBlurPlaceholder(\n absPath,\n opts.placeholderSize,\n )\n\n return {\n src: fallbackSources[fallbackSources.length - 1]?.src ?? absPath,\n srcset: fallbackFormat?.srcset ?? '',\n width: metadata.width,\n height: metadata.height,\n placeholder,\n formats,\n sources,\n }\n}\n\ninterface ImageMetadata {\n width: number\n height: number\n format: string\n}\n\n/**\n * Read basic image metadata.\n * Uses minimal binary header parsing — no external dependencies.\n */\nasync function getImageMetadata(absPath: string): Promise<ImageMetadata> {\n const buffer = await readFile(absPath)\n const ext = extname(absPath).toLowerCase()\n\n if (ext === '.png') {\n // PNG: width at bytes 16-19, height at 20-23 (big-endian)\n const width = buffer.readUInt32BE(16)\n const height = buffer.readUInt32BE(20)\n return { width, height, format: 'png' }\n }\n\n if (ext === '.jpg' || ext === '.jpeg') {\n // JPEG: scan for SOF markers\n const dimensions = parseJpegDimensions(buffer)\n return { ...dimensions, format: 'jpeg' }\n }\n\n if (ext === '.webp') {\n // WebP: VP8 header\n const dimensions = parseWebPDimensions(buffer)\n return { ...dimensions, format: 'webp' }\n }\n\n // Fallback\n return { width: 0, height: 0, format: ext.slice(1) }\n}\n\n/** @internal Exported for testing */\nexport function parseJpegDimensions(buffer: Buffer): {\n width: number\n height: number\n} {\n let offset = 2 // Skip SOI marker\n while (offset < buffer.length) {\n if (buffer[offset] !== 0xff) break\n const marker = buffer[offset + 1]!\n // SOF markers (0xC0-0xCF except 0xC4, 0xC8, 0xCC)\n if (\n marker >= 0xc0 &&\n marker <= 0xcf &&\n marker !== 0xc4 &&\n marker !== 0xc8 &&\n marker !== 0xcc\n ) {\n const height = buffer.readUInt16BE(offset + 5)\n const width = buffer.readUInt16BE(offset + 7)\n return { width, height }\n }\n const length = buffer.readUInt16BE(offset + 2)\n offset += 2 + length\n }\n return { width: 0, height: 0 }\n}\n\n/** @internal Exported for testing */\nexport function parseWebPDimensions(buffer: Buffer): {\n width: number\n height: number\n} {\n // RIFF header: bytes 0-3 = \"RIFF\", 8-11 = \"WEBP\"\n const chunk = buffer.toString('ascii', 12, 16)\n if (chunk === 'VP8 ') {\n // Lossy VP8\n const width = buffer.readUInt16LE(26) & 0x3fff\n const height = buffer.readUInt16LE(28) & 0x3fff\n return { width, height }\n }\n if (chunk === 'VP8L') {\n // Lossless VP8L\n const bits = buffer.readUInt32LE(21)\n const width = (bits & 0x3fff) + 1\n const height = ((bits >> 14) & 0x3fff) + 1\n return { width, height }\n }\n if (chunk === 'VP8X') {\n // Extended VP8X\n const width =\n 1 + ((buffer[24]! | (buffer[25]! << 8) | (buffer[26]! << 16)) & 0xffffff)\n const height =\n 1 + ((buffer[27]! | (buffer[28]! << 8) | (buffer[29]! << 16)) & 0xffffff)\n return { width, height }\n }\n return { width: 0, height: 0 }\n}\n\n/**\n * Resize an image using native platform capabilities.\n * Uses sharp if available, falls back to canvas API.\n */\nasync function resizeImage(\n input: string,\n output: string,\n width: number,\n format: ImageFormat,\n quality: number,\n): Promise<void> {\n try {\n // Try sharp (the standard Node.js image processing library)\n const sharp = await import('sharp').then((m) => m.default ?? m)\n let pipeline = sharp(input).resize(width)\n\n switch (format) {\n case 'webp':\n pipeline = pipeline.webp({ quality })\n break\n case 'avif':\n pipeline = pipeline.avif({ quality })\n break\n case 'jpeg':\n pipeline = pipeline.jpeg({ quality, mozjpeg: true })\n break\n case 'png':\n pipeline = pipeline.png({ compressionLevel: 9 })\n break\n }\n\n await pipeline.toFile(output)\n } catch {\n // sharp not available — copy original as fallback\n warnSharpMissing()\n const content = await readFile(input)\n await writeFile(output, content)\n }\n}\n\n/**\n * Generate a tiny blur placeholder as a base64 data URI.\n */\nasync function generateBlurPlaceholder(\n input: string,\n size: number,\n): Promise<string> {\n try {\n const sharp = await import('sharp').then((m) => m.default ?? m)\n const buffer = await sharp(input)\n .resize(size, size, { fit: 'inside' })\n .blur(2)\n .webp({ quality: 20 })\n .toBuffer()\n\n return `data:image/webp;base64,${buffer.toString('base64')}`\n } catch {\n // sharp not available — return a transparent placeholder\n return \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1' height='1'%3E%3C/svg%3E\"\n }\n}\n"],"mappings":";;;;;AAKA,IAAI,cAAc;A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