npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@knewbeing/markdown-it-unlazy-img

v1.1.1

Published

[![npm version](https://img.shields.io/npm/v/@knewbeing/markdown-it-unlazy-img.svg)](https://www.npmjs.com/package/@knewbeing/markdown-it-unlazy-img) [![license](https://img.shields.io/npm/l/@knewbeing/markdown-it-unlazy-img.svg)](./LICENSE)

Readme

@knewbeing/markdown-it-unlazy-img

npm version license

将 Markdown 图片渲染为支持 ThumbHash 低清占位的懒加载组件的 markdown-it 插件。

基于 unlazy 的懒加载方案,配合 ThumbHash 算法为图片生成约 30 bytes 的模糊占位,实现渐进式图片加载体验。


版权声明 / Copyright

本包代码派生自 @nolebase/markdown-it-unlazy-img(MIT 许可证)。
原始版权归 nolebase 所有。
knewbeing(知在,[email protected])改进并重新发布,修改部分仍遵循 MIT 许可证。

This package is derived from @nolebase/markdown-it-unlazy-img (MIT License).
Original copyright belongs to nolebase.
Improved and republished by knewbeing ([email protected]). Modifications remain under MIT License.


功能特性 / Features

  • 🖼 ThumbHash 占位 — 读取预生成的 ThumbHash map 文件,为每张图片附加 thumbhashplaceholderSrc 属性
  • 📐 尺寸保留 — 自动填充图片的原始宽高(width/height),防止布局抖动
  • 📦 自定义组件标签 — 默认输出 <UnLazyImage>,可通过 imgElementTag 自定义
  • 🔗 外链跳过 — 自动跳过外部 URL 和不支持的图片格式(仅处理 .png/.jpg/.jpeg
  • 🗺 灵活的 map 来源 — 支持直接传入 map 对象、指定文件路径或 glob 扫描三种方式

安装 / Installation

npm install @knewbeing/markdown-it-unlazy-img
# or
pnpm add @knewbeing/markdown-it-unlazy-img

前置条件 / Prerequisites

使用本插件前,需先通过 ThumbHash 工具生成图片的 map 文件(thumbhashes/map.json)。
该文件通常由 @nolebase/vitepress-plugin-thumbnail-hash 在构建时自动生成。


快速开始 / Quick Start

在 VitePress 中使用

// .vitepress/config.ts
import { defineConfig } from 'vitepress'
import { UnlazyImages } from '@knewbeing/markdown-it-unlazy-img'

export default defineConfig({
  markdown: {
    config: (md) => {
      md.use(UnlazyImages()())
    },
  },
})

指定 thumbhash map 路径

md.use(UnlazyImages()(), {
  thumbhash: {
    mapFilePath: './.vitepress/cache/thumbhashes/map.json',
  },
})

使用自定义图片组件标签

md.use(UnlazyImages()(), {
  imgElementTag: 'MyLazyImage',
  thumbhash: {
    mapGlobPatterns: ['**/thumbhashes/map.json'],
  },
})

配置项 / Options

UnlazyImagesOptions

| 参数 | 类型 | 默认值 | 说明 | |------|------|--------|------| | imgElementTag | string | 'UnLazyImage' | 输出的自定义图片组件标签名 | | thumbhash | ThumbnailImageThumbhashOptions | glob 自动查找 | ThumbHash 数据来源配置 | | logFormatNotSupportedWarning | boolean | false | 是否对不支持的格式输出警告 |

ThumbnailImageThumbhashOptions(三选一)

// 方式一:通过 glob 自动查找 map 文件
{ mapGlobPatterns: ['**/thumbhashes/map.json'] }

// 方式二:直接指定 map 文件路径
{ mapFilePath: './.vitepress/cache/thumbhashes/map.json' }

// 方式三:直接传入 map 对象
{ map: { 'images/cover.jpg': { dataBase64: '...', dataUrl: '...', ... } } }

输出示例 / Output Example

<!-- 输入 Markdown -->
![封面图](./images/cover.jpg)

<!-- 生成 HTML -->
<UnLazyImage
  src="./images/cover.jpg"
  alt="封面图"
  thumbhash="3vcRJoJ4iIiHd3..."
  placeholderSrc="data:image/png;base64,..."
  autoSizes="true"
  width="1200"
  height="630"
/>

许可证 / License

MIT

相关链接 / Links