Skip to content

Commit

Permalink
feat: support image preview (#105)
Browse files Browse the repository at this point in the history
* feat: support image preview

* feat: replacing the viewerjs library

* fix: remove useless code
  • Loading branch information
callqh authored Oct 23, 2022
1 parent b39c221 commit f7330a8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"husky": "^8.0.1",
"lodash-es": "^4.17.21",
"mdast-util-mdxjs-esm": "^1.3.0",
"medium-zoom": "^1.0.6",
"ora": "^6.1.2",
"picocolors": "^1.0.0",
"polka": "^0.5.2",
Expand Down
5 changes: 5 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/theme-default/logic/sideEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { throttle } from 'lodash-es';
import { APPEARANCE_KEY } from '../../shared/constants';
import { inBrowser } from '../../shared/utils';
import { setupCopyCodeButton } from './copyCode';
import mediumZoom from 'medium-zoom';

const DEFAULT_NAV_HEIGHT = 60;

Expand Down Expand Up @@ -221,6 +222,14 @@ function bindingMenuGroupToggle() {
});
}

function bindingImagePreview() {
const imageList = document.querySelectorAll<HTMLImageElement>('img');
mediumZoom(imageList, {
margin: 100,
background: 'rgba(0, 0, 0, 0.7)'
});
}

export function setup() {
if (!inBrowser()) {
return;
Expand All @@ -233,4 +242,5 @@ export function setup() {
bindingWindowScroll();
bindingMenuGroupToggle();
setupCopyCodeButton();
bindingImagePreview();
}
6 changes: 6 additions & 0 deletions src/theme-default/styles/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,9 @@ fieldset {
.visually-hidden {
visibility: hidden;
}

/* https://github.com/francoischalifour/medium-zoom#debugging */
.medium-zoom-overlay,
.medium-zoom-image--opened {
z-index: 999;
}

1 comment on commit f7330a8

@vercel
Copy link

@vercel vercel bot commented on f7330a8 Oct 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.