blank project

This commit is contained in:
root
2025-10-17 20:17:33 +00:00
commit 14b2d53e8e
9366 changed files with 1515019 additions and 0 deletions

View File

@@ -0,0 +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,
/** @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 {};

142
node_modules/astro/dist/assets/utils/node/emitAsset.js generated vendored Normal file
View File

@@ -0,0 +1,142 @@
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { generateContentHash } from "../../../core/encryption.js";
import { prependForwardSlash, slash } from "../../../core/path.js";
import { imageMetadata } from "../metadata.js";
const svgContentCache = /* @__PURE__ */ new WeakMap();
const keyRegistry = /* @__PURE__ */ new Map();
function keyFor(hash) {
let key = keyRegistry.get(hash);
if (!key) {
key = { hash };
keyRegistry.set(hash, key);
}
return key;
}
async function handleSvgDeduplication(fileData, filename, fileEmitter) {
const contentHash = await generateContentHash(fileData.buffer);
const key = keyFor(contentHash);
const existing = svgContentCache.get(key);
if (existing) {
const handle = fileEmitter({
name: existing.filename,
source: fileData,
type: "asset"
});
return handle;
} else {
const handle = fileEmitter({
name: filename,
source: fileData,
type: "asset"
});
svgContentCache.set(key, { handle, filename });
return handle;
}
}
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 {
let handle;
if (fileMetadata.format === "svg") {
handle = await handleSvgDeduplication(fileData, filename, fileEmitter);
} else {
handle = fileEmitter({
name: filename,
source: fileData,
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;
}
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 {
let handle;
if (fileMetadata.format === "svg") {
handle = await handleSvgDeduplication(fileData, filename, fileEmitter);
} else {
handle = fileEmitter({
name: filename,
source: fileData,
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;
}
function fileURLToNormalizedPath(filePath) {
return slash(fileURLToPath(filePath) + filePath.search).replace(/\\/g, "/");
}
export {
emitESMImage,
emitImageMetadata
};