A VuePress plugin that integrates medium-zoom library to provide image zoom functionality for documentation sites.
npx @tessl/cli install tessl/npm-vuepress--plugin-medium-zoom@1.9.0A VuePress plugin that integrates the medium-zoom library to provide elegant image zoom functionality for documentation sites. The plugin enables users to click on images to expand them with a smooth zoom animation overlay, enhancing the visual experience of documentation without additional UI complexity.
npm install @vuepress/plugin-medium-zoomVuePress plugins are typically imported and configured in the VuePress configuration file:
// .vuepress/config.js
module.exports = {
plugins: [
['@vuepress/plugin-medium-zoom', options]
]
}For programmatic usage:
const mediumZoomPlugin = require('@vuepress/plugin-medium-zoom');Enable the plugin with default settings that target content images not wrapped in links:
// .vuepress/config.js
module.exports = {
plugins: [
'@vuepress/plugin-medium-zoom'
]
}Configure the plugin to target specific images using CSS selectors:
// .vuepress/config.js
module.exports = {
plugins: [
['@vuepress/plugin-medium-zoom', {
selector: '.my-custom-images img',
options: {
margin: 16,
background: 'rgba(25, 18, 25, 0.9)',
scrollOffset: 40
}
}]
]
}Creates a VuePress plugin configuration object with medium-zoom integration.
/**
* VuePress plugin factory function for medium-zoom integration (default export)
* @param {PluginOptions} options - Plugin configuration options
* @param {VuePressContext} context - VuePress application context
* @returns {VuePressPlugin} Plugin configuration object
*/
module.exports = (options, context) => VuePressPlugin;
interface PluginOptions {
/** CSS selector for images to apply zoom functionality */
selector?: string;
/** Configuration options passed to medium-zoom library */
options?: MediumZoomOptions;
}
interface VuePressPlugin {
/** Global constants injected into client-side code */
define: {
SELECTOR: string;
OPTIONS: MediumZoomOptions | undefined;
};
/** Path to client-side Vue.js mixin */
clientRootMixin: string;
}Configure image targeting and zoom behavior through the options parameter.
interface PluginOptions {
/**
* CSS selector for images to apply zoom functionality
* @default '.theme-default-content :not(a) > img'
*/
selector?: string;
/**
* Configuration options passed directly to medium-zoom library
* Supports all medium-zoom configuration options
*/
options?: MediumZoomOptions;
}
interface MediumZoomOptions {
/** Spacing around the zoomed image in pixels */
margin?: number;
/** Background color/style for the zoom overlay */
background?: string;
/** Vertical offset from viewport top when scrolling */
scrollOffset?: number;
/** Additional medium-zoom configuration options */
[key: string]: any;
}The plugin automatically injects a Vue.js mixin that handles zoom initialization and lifecycle management.
interface ClientRootMixin {
/** Vue component data containing zoom instance */
data(): {
zoom: MediumZoomInstance | null;
};
/** Initialize zoom functionality when component mounts */
mounted(): void;
/** Reinitialize zoom when component updates (SPA navigation) */
updated(): void;
/** Update/reinitialize zoom functionality with current DOM state */
methods: {
updateZoom(): void;
};
}
interface MediumZoomInstance {
/** Remove zoom functionality from all images */
detach(): void;
/** Additional medium-zoom instance methods */
[key: string]: any;
}The plugin includes CSS styling for proper z-index management of zoom overlays.
/* Zoom overlay container styling */
.medium-zoom-overlay {
z-index: 100;
}
/* Zoomed image styling - ensures image appears above overlay */
.medium-zoom-overlay ~ img {
z-index: 101;
}module.exports = {
plugins: [
['@vuepress/plugin-medium-zoom', {
selector: 'img'
}]
]
}module.exports = {
plugins: [
['@vuepress/plugin-medium-zoom', {
selector: '.content-wrapper img:not([data-no-zoom])'
}]
]
}module.exports = {
plugins: [
['@vuepress/plugin-medium-zoom', {
selector: '.theme-default-content :not(a) > img',
options: {
margin: 24,
background: 'rgba(0, 0, 0, 0.8)',
scrollOffset: 0,
container: {
top: 24,
right: 24,
bottom: 24,
left: 24
},
template: {
closeButton: true
}
}
}]
]
}SELECTOR and OPTIONS globally via define mechanismmedium-zoom@^1.0.4 as core zoom functionalityoptions parameter.theme-default-content :not(a) > img - targets content images not wrapped in links