UNPKG

asciidoctor-kroki

Version:

Asciidoctor extension to convert diagrams to images using Kroki

98 lines 4.2 kB
export type VfsImage = { /** * - Directory (relative or absolute) where the file should be written. */ relative: string; /** * - File name including extension. */ basename: string; /** * - MIME type of the image (e.g. `image/svg+xml`, `image/png`). */ mediaType: string; /** * - Raw file contents. */ contents: Buffer; }; export type Vfs = { /** * Persists a rendered diagram image. The Node.js default creates the target directory * recursively and writes the file synchronously. */ add: (image: VfsImage) => void; /** * Returns `true` when the file at the given path already exists, allowing the extension * to skip a Kroki network request for previously generated diagrams. */ exists: (path: string) => boolean; /** * Reads a file and returns its contents. Accepts local filesystem paths, `file://` URIs, * and `http://`/`https://` URLs (fetched via the built-in HTTP client). * Custom implementations may use the optional `resource` (diagram resource identity, * e.g. an Antora resource id) to resolve the path. */ read: (path: string, encoding?: BufferEncoding, resource?: { [key: string]: string; }) => Promise<string>; /** * Parses a resource identifier into its directory and full path components. * Backslashes are normalised to forward slashes so that path.posix operations * work correctly on Windows. */ parse: (resourceId: string, resource?: { [key: string]: string; }) => { dir: string; path: string; }; }; /** * Descriptor for a diagram image to be persisted by {@link Vfs#add}. * * @typedef {Object} VfsImage * @property {string} relative - Directory (relative or absolute) where the file should be written. * @property {string} basename - File name including extension. * @property {string} mediaType - MIME type of the image (e.g. `image/svg+xml`, `image/png`). * @property {Buffer} contents - Raw file contents. */ /** * Virtual filesystem interface that abstracts file I/O for both Node.js and browser environments. * Pass a custom implementation to the Asciidoctor extension to redirect reads and writes * (e.g. to an in-memory store or a bundler's asset pipeline). * Any method that is omitted falls back to the Node.js implementation provided by {@link nodefs}. * * @typedef {Object} Vfs * @property {(image: VfsImage) => void} add * Persists a rendered diagram image. The Node.js default creates the target directory * recursively and writes the file synchronously. * @property {(path: string) => boolean} exists * Returns `true` when the file at the given path already exists, allowing the extension * to skip a Kroki network request for previously generated diagrams. * @property {(path: string, encoding?: BufferEncoding, resource?: {[key: string]: string}) => Promise<string>} read * Reads a file and returns its contents. Accepts local filesystem paths, `file://` URIs, * and `http://`/`https://` URLs (fetched via the built-in HTTP client). * Custom implementations may use the optional `resource` (diagram resource identity, * e.g. an Antora resource id) to resolve the path. * @property {(resourceId: string, resource?: {[key: string]: string}) => {dir: string, path: string}} parse * Parses a resource identifier into its directory and full path components. * Backslashes are normalised to forward slashes so that path.posix operations * work correctly on Windows. */ /** * Default Node.js virtual filesystem implementation backed by `node:fs`. * * @type {Vfs} */ declare const nodefs: Vfs; /** * Resolves a complete {@link Vfs} implementation by merging the provided `vfs` object * with {@link nodefs} fallbacks for any missing methods. * * @param {Partial<Vfs>|undefined} vfs - Custom VFS implementation, or `undefined` to use Node.js defaults entirely. * @returns {Vfs} A fully-resolved VFS with all four methods defined. */ export declare function resolveVfs(vfs: Partial<Vfs> | undefined): Vfs; export default nodefs; //# sourceMappingURL=node-fs.d.ts.map