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

vitepress-component-medium-zoom

v1.1.1

Published

VitePress image preview component with medium-zoom support

Readme

vitepress-component-medium-zoom

English | 中文

VitePress 图片预览功能组件

特性

  • 🖼️ 点击图片放大/缩小
  • 🔄 路由变化时自动重新初始化
  • ⚙️ 可自定义选择器和配置选项
  • 🎨 内置 z-index 样式,确保遮罩层正确显示,可通过 --vp-medium-zoom-z-index css 变量自定义

安装

npm install vitepress-component-medium-zoom
# 或
pnpm add vitepress-component-medium-zoom
# 或
yarn add vitepress-component-medium-zoom

使用

参考 VitePress Layout Slots,在布局中直接引入组件。

创建或更新 .vitepress/theme/index.js

import DefaultTheme from 'vitepress/theme';
import MyLayout from './MyLayout.vue';

export default {
  extends: DefaultTheme,
  // override the Layout with a wrapper component that
  // injects the slots
  Layout: MyLayout
};

创建或更新 .vitepress/theme/MyLayout.vue

<script setup>
import DefaultTheme from 'vitepress/theme';
import { MediumZoom } from 'vitepress-component-medium-zoom';
import 'vitepress-component-medium-zoom/style.css';

const { Layout } = DefaultTheme;
</script>

<template>
  <Layout>...</Layout>
  <!-- 在这里使用 -->
  <MediumZoom />
</template>

注意: 该组件不会渲染任何可见内容,因此可以将其放置在布局的任何位置。它会自动处理所有匹配选择器的图片缩放功能。

⚠️ 重要: 需要把下面这个配置添加到 .vitepress/config.ts 中,否则构建会报错:

vite: {
  ssr: {
    noExternal: ['vitepress-component-medium-zoom'];
  }
}

Props

selector

  • 类型: string | HTMLElement | HTMLElement[] | NodeList
  • 默认值: '.vp-doc img'

自定义图片选择器。遵循 medium-zoom 的选择器格式。

示例:

<MediumZoom selector=".vp-doc img" />

如果某些图像不要 zoom,可以自定义一个 data 值,然后从 selector 中排除掉。

<MediumZoom selector=".vp-doc img:not([data-disable-zoom])" />

示例:

![foo](./assets/foo.png){data-disable-zoom}

<img src="image.png" data-disable-zoom />

options

  • 类型: ZoomOptions
  • 默认值: {}

medium-zoom 的配置选项。查看 medium-zoom 文档 了解可用的配置选项。

示例:

<MediumZoom
  selector=".vp-doc img"
  :options="{
    background: 'rgba(0, 0, 0, 0.8)',
    margin: 24
  }"
/>

工作原理

该组件使用 medium-zoom 库来提供图片缩放功能。它:

  1. 组件挂载时自动初始化
  2. 路由变化时重新初始化(使用 VitePress 路由钩子)
  3. 组件卸载时清理资源
  4. 应用适当的 z-index 样式,确保遮罩层显示在内容之上

参考

组件参考了 Rspress 文档框架中的 @rspress/plugin-medium-zoom 的设计。

License

MIT

Copyright (c) 2026-present, REFINITIST