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
20 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, useAttrs, computed, ref, watch, onMounted, openBlock, createElementBlock, mergeProps, unref, renderSlot, createElementVNode, normalizeClass, toDisplayString, Fragment, createCommentVNode, createBlock, withCtx, nextTick } from 'vue';\nimport { isClient, useThrottleFn, useEventListener } from '@vueuse/core';\nimport { fromPairs } from 'lodash-unified';\nimport { ElImageViewer } from '../../image-viewer/index.mjs';\nimport { imageProps, imageEmits } from './image.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { isInContainer } from '../../../utils/dom/position.mjs';\nimport { useLocale } from '../../../hooks/use-locale/index.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { useAttrs as useAttrs$1 } from '../../../hooks/use-attrs/index.mjs';\nimport { isArray, isString } from '@vue/shared';\nimport { isElement } from '../../../utils/types.mjs';\nimport { getScrollContainer } from '../../../utils/dom/scroll.mjs';\nconst __default__ = defineComponent({\n name: \"ElImage\",\n inheritAttrs: false\n});\nconst _sfc_main = /* @__PURE__ */defineComponent({\n ...__default__,\n props: imageProps,\n emits: imageEmits,\n setup(__props, {\n emit\n }) {\n const props = __props;\n let prevOverflow = \"\";\n const {\n t\n } = useLocale();\n const ns = useNamespace(\"image\");\n const rawAttrs = useAttrs();\n const containerAttrs = computed(() => {\n return fromPairs(Object.entries(rawAttrs).filter(([key]) => /^(data-|on[A-Z])/i.test(key) || [\"id\", \"style\"].includes(key)));\n });\n const imgAttrs = useAttrs$1({\n excludeListeners: true,\n excludeKeys: computed(() => {\n return Object.keys(containerAttrs.value);\n })\n });\n const imageSrc = ref();\n const hasLoadError = ref(false);\n const isLoading = ref(true);\n const showViewer = ref(false);\n const container = ref();\n const _scrollContainer = ref();\n const supportLoading = isClient && \"loading\" in HTMLImageElement.prototype;\n let stopScrollListener;\n let stopWheelListener;\n const imageKls = computed(() => [ns.e(\"inner\"), preview.value && ns.e(\"preview\"), isLoading.value && ns.is(\"loading\")]);\n const imageStyle = computed(() => {\n const {\n fit\n } = props;\n if (isClient && fit) {\n return {\n objectFit: fit\n };\n }\n return {};\n });\n const preview = computed(() => {\n const {\n previewSrcList\n } = props;\n return isArray(previewSrcList) && previewSrcList.length > 0;\n });\n const imageIndex = computed(() => {\n const {\n previewSrcList,\n initialIndex\n } = props;\n let previewIndex = initialIndex;\n if (initialIndex > previewSrcList.length - 1) {\n previewIndex = 0;\n }\n return previewIndex;\n });\n const isManual = computed(() => {\n if (props.loading === \"eager\") return false;\n return !supportLoading && props.loading === \"lazy\" || props.lazy;\n });\n const loadImage = () => {\n if (!isClient) return;\n isLoading.value = true;\n hasLoadError.value = false;\n imageSrc.value = props.src;\n };\n function handleLoad(event) {\n isLoading.value = false;\n hasLoadError.value = false;\n emit(\"load\", event);\n }\n function handleError(event) {\n isLoading.value = false;\n hasLoadError.value = true;\n emit(\"error\", event);\n }\n function handleLazyLoad() {\n if (isInContainer(container.value, _scrollContainer.value)) {\n loadImage();\n removeLazyLoadListener();\n }\n }\n const lazyLoadHandler = useThrottleFn(handleLazyLoad, 200, true);\n async function addLazyLoadListener() {\n var _a;\n if (!isClient) return;\n await nextTick();\n const {\n scrollContainer\n } = props;\n if (isElement(scrollContainer)) {\n _scrollContainer.value = s