vuepress-plugin-lightgallery
Version:
Light Gallery plugin for VuePress
60 lines (57 loc) • 1.89 kB
JavaScript
import { n as useLightGalleryOptions } from "../lightgallery-B5ld7Osg.js";
import { defineClientConfig, onContentUpdated } from "vuepress/client";
import LightGallery from "lightgallery/lightgallery.es5.js";
import { defineComponent, h, onUnmounted, shallowRef } from "vue";
import { useLightGalleryPlugins } from "@temp/lightgallery/plugins.js";
import "lightgallery/scss/lightgallery.scss";
//#region src/client/components/LightGallery.ts
const getImages = (images) => images.map(({ alt, srcset, src }) => ({
src,
srcset,
thumb: src || srcset,
alt,
subHtml: alt
}));
var LightGallery_default = defineComponent({
name: "LightGallery",
setup() {
const lightGalleryOptions = useLightGalleryOptions();
const container = shallowRef();
let instance = null;
let id;
const initLightGallery = async () => {
const timeID = id = Date.now();
const lightGalleryPlugins = await useLightGalleryPlugins();
if (timeID === id) {
instance?.destroy();
const images = [...document.querySelectorAll(__LG_SELECTOR__)];
instance = new LightGallery(container.value, {
...lightGalleryOptions,
dynamic: true,
dynamicEl: getImages(images),
licenseKey: "VSY7R-J@WED-CJY76-UMDXQ",
plugins: lightGalleryPlugins.map(({ default: plugin }) => plugin)
});
images.forEach((image, index) => {
image.addEventListener("click", () => {
instance?.openGallery(index);
});
});
}
};
onContentUpdated(async (reason) => {
if (reason !== "beforeUnmount") await initLightGallery();
});
onUnmounted(() => instance?.destroy());
return () => h("div", {
ref: container,
class: "lightgallery-vuepress"
});
}
});
//#endregion
//#region src/client/config.ts
var config_default = defineClientConfig({ rootComponents: [LightGallery_default] });
//#endregion
export { config_default as default };
//# sourceMappingURL=config.js.map