full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -1,7 +1,29 @@
import type * as vite from 'vite';
import type { ImageMetadata } from '../../types.js';
type FileEmitter = vite.Rollup.EmitFile;
type ImageMetadataWithContents = ImageMetadata & {
contents?: Buffer;
};
/**
* Processes an image file and emits its metadata and optionally its contents. This function supports both build and development modes.
*
* @param {string | undefined} id - The identifier or path of the image file to process. If undefined, the function returns immediately.
* @param {boolean} _watchMode - **Deprecated**: Indicates if the method is operating in watch mode. This parameter will be removed or updated in the future.
* @param {boolean} _experimentalSvgEnabled - **Deprecated**: A flag to enable experimental handling of SVG files. Embeds SVG file data if set to true.
* @param {FileEmitter | undefined} [fileEmitter] - Function for emitting files during the build process. May throw in certain scenarios.
* @return {Promise<ImageMetadataWithContents | undefined>} Resolves to metadata with optional image contents or `undefined` if processing fails.
*/
export declare function emitESMImage(id: string | undefined,
/** @deprecated */
_watchMode: boolean, fileEmitter?: FileEmitter): Promise<ImageMetadata | undefined>;
_watchMode: boolean,
/** @deprecated */
_experimentalSvgEnabled: boolean, fileEmitter?: FileEmitter): Promise<ImageMetadataWithContents | undefined>;
/**
* Processes an image file and emits its metadata and optionally its contents. This function supports both build and development modes.
*
* @param {string | undefined} id - The identifier or path of the image file to process. If undefined, the function returns immediately.
* @param {FileEmitter | undefined} [fileEmitter] - Function for emitting files during the build process. May throw in certain scenarios.
* @return {Promise<ImageMetadataWithContents | undefined>} Resolves to metadata with optional image contents or `undefined` if processing fails.
*/
export declare function emitImageMetadata(id: string | undefined, fileEmitter?: FileEmitter): Promise<ImageMetadataWithContents | undefined>;
export {};

View File

@@ -3,7 +3,51 @@ import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { prependForwardSlash, slash } from "../../../core/path.js";
import { imageMetadata } from "../metadata.js";
async function emitESMImage(id, _watchMode, fileEmitter) {
async function emitESMImage(id, _watchMode, _experimentalSvgEnabled, fileEmitter) {
if (!id) {
return void 0;
}
const url = pathToFileURL(id);
let fileData;
try {
fileData = await fs.readFile(url);
} catch {
return void 0;
}
const fileMetadata = await imageMetadata(fileData, id);
const emittedImage = {
src: "",
...fileMetadata
};
Object.defineProperty(emittedImage, "fsPath", {
enumerable: false,
writable: false,
value: id
});
let isBuild = typeof fileEmitter === "function";
if (isBuild) {
const pathname = decodeURI(url.pathname);
const filename = path.basename(pathname, path.extname(pathname) + `.${fileMetadata.format}`);
try {
const handle = fileEmitter({
name: filename,
source: await fs.readFile(url),
type: "asset"
});
emittedImage.src = `__ASTRO_ASSET_IMAGE__${handle}__`;
} catch {
isBuild = false;
}
}
if (!isBuild) {
url.searchParams.append("origWidth", fileMetadata.width.toString());
url.searchParams.append("origHeight", fileMetadata.height.toString());
url.searchParams.append("origFormat", fileMetadata.format);
emittedImage.src = `/@fs` + prependForwardSlash(fileURLToNormalizedPath(url));
}
return emittedImage;
}
async function emitImageMetadata(id, fileEmitter) {
if (!id) {
return void 0;
}
@@ -51,5 +95,6 @@ function fileURLToNormalizedPath(filePath) {
return slash(fileURLToPath(filePath) + filePath.search).replace(/\\/g, "/");
}
export {
emitESMImage
emitESMImage,
emitImageMetadata
};