vue-pinch-zoom is a specialized Vue.js component designed to provide pinch-zoom and drag functionalities for images using touch gestures. It allows users to scale and pan image content within a defined container, offering features like configurable transition durations, zoom limits (absolute or based on original image size), minimum scale settings, and automatic zoom-out. It supports both double-tap and mouse wheel interactions, and includes options to disable panning, customize zoom controls, and handle container overflow. As of version 1.0.1, the library's `peerDependencies` indicate support for both Vue 2 (`^2.5.0`) and Vue 3 (`^3.0.0`), although its installation and usage examples in the README primarily demonstrate Vue 2 global registration syntax. The library ships with TypeScript types, enhancing developer experience in TypeScript projects. It differentiates itself by offering a comprehensive set of properties for fine-grained control over the zoom and pan behavior, catering to various use cases from simple image viewers to more interactive applications. The release cadence is not explicitly stated but appears to be stable at its current version.
npm install vue-pinch-zoomVerified import paths — ran on the pinned version, not inferred.
Demonstrates installation, global component registration (Vue 2 style), and basic usage of the pinch-zoom component with an image, showcasing common properties like `limitZoom`, `autoZoomOut`, and `doubleTap`.
For Vue 3, use `app.component('pinch-zoom', PinchZoom)` in your `main.ts` or `main.js` file for global registration. For local usage, simply import `PinchZoom` and add it to the `components` option of your SFC (or use directly in `<script setup>`).Ensure `limitZoom` is either a numeric value or precisely the string `"original image size"`. When using TypeScript, the `PinchZoomProps` interface will guide correct usage.
If `autoHeight` is `true`, always provide `width` and `height` attributes to the `<img>` tag within the `<pinch-zoom>` component: e.g., `<img src="..." width="800" height="600" />`.
To ensure both mouse and touch events are always handled, set the prop as `:listeners="'mouse and touch'"`.
Ensure the `<pinch-zoom>` wrapper or its direct parent has explicit `width` and `height` CSS properties, for example: `style="width: 100%; height: 400px;"` or using CSS classes.
For global registration (Vue 2): `Vue.component('pinch-zoom', PinchZoom);`. For global registration (Vue 3): `app.component('pinch-zoom', PinchZoom);`. For local registration (Vue 2/3): include `PinchZoom` in the `components` option of your parent component: `components: { PinchZoom }`.Ensure the value for `limitZoom` matches its expected types, e.g., `:limitZoom="2.5"` or `:limitZoom="'original image size'"`. Double-check the prop name for typos.
If using a build tool with Vue 2, ensure Vue is imported and instantiated (e.g., `new Vue({...})`). For Vue 3, this error is less common as global app registration uses an `app` instance (`app.component`). Ensure your setup correctly initializes Vue.Correct the value of the `limitZoom` prop to either a valid number (e.g., `:limitZoom="2.0"`) or the exact string `"original image size"` (e.g., `:limitZoom="'original image size'"`). Review the property documentation carefully.