/// /** * [[include:src/codecs/rpng/README.md]] * * @module codecs/rpng */ import schema from '@stencila/schema'; import { Chunk } from 'png-chunks-extract'; import * as vfile from '../../util/vfile'; import { Codec, CommonEncodeOptions } from '../types'; export declare class RpngCodec extends Codec implements Codec { /** * @override Overrides {@link PngCodec.mediaTypes} to provide * a vendor media type similar to [image/vnd.mozilla.apng](https://www.iana.org/assignments/media-types/image/vnd.mozilla.apng) * for example. */ readonly mediaTypes: string[]; /** * @override Overrides {@link PngCodec.extNames} to provide * an extension name to match files with this codec. */ readonly extNames: string[]; /** * Sniff a PNG file to see if it is an RPNG * * @param source The source to sniff (a file path) */ readonly sniff: (source: string) => Promise; /** * Decode a RPNG to a Stencila node. * * This is done by extracting the JSON * from the `tEXt` chunk and parsing it. * * @param file The `VFile` to decode * @returns The Stencila node */ readonly decode: (file: vfile.VFile) => Promise; /** * Sniff and decode a RPNG to a Stencila node. * * Combines the `sniff` and `decode` methods. * Doing so is more efficient if both operations are needed * because the image does not need to be read twice. * * @param source The source to sniff (a file path) * @returns The Stencila node if any, `undefined` otherwise */ readonly sniffDecode: (source: string) => Promise; /** * @override Overrides {@link Codec.preWrite} so that media files * do NOT get written to a sibling folder (since they are embedded * in the PNG file). */ preWrite(node: schema.Node): Promise; /** * Encode a Stencila node to a RPNG. * * @param node The Stencila node to encode * @param options Object containing settings for the encoder. */ readonly encode: (node: schema.Node, options?: CommonEncodeOptions) => Promise; } /** * Find a text chunk in an image * * @param chunks The image chunks to search through * @param keyword The keyword for the text chunk */ export declare function find(chunks: Chunk[], keyword?: string): [number, string | undefined]; /** * Does an image have a text chunk with the given keyword? * * @param image The image `Buffer` * @param keyword The keyword for the text chunk */ export declare function has(image: Buffer, keyword?: string): boolean; /** * Extract a text chunk from an image * * @param image The image `Buffer` * @param keyword The keyword for the text chunk */ export declare function extract(image: Buffer, keyword?: string): string; /** * Insert a text chunk into an image * * @param text The text to insert * @param image The image to insert into * @param keyword The keyword for the text chunk * @param type The type of chunk to insert */ export declare function insert(text: string, image: Buffer, keyword?: string, type?: 'tEXt' | 'zTXt'): Buffer;