function-call.mjs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
  2. import { extend, inBrowser } from "../utils/index.mjs";
  3. import { mountComponent, usePopupState } from "../utils/mount-component.mjs";
  4. import VanImagePreview from "./ImagePreview.mjs";
  5. let instance;
  6. const defaultConfig = {
  7. loop: true,
  8. images: [],
  9. maxZoom: 3,
  10. minZoom: 1 / 3,
  11. onScale: void 0,
  12. onClose: void 0,
  13. onChange: void 0,
  14. vertical: false,
  15. teleport: "body",
  16. className: "",
  17. showIndex: true,
  18. closeable: false,
  19. closeIcon: "clear",
  20. transition: void 0,
  21. beforeClose: void 0,
  22. doubleScale: true,
  23. overlayStyle: void 0,
  24. overlayClass: void 0,
  25. startPosition: 0,
  26. swipeDuration: 300,
  27. showIndicators: false,
  28. closeOnPopstate: true,
  29. closeOnClickOverlay: true,
  30. closeIconPosition: "top-right"
  31. };
  32. function initInstance() {
  33. ({
  34. instance
  35. } = mountComponent({
  36. setup() {
  37. const {
  38. state,
  39. toggle
  40. } = usePopupState();
  41. const onClosed = () => {
  42. state.images = [];
  43. };
  44. return () => _createVNode(VanImagePreview, _mergeProps(state, {
  45. "onClosed": onClosed,
  46. "onUpdate:show": toggle
  47. }), null);
  48. }
  49. }));
  50. }
  51. const showImagePreview = (options, startPosition = 0) => {
  52. if (!inBrowser) {
  53. return;
  54. }
  55. if (!instance) {
  56. initInstance();
  57. }
  58. options = Array.isArray(options) ? {
  59. images: options,
  60. startPosition
  61. } : options;
  62. instance.open(extend({}, defaultConfig, options));
  63. return instance;
  64. };
  65. export {
  66. showImagePreview
  67. };