-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-medium-zoom): use client config
- Loading branch information
1 parent
256e90d
commit 9c42ba4
Showing
5 changed files
with
53 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './useMediumZoom.js' | ||
export * from './useMediumZoomOptions.js' |
21 changes: 21 additions & 0 deletions
21
ecosystem/plugin-medium-zoom/src/client/composables/useMediumZoomOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { defineClientData, useClientData } from '@vuepress/client' | ||
import type { InjectionKey } from 'vue' | ||
import type { MediumZoomOptions } from '../types.js' | ||
|
||
export const mediumZoomKey: InjectionKey<MediumZoomOptions> = Symbol( | ||
__VUEPRESS_DEV__ ? 'medium-zoom' : '' | ||
) | ||
|
||
export const defineDocsearchConfig = (options: MediumZoomOptions): void => | ||
defineClientData(mediumZoomKey, options) | ||
|
||
export const useMediumZoomOptions = (): Required<MediumZoomOptions> => { | ||
const options = useClientData(mediumZoomKey) | ||
|
||
return { | ||
selector: ':not(a) > img', | ||
delay: 500, | ||
zoomOptions: {}, | ||
...options, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { ZoomOptions } from 'medium-zoom' | ||
|
||
/** | ||
* Options for @vuepress/plugin-medium-zoom | ||
*/ | ||
export interface MediumZoomOptions { | ||
/** | ||
* Selector of zoomable images | ||
* | ||
* @default ':not(a) > img' | ||
*/ | ||
selector?: string | ||
|
||
/** | ||
* Delay in milliseconds | ||
* | ||
* @default 500 | ||
*/ | ||
delay?: number | ||
|
||
/** | ||
* Options for medium-zoom | ||
* | ||
* @see https://github.com/francoischalifour/medium-zoom#options | ||
*/ | ||
zoomOptions?: ZoomOptions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,10 @@ | ||
import type { Plugin } from '@vuepress/core' | ||
import { getDirname, path } from '@vuepress/utils' | ||
import type { ZoomOptions } from 'medium-zoom' | ||
|
||
const __dirname = getDirname(import.meta.url) | ||
|
||
/** | ||
* Options for @vuepress/plugin-medium-zoom | ||
*/ | ||
export interface MediumZoomPluginOptions { | ||
/** | ||
* Selector of zoomable images | ||
* | ||
* @default ':not(a) > img' | ||
*/ | ||
selector?: string | ||
|
||
/** | ||
* Delay in milliseconds | ||
* | ||
* @default 500 | ||
*/ | ||
delay?: number | ||
|
||
/** | ||
* Options for medium-zoom | ||
* | ||
* @see https://github.com/francoischalifour/medium-zoom#options | ||
*/ | ||
zoomOptions?: ZoomOptions | ||
} | ||
|
||
export const mediumZoomPlugin = ({ | ||
selector = ':not(a) > img', | ||
zoomOptions = {}, | ||
delay = 500, | ||
}: MediumZoomPluginOptions = {}): Plugin => ({ | ||
export const mediumZoomPlugin = (): Plugin => ({ | ||
name: '@vuepress/plugin-medium-zoom', | ||
|
||
clientConfigFile: path.resolve(__dirname, '../client/config.js'), | ||
|
||
define: { | ||
__MZ_SELECTOR__: selector, | ||
__MZ_ZOOM_OPTIONS__: zoomOptions, | ||
__MZ_DELAY__: delay, | ||
}, | ||
}) |