@rspress/plugin-medium-zoom 1.42.1-canary-20240226 → 1.42.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ function pluginMediumZoom(options = {}) {
23
23
  name: '@rspress/plugin-medium-zoom',
24
24
  globalUIComponents: [
25
25
  [
26
- __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.join(__dirname, '../src/components/MediumZoom.tsx'),
26
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(__dirname, '../static/MediumZoom.tsx'),
27
27
  options
28
28
  ]
29
29
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-medium-zoom",
3
- "version": "1.42.1-canary-20240226",
3
+ "version": "1.42.1",
4
4
  "description": "A plugin for rspress to zoom images in docs.",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -20,7 +20,8 @@
20
20
  "module": "./dist/node/index.js",
21
21
  "types": "./dist/index.d.ts",
22
22
  "files": [
23
- "dist"
23
+ "dist",
24
+ "static"
24
25
  ],
25
26
  "dependencies": {
26
27
  "medium-zoom": "1.1.0"
@@ -33,11 +34,11 @@
33
34
  "@types/react-dom": "^18.3.5",
34
35
  "react": "^18.3.1",
35
36
  "typescript": "^5.5.3",
36
- "@rspress/shared": "1.42.1-canary-20240226",
37
- "@rspress/config": "1.0.0"
37
+ "@rspress/config": "1.0.0",
38
+ "@rspress/shared": "1.42.1"
38
39
  },
39
40
  "peerDependencies": {
40
- "@rspress/runtime": "^1.42.0"
41
+ "@rspress/runtime": "^1.42.1"
41
42
  },
42
43
  "engines": {
43
44
  "node": ">=14.17.6"
@@ -0,0 +1,5 @@
1
+ /* https://github.com/francoischalifour/medium-zoom#debugging */
2
+ .medium-zoom-overlay,
3
+ .medium-zoom-image--opened {
4
+ z-index: 999;
5
+ }
@@ -0,0 +1,29 @@
1
+ import { useLocation } from '@rspress/runtime';
2
+ import mediumZoom, { type Zoom, type ZoomOptions } from 'medium-zoom';
3
+ import { useEffect } from 'react';
4
+ import './MediumZoom.css';
5
+
6
+ interface Props {
7
+ selector?: string;
8
+ options?: ZoomOptions;
9
+ }
10
+
11
+ export default function MediumZoom(props: Props) {
12
+ const { pathname } = useLocation();
13
+ const { selector = '.rspress-doc img', options = {} } = props;
14
+
15
+ useEffect(() => {
16
+ let zoom: Zoom | undefined;
17
+ const timeout = setTimeout(() => {
18
+ const images = document.querySelectorAll(selector);
19
+ zoom = mediumZoom(images, { ...options, background: 'var(--rp-c-bg)' });
20
+ }, 100);
21
+ return () => {
22
+ clearTimeout(timeout);
23
+ zoom?.detach();
24
+ zoom?.close();
25
+ };
26
+ }, [pathname]);
27
+
28
+ return null;
29
+ }