You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
32 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, markRaw, ref, effectScope, shallowRef, computed, watch, nextTick, onMounted, openBlock, createBlock, unref, withCtx, createVNode, Transition, createElementVNode, normalizeClass, normalizeStyle, withModifiers, createCommentVNode, createElementBlock, Fragment, resolveDynamicComponent, renderList, withDirectives, vShow, renderSlot } from 'vue';\nimport { useEventListener } from '@vueuse/core';\nimport { throttle } from 'lodash-unified';\nimport ElFocusTrap from '../../focus-trap/src/focus-trap.mjs';\nimport { ElTeleport } from '../../teleport/index.mjs';\nimport { ElIcon } from '../../icon/index.mjs';\nimport { FullScreen, ScaleToOriginal, Close, ArrowLeft, ArrowRight, ZoomOut, ZoomIn, RefreshLeft, RefreshRight } from '@element-plus/icons-vue';\nimport { imageViewerProps, imageViewerEmits } from './image-viewer.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { useLocale } from '../../../hooks/use-locale/index.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { useZIndex } from '../../../hooks/use-z-index/index.mjs';\nimport { EVENT_CODE } from '../../../constants/aria.mjs';\nimport { keysOf } from '../../../utils/objects.mjs';\nconst __default__ = defineComponent({\n name: \"ElImageViewer\"\n});\nconst _sfc_main = /* @__PURE__ */defineComponent({\n ...__default__,\n props: imageViewerProps,\n emits: imageViewerEmits,\n setup(__props, {\n expose,\n emit\n }) {\n var _a;\n const props = __props;\n const modes = {\n CONTAIN: {\n name: \"contain\",\n icon: markRaw(FullScreen)\n },\n ORIGINAL: {\n name: \"original\",\n icon: markRaw(ScaleToOriginal)\n }\n };\n const {\n t\n } = useLocale();\n const ns = useNamespace(\"image-viewer\");\n const {\n nextZIndex\n } = useZIndex();\n const wrapper = ref();\n const imgRefs = ref([]);\n const scopeEventListener = effectScope();\n const loading = ref(true);\n const activeIndex = ref(props.initialIndex);\n const mode = shallowRef(modes.CONTAIN);\n const transform = ref({\n scale: 1,\n deg: 0,\n offsetX: 0,\n offsetY: 0,\n enableTransition: false\n });\n const zIndex = ref((_a = props.zIndex) != null ? _a : nextZIndex());\n const isSingle = computed(() => {\n const {\n urlList\n } = props;\n return urlList.length <= 1;\n });\n const isFirst = computed(() => {\n return activeIndex.value === 0;\n });\n const isLast = computed(() => {\n return activeIndex.value === props.urlList.length - 1;\n });\n const currentImg = computed(() => {\n return props.urlList[activeIndex.value];\n });\n const arrowPrevKls = computed(() => [ns.e(\"btn\"), ns.e(\"prev\"), ns.is(\"disabled\", !props.infinite && isFirst.value)]);\n const arrowNextKls = computed(() => [ns.e(\"btn\"), ns.e(\"next\"), ns.is(\"disabled\", !props.infinite && isLast.value)]);\n const imgStyle = computed(() => {\n const {\n scale,\n deg,\n offsetX,\n offsetY,\n enableTransition\n } = transform.value;\n let translateX = offsetX / scale;\n let translateY = offsetY / scale;\n const radian = deg * Math.PI / 180;\n const cosRadian = Math.cos(radian);\n const sinRadian = Math.sin(radian);\n translateX = translateX * cosRadian + translateY * sinRadian;\n translateY = translateY * cosRadian - offsetX / scale * sinRadian;\n const style = {\n transform: `scale(${scale}) rotate(${deg}deg) translate(${translateX}px, ${translateY}px)`,\n transition: enableTransition ? \"transform .3s\" : \"\"\n };\n if (mode.value.name === modes.CONTAIN.name) {\n style.maxWidth = style.maxHeight = \"100%\";\n }\n return style;\n });\n function hide() {\n unregisterEventListener();\n emit(\"close\");\n }\n function registerEventListener() {\n const keydownHandler = throttle(e => {\n