{"version":3,"file":"image.mjs","names":["viewer-error"],"sources":["../../../../src/components/image/src/image.tsx"],"sourcesContent":["import { computed, defineComponent, reactive, shallowRef, watch } from \"vue\";\nimport { Picture as ElIconPicture } from \"@element-plus/icons-vue\";\nimport { ElIcon, ElImage, imageEmits, imageProps } from \"element-plus\";\nimport { makeSlots, useEmits, useExpose, useProps, useRender } from \"../../../utils\";\nimport type { ImageInstance, ImageViewerAction } from \"element-plus\";\n\n/** FaImage 的运行时 Props 定义 */\nexport const faImageProps = {\n\t// eslint-disable-next-line @typescript-eslint/no-deprecated -- Element Plus 2.x 尚未提供可替代的公开运行时 props 定义。\n\t...imageProps,\n\t/** when enabling preview, use this flag to control whether clicking on backdrop can exit preview mode. */\n\thideOnClickModal: {\n\t\ttype: Boolean,\n\t\tdefault: true,\n\t},\n\t/** whether to append image-viewer to body. A nested parent element attribute transform should have this attribute set to `true`. */\n\tpreviewTeleported: {\n\t\ttype: Boolean,\n\t\tdefault: true,\n\t},\n\t/** whether to use lazy load. */\n\tlazy: {\n\t\ttype: Boolean,\n\t\tdefault: true,\n\t},\n\t/** Base64图片 */\n\tbase64: Boolean,\n\t/** 原图 */\n\toriginal: Boolean,\n\t/** 标准 */\n\tnormal: Boolean,\n\t/** 小图 */\n\tsmall: Boolean,\n\t/** 缩略图 */\n\tthumb: Boolean,\n\t/** 是否可以预览图片 */\n\tpreview: {\n\t\ttype: Boolean,\n\t\tdefault: true,\n\t},\n};\n\n/** FaImage 的运行时事件定义。 */\nexport const faImageEmits = {\n\t...imageEmits,\n};\n\n/** FaImage 的插槽参数 */\nexport interface FaImageSlots extends Record<string, unknown> {\n\t/** 当图像尚未加载时，自定义的占位符内容 */\n\tplaceholder: never;\n\t/** 自定义图像加载失败的内容 */\n\terror: never;\n\t/** 当图像预览时自定义内容 */\n\tviewer: { src?: string };\n\t/** 图片预览进度内容 */\n\tprogress: { activeIndex: number; total: number };\n\t/** 图片预览工具栏内容 */\n\ttoolbar: {\n\t\tactions: (action: ImageViewerAction, options?: Record<string, never>) => void;\n\t\tprev: () => void;\n\t\tnext: () => void;\n\t\treset: () => void;\n\t\tactiveIndex: number;\n\t\tsetActiveItem: (index: number) => void;\n\t};\n\t/** 图片预览加载失败内容 */\n\t\"viewer-error\": { activeIndex: number; src: string };\n}\n\nexport default defineComponent({\n\tname: \"FaImage\",\n\tprops: faImageProps,\n\temits: faImageEmits,\n\tslots: makeSlots<FaImageSlots>(),\n\tsetup(props, { slots, emit, expose }) {\n\t\tconst imageRef = shallowRef<ImageInstance | null>(null);\n\n\t\tconst state = reactive({\n\t\t\t/** 图片加载错误 */\n\t\t\tloadError: false,\n\t\t\tsrc: computed(() => {\n\t\t\t\tif (!props.src) return undefined;\n\t\t\t\tif (props.base64) {\n\t\t\t\t\treturn `data:image/png;base64,${props.src}`;\n\t\t\t\t} else if (props.original || state.loadError) {\n\t\t\t\t\treturn props.src;\n\t\t\t\t} else if (props.normal) {\n\t\t\t\t\treturn `${props.src}@!normal`;\n\t\t\t\t} else if (props.small) {\n\t\t\t\t\treturn `${props.src}@!small`;\n\t\t\t\t} else if (props.thumb) {\n\t\t\t\t\treturn `${props.src}@!thumb`;\n\t\t\t\t} else {\n\t\t\t\t\t// 默认使用缩略图\n\t\t\t\t\treturn `${props.src}@!thumb`;\n\t\t\t\t}\n\t\t\t}),\n\t\t\tpreviewList: computed(() => (props.preview && props.src ? [props.base64 ? `data:image/png;base64,${props.src}` : props.src] : [])),\n\t\t});\n\n\t\twatch(\n\t\t\t() => props.src,\n\t\t\t() => {\n\t\t\t\tstate.loadError = false;\n\t\t\t}\n\t\t);\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated -- 透传范围必须与继承的 Element Plus 2.x 运行时 props 保持一致。\n\t\tconst bindProps = useProps(props, imageProps, [\"src\", \"previewSrcList\"]);\n\t\tconst bindEmits = useEmits(imageEmits, emit, [\"error\"]);\n\n\t\tuseRender(() => (\n\t\t\t<ElImage\n\t\t\t\t{...bindProps.value}\n\t\t\t\t{...bindEmits.value}\n\t\t\t\tclass=\"fa-image\"\n\t\t\t\tref={imageRef}\n\t\t\t\tsrc={state.src}\n\t\t\t\tpreviewSrcList={state.previewList}\n\t\t\t\tonError={(event) => {\n\t\t\t\t\tstate.loadError ||= true;\n\t\t\t\t\temit(\"error\", event);\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{{\n\t\t\t\t\terror: () =>\n\t\t\t\t\t\tslots.error ? (\n\t\t\t\t\t\t\tslots.error()\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<div class=\"fa-image__error-image\">\n\t\t\t\t\t\t\t\t<ElIcon class=\"icon\">\n\t\t\t\t\t\t\t\t\t<ElIconPicture />\n\t\t\t\t\t\t\t\t</ElIcon>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t),\n\t\t\t\t\t...(slots.placeholder && { placeholder: () => slots.placeholder?.() ?? [] }),\n\t\t\t\t\t...(slots.viewer && { viewer: () => slots.viewer?.({ src: state.src }) ?? [] }),\n\t\t\t\t\t...(slots.progress && {\n\t\t\t\t\t\tprogress: (scope: { activeIndex: number; total: number }) => slots.progress?.(scope) ?? [],\n\t\t\t\t\t}),\n\t\t\t\t\t...(slots.toolbar && {\n\t\t\t\t\t\ttoolbar: (scope: FaImageSlots[\"toolbar\"]) => slots.toolbar?.(scope) ?? [],\n\t\t\t\t\t}),\n\t\t\t\t\t...(slots[\"viewer-error\"] && {\n\t\t\t\t\t\t\"viewer-error\": (scope: { activeIndex: number; src: string }) => slots[\"viewer-error\"]?.(scope) ?? [],\n\t\t\t\t\t}),\n\t\t\t\t}}\n\t\t\t</ElImage>\n\t\t));\n\n\t\treturn useExpose(expose, {\n\t\t\t/** 手动打开图片预览。 */\n\t\t\tshowPreview: computed(() => imageRef.value?.showPreview),\n\t\t});\n\t},\n});\n"],"mappings":";;;;;;;;;;AAOA,MAAa,eAAe;CAE3B,GAAG;;CAEH,kBAAkB;EACjB,MAAM;EACN,SAAS;CACV;;CAEA,mBAAmB;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