This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(photo-swipe): rebuild photoswipe
- Loading branch information
1 parent
756eb26
commit 18bf3c3
Showing
10 changed files
with
207 additions
and
71 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
File renamed without changes.
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,34 @@ | ||
import type { Item } from "photoswipe"; | ||
|
||
export const getImageInfo = ( | ||
image: HTMLImageElement | ||
): Item & { title: string } => ({ | ||
src: image.src, | ||
w: image.naturalWidth, | ||
h: image.naturalHeight, | ||
title: image.alt, | ||
}); | ||
|
||
export interface PhotoSwipeImages { | ||
elements: HTMLImageElement[]; | ||
infos: Item[]; | ||
} | ||
|
||
export const getImages = (selector: string): Promise<PhotoSwipeImages> => { | ||
const images = Array.from( | ||
document.querySelectorAll<HTMLImageElement>(selector) | ||
); | ||
|
||
return Promise.all( | ||
images.map( | ||
(image) => | ||
new Promise<Item>((resolve, reject) => { | ||
if (image.complete) resolve(getImageInfo(image)); | ||
else { | ||
image.onload = (): void => resolve(getImageInfo(image)); | ||
image.onerror = (err): void => reject(err); | ||
} | ||
}) | ||
) | ||
).then((infos) => ({ elements: images, infos })); | ||
}; |
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,30 +1,3 @@ | ||
import { getLocales } from "@mr-hope/vuepress-shared"; | ||
import { resolve } from "path"; | ||
import { photoSwipeLocales } from "./locales"; | ||
|
||
import type { Plugin } from "@mr-hope/vuepress-types"; | ||
import type { PhotoSwipeOptions } from "../types"; | ||
|
||
const photoSwipePlugin: Plugin<PhotoSwipeOptions> = (options, context) => { | ||
return { | ||
name: "photo-swipe", | ||
|
||
define: (): Record<string, unknown> => ({ | ||
PHOTO_SWIPE_SELECTOR: | ||
options.selector || ".theme-default-content :not(a) > img", | ||
PHOTO_SWIPE_DELAY: options.delay || 500, | ||
PHOTO_SWIPE_OPTIONS: options.options || {}, | ||
PHOTO_SWIPE_LOCALES: getLocales( | ||
context, | ||
photoSwipeLocales, | ||
options.locales | ||
), | ||
}), | ||
|
||
enhanceAppFiles: resolve(__dirname, "../client/enhanceAppFile.js"), | ||
|
||
globalUIComponents: "PhotoSwipe", | ||
}; | ||
}; | ||
import { photoSwipePlugin } from "./plugin"; | ||
|
||
export = photoSwipePlugin; |
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,31 @@ | ||
import { getLocales } from "@mr-hope/vuepress-shared"; | ||
import { resolve } from "path"; | ||
import { photoSwipeLocales } from "./locales"; | ||
|
||
import type { Plugin } from "@mr-hope/vuepress-types"; | ||
import type { PhotoSwipeOptions } from "../types"; | ||
|
||
export const photoSwipePlugin: Plugin<PhotoSwipeOptions> = ( | ||
options, | ||
context | ||
) => { | ||
return { | ||
name: "vuepress-plugin-photo-swipe", | ||
|
||
define: (): Record<string, unknown> => ({ | ||
PHOTO_SWIPE_SELECTOR: | ||
options.selector || ".theme-default-content :not(a) > img", | ||
PHOTO_SWIPE_DELAY: options.delay || 500, | ||
PHOTO_SWIPE_OPTIONS: options.options || {}, | ||
PHOTO_SWIPE_LOCALES: getLocales( | ||
context, | ||
photoSwipeLocales, | ||
options.locales | ||
), | ||
}), | ||
|
||
enhanceAppFiles: resolve(__dirname, "../client/enhanceAppFile.js"), | ||
|
||
globalUIComponents: "PhotoSwipe", | ||
}; | ||
}; |
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
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