vitepress-component-medium-zoom 1.0.0 → 1.1.0
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/README.md +36 -6
- package/README.zh-CN.md +37 -7
- package/dist/index.css +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/package.json +1 -5
package/README.md
CHANGED
|
@@ -45,19 +45,30 @@ Create or update `.vitepress/theme/MyLayout.vue`:
|
|
|
45
45
|
<script setup>
|
|
46
46
|
import DefaultTheme from 'vitepress/theme';
|
|
47
47
|
import { MediumZoom } from 'vitepress-component-medium-zoom';
|
|
48
|
+
import 'vitepress-component-medium-zoom/style.css';
|
|
48
49
|
|
|
49
50
|
const { Layout } = DefaultTheme;
|
|
50
51
|
</script>
|
|
51
52
|
|
|
52
53
|
<template>
|
|
53
54
|
<Layout>...</Layout>
|
|
54
|
-
<!--
|
|
55
|
+
<!-- Use here -->
|
|
55
56
|
<MediumZoom />
|
|
56
57
|
</template>
|
|
57
58
|
```
|
|
58
59
|
|
|
59
60
|
**Note:** The component doesn't render any visible content, so you can place it anywhere in your layout. It will automatically handle image zooming for all images matching the selector.
|
|
60
61
|
|
|
62
|
+
⚠️ **Important:** You need to add the following configuration to `.vitepress/config.ts`, otherwise the build will fail:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
vite: {
|
|
66
|
+
ssr: {
|
|
67
|
+
noExternal: ['vitepress-component-medium-zoom'];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
61
72
|
## Props
|
|
62
73
|
|
|
63
74
|
### selector
|
|
@@ -73,6 +84,24 @@ Customize the image selector. This follows the [medium-zoom](https://github.com/
|
|
|
73
84
|
<MediumZoom selector=".vp-doc img" />
|
|
74
85
|
```
|
|
75
86
|
|
|
87
|
+
If you want to exclude certain images from zooming, you can use a custom data attribute and exclude them from the selector.
|
|
88
|
+
|
|
89
|
+
```vue
|
|
90
|
+
<MediumZoom selector=".vp-doc img:not([data-disable-zoom])" />
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Example:**
|
|
94
|
+
|
|
95
|
+
```md
|
|
96
|
+
{data-disable-zoom}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
or
|
|
100
|
+
|
|
101
|
+
```vue
|
|
102
|
+
<img src="image.png" data-disable-zoom />
|
|
103
|
+
```
|
|
104
|
+
|
|
76
105
|
### options
|
|
77
106
|
|
|
78
107
|
- **Type**: `ZoomOptions`
|
|
@@ -92,16 +121,17 @@ Configuration options for medium-zoom. See the [medium-zoom documentation](https
|
|
|
92
121
|
/>
|
|
93
122
|
```
|
|
94
123
|
|
|
95
|
-
|
|
124
|
+
### zIndex
|
|
96
125
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
126
|
+
- **Type**: `number`
|
|
127
|
+
- **Default**: `999`
|
|
128
|
+
|
|
129
|
+
Customize the z-index value for the overlay and zoomed image.
|
|
100
130
|
|
|
101
131
|
**Example:**
|
|
102
132
|
|
|
103
133
|
```vue
|
|
104
|
-
<
|
|
134
|
+
<MediumZoom :z-index="2000" />
|
|
105
135
|
```
|
|
106
136
|
|
|
107
137
|
## How It Works
|
package/README.zh-CN.md
CHANGED
|
@@ -21,7 +21,7 @@ pnpm add vitepress-component-medium-zoom
|
|
|
21
21
|
yarn add vitepress-component-medium-zoom
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## 使用
|
|
25
25
|
|
|
26
26
|
参考 [VitePress Layout Slots](https://vitepress.dev/guide/extending-default-theme#layout-slots),在布局中直接引入组件。
|
|
27
27
|
|
|
@@ -45,19 +45,30 @@ export default {
|
|
|
45
45
|
<script setup>
|
|
46
46
|
import DefaultTheme from 'vitepress/theme';
|
|
47
47
|
import { MediumZoom } from 'vitepress-component-medium-zoom';
|
|
48
|
+
import 'vitepress-component-medium-zoom/style.css';
|
|
48
49
|
|
|
49
50
|
const { Layout } = DefaultTheme;
|
|
50
51
|
</script>
|
|
51
52
|
|
|
52
53
|
<template>
|
|
53
54
|
<Layout>...</Layout>
|
|
54
|
-
<!--
|
|
55
|
+
<!-- 在这里使用 -->
|
|
55
56
|
<MediumZoom />
|
|
56
57
|
</template>
|
|
57
58
|
```
|
|
58
59
|
|
|
59
60
|
**注意:** 该组件不会渲染任何可见内容,因此可以将其放置在布局的任何位置。它会自动处理所有匹配选择器的图片缩放功能。
|
|
60
61
|
|
|
62
|
+
⚠️ **重要:** 需要把下面这个配置添加到 `.vitepress/config.ts` 中,否则构建会报错:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
vite: {
|
|
66
|
+
ssr: {
|
|
67
|
+
noExternal: ['vitepress-component-medium-zoom'];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
61
72
|
## Props
|
|
62
73
|
|
|
63
74
|
### selector
|
|
@@ -73,6 +84,24 @@ const { Layout } = DefaultTheme;
|
|
|
73
84
|
<MediumZoom selector=".vp-doc img" />
|
|
74
85
|
```
|
|
75
86
|
|
|
87
|
+
如果某些图像不要 zoom,可以自定义一个 data 值,然后从 selector 中排除掉。
|
|
88
|
+
|
|
89
|
+
```vue
|
|
90
|
+
<MediumZoom selector=".vp-doc img:not([data-disable-zoom])" />
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**示例:**
|
|
94
|
+
|
|
95
|
+
```md
|
|
96
|
+
{data-disable-zoom}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
或
|
|
100
|
+
|
|
101
|
+
```vue
|
|
102
|
+
<img src="image.png" data-disable-zoom />
|
|
103
|
+
```
|
|
104
|
+
|
|
76
105
|
### options
|
|
77
106
|
|
|
78
107
|
- **类型**: `ZoomOptions`
|
|
@@ -92,16 +121,17 @@ medium-zoom 的配置选项。查看 [medium-zoom 文档](https://github.com/fra
|
|
|
92
121
|
/>
|
|
93
122
|
```
|
|
94
123
|
|
|
95
|
-
|
|
124
|
+
### zIndex
|
|
96
125
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
126
|
+
- **类型**: `number`
|
|
127
|
+
- **默认值**: `999`
|
|
128
|
+
|
|
129
|
+
自定义遮罩层和放大图片的 z-index 值。
|
|
100
130
|
|
|
101
131
|
**示例:**
|
|
102
132
|
|
|
103
133
|
```vue
|
|
104
|
-
<
|
|
134
|
+
<MediumZoom :z-index="2000" />
|
|
105
135
|
```
|
|
106
136
|
|
|
107
137
|
## 工作原理
|
package/dist/index.css
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,12 @@ import { ZoomOptions, ZoomSelector } from "medium-zoom";
|
|
|
5
5
|
type __VLS_Props = {
|
|
6
6
|
selector?: ZoomSelector;
|
|
7
7
|
options?: ZoomOptions;
|
|
8
|
+
zIndex?: number;
|
|
8
9
|
};
|
|
9
10
|
declare const __VLS_export: vue0.DefineComponent<__VLS_Props, {}, {}, {}, {}, vue0.ComponentOptionsMixin, vue0.ComponentOptionsMixin, {}, string, vue0.PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
10
11
|
selector: ZoomSelector;
|
|
11
12
|
options: ZoomOptions;
|
|
13
|
+
zIndex: number;
|
|
12
14
|
}, {}, {}, {}, string, vue0.ComponentProvideOptions, false, {}, any>;
|
|
13
15
|
declare const _default: typeof __VLS_export;
|
|
14
16
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineComponent as e,nextTick as t,onBeforeUnmount as n,onMounted as r}from"vue";import{useRouter as
|
|
1
|
+
import{defineComponent as e,nextTick as t,onBeforeUnmount as n,onMounted as r,useCssVars as i}from"vue";import{useRouter as a}from"vitepress";import o from"medium-zoom";var s=e({__name:`MediumZoom`,props:{selector:{type:null,required:!1,default:`.vp-doc img`},options:{type:Object,required:!1,default:()=>({})},zIndex:{type:Number,required:!1,default:999}},setup(e){i(e=>({"7055c699-zIndex":e.zIndex}));let s=e,c,l,u=a();u.onAfterRouteChange=d,r(d),n(()=>{clearTimeout(l),c&&(c.detach(),c.close())});function d(){t(()=>{c&&=(c.detach(),c.close(),void 0),clearTimeout(l),l=setTimeout(()=>{c=o(s.selector,{background:`var(--vp-c-bg)`,...s.options})},100)})}return()=>{}}});export{s as MediumZoom};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitepress-component-medium-zoom",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "VitePress image preview component with medium-zoom support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vitepress",
|
|
@@ -58,10 +58,6 @@
|
|
|
58
58
|
"vue": "^3.5.26",
|
|
59
59
|
"vue-tsc": "^3.2.1"
|
|
60
60
|
},
|
|
61
|
-
"peerDependencies": {
|
|
62
|
-
"vitepress": "^1.0.0",
|
|
63
|
-
"vue": "^3.0.0"
|
|
64
|
-
},
|
|
65
61
|
"publishConfig": {
|
|
66
62
|
"access": "public"
|
|
67
63
|
},
|