yanzhen-design-vue
Version:
52 lines (51 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const vViewer = require("v-viewer");
const lodashEs = require("lodash-es");
const utilsVue = require("@yanzhen-libs/utils-vue");
const utils = require("@yanzhen-libs/utils");
require("viewerjs/dist/viewer.css");
function useViewerApi({ options, images } = {}) {
const viewer = vue.ref();
const optionsRef = vue.computed(() => {
return lodashEs.mergeWith(
{
toolbar: true,
initialViewIndex: 1
},
vue.unref(options) ?? {}
);
});
const imagesRef = vue.computed(() => {
return !utils.isEmptyArray(vue.unref(images)) ? vue.unref(images) : [];
});
function handlePreview(images2, options2) {
var _a;
(_a = vue.unref(viewer)) == null ? void 0 : _a.destroy();
viewer.value = vViewer.api({
images: images2 ?? vue.unref(imagesRef),
options: lodashEs.mergeWith({}, vue.unref(optionsRef), options2 ?? {})
});
return vue.unref(viewer);
}
const watcher = utilsVue.createWatcher();
watcher.set("images", {
source: () => [vue.unref(optionsRef), vue.unref(imagesRef)],
handler: () => {
var _a;
(_a = vue.unref(viewer)) == null ? void 0 : _a.update();
},
deep: true
});
vue.onUnmounted(() => {
var _a;
watcher.stop();
(_a = vue.unref(viewer)) == null ? void 0 : _a.destroy();
});
return {
viewer,
preview: handlePreview
};
}
exports.useViewerApi = useViewerApi;