UNPKG

@nolebase/markdown-it-unlazy-img

Version:

A markdown-it plugin wraps and transforms image tags to support lazy loading, blurhash, thumbhash, and more.

119 lines (116 loc) 3.68 kB
import { PluginWithOptions } from 'markdown-it'; interface ThumbHashAsset { /** * The file name of the image. Will be normalized to be relative to the * root of the VitePress configuration file. */ assetFileName: string; /** * The full file name of the image. */ assetFullFileName: string; /** * The hash of the image. */ assetFullHash: string; /** * The base64 encoded url safe hash of the image. */ assetFileHash: string; /** * The asset URL of the image. Will be used to render as `src` attribute * in the HTML. */ assetUrl: string; /** * The asset URL of the image with base. Will be used to render as `data-src` * attribute in the HTML used by unlazy. * * Value will be automatically calculated based on the `base` field * configured in the VitePress configuration. */ assetUrlWithBase: string; } interface ThumbHashCalculated { /** * The thumbhash data URL of the image. Will be used to render as * `src` attribute in the HTML. */ dataUrl: string; /** * The thumbhash data base64 of the image. Will be used to render as * `data-thumbhash` attribute in the HTML. */ dataBase64: string; /** * The resized width of the image (thumbhash requires the image to be * resized to less than 100px in width or height). */ width: number; /** * The original width of the image. */ originalWidth: number; /** * The resized height of the image (thumbhash requires the image to * be resized to less than 100px in width or height). */ height: number; /** * The original height of the image. */ originalHeight: number; } type ThumbHash = ThumbHashAsset & ThumbHashCalculated; interface ThumbnailImageThumbhashOptionsGlobPattern { /** * The glob pattern to search for the thumbhash map file. * * @default Array ['**\/.vitepress/cache/@nolebase/vitepress-plugin-thumbnail-hash/thumbhashes/map.json', '**\/thumbhashes/map.json'] */ mapGlobPatterns: string | string[]; } interface ThumbnailImageThumbhashOptionsPath { /** * The path to the thumbhash map file. * * @default '' */ mapFilePath: string; } interface ThumbnailImageThumbhashOptionsMap { /** * The thumbhash map object. * * @default {} */ map: Record<string, ThumbHash>; } type ThumbnailImageThumbhashOptions = ThumbnailImageThumbhashOptionsGlobPattern | ThumbnailImageThumbhashOptionsPath | ThumbnailImageThumbhashOptionsMap; interface UnlazyImagesOptions { /** * The tag name of the image element. * * @default string 'NolebaseEnhancedImg' */ imgElementTag?: string; /** * The thumbhash options. * * @default { mapGlobPatterns: ['**\/.vitepress/cache/@nolebase/vitepress-plugin-thumbnail-hash/thumbhashes/map.json', '**\/thumbhashes/map.json'] } */ thumbhash?: ThumbnailImageThumbhashOptions; /** * Log format not supported warning */ logFormatNotSupportedWarning?: boolean; } /** * The same regexp as VitePress uses * https://github.com/vuejs/vitepress/blob/3113dad002e60312ca7b679cf38b887196c33303/src/shared/shared.ts#L17 * * Used in https://github.com/vuejs/vitepress/blob/3113dad002e60312ca7b679cf38b887196c33303/src/node/markdown/plugins/image.ts#L19 */ declare const EXTERNAL_URL_RE: RegExp; declare const UnlazyImages: () => PluginWithOptions<UnlazyImagesOptions>; export { EXTERNAL_URL_RE, type ThumbHash, type ThumbHashAsset, type ThumbHashCalculated, UnlazyImages, type UnlazyImagesOptions };