vue-files-preview-inno
Version:
A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.
1 lines • 4.9 kB
Source Map (JSON)
{"version":3,"file":"index.vue2.mjs","sources":["../../../../../../packages/preview/supports/unknown-preview/index.vue"],"sourcesContent":["<script lang='ts' setup>\nimport { computed, onMounted } from 'vue'\nimport type { PreviewProps } from '../../preview.interface'\nimport { getFileNameFromUrl, getFileType, getFileTypeFromUrl } from '../../utils/utils'\n\nconst props = withDefaults(\n defineProps<PreviewProps>(),\n {\n url: () => null,\n file: () => null,\n },\n)\n\nconst emit = defineEmits<{\n error: [error: Error]\n}>()\n\nconst fileExtension = computed(() => {\n if (props.file) {\n const ext = getFileType(props.file, props.name)\n return ext ? `.${ext}` : ''\n }\n if (props.url) {\n const ext = getFileTypeFromUrl(props.url)\n return ext ? `.${ext}` : ''\n }\n return ''\n})\n\nconst fileName = computed(() => {\n if (props.file && 'name' in props.file && props.file.name) {\n return props.file.name\n }\n if (props.name) {\n return props.name\n }\n if (props.url) {\n return getFileNameFromUrl(props.url)\n }\n return ''\n})\n\nonMounted(() => {\n emit('error', new Error(`Unsupported file type: ${fileExtension.value}`))\n})\n</script>\n\n<template>\n <div class=\"unknown-preview\">\n <div class=\"unknown-preview-icon-wrapper\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z\"/>\n <polyline points=\"14 2 14 8 20 8\"/>\n </svg>\n <span v-if=\"fileExtension\" class=\"unknown-preview-badge\">{{ fileExtension }}</span>\n </div>\n <div v-if=\"fileName\" class=\"unknown-preview-name\" :title=\"fileName\">{{ fileName }}</div>\n <div class=\"unknown-preview-tip\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\"/>\n <line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"12\"/>\n <line x1=\"12\" y1=\"16\" x2=\"12.01\" y2=\"16\"/>\n </svg>\n <span>This file type is not supported for preview</span>\n </div>\n </div>\n</template>\n\n<style scoped lang='scss'>\n.unknown-preview {\n width: 100%;\n height: 100%;\n min-height: 200px;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 20px;\n background: #fff;\n}\n\n.unknown-preview-icon-wrapper {\n position: relative;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 88px;\n height: 88px;\n border-radius: 20px;\n background: linear-gradient(135deg, #f0f4ff 0%, #e8ecf8 100%);\n color: #8b9dc3;\n}\n\n.unknown-preview-badge {\n position: absolute;\n bottom: -6px;\n right: -6px;\n padding: 2px 8px;\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: white;\n font-size: 11px;\n font-weight: 600;\n border-radius: 6px;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n}\n\n.unknown-preview-name {\n font-size: 15px;\n font-weight: 500;\n color: #333;\n max-width: 280px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.unknown-preview-tip {\n display: flex;\n align-items: center;\n gap: 6px;\n font-size: 13px;\n color: #aab2c0;\n\n svg {\n flex-shrink: 0;\n }\n}\n</style>"],"names":["props","__props","emit","__emit","fileExtension","computed","ext","getFileType","getFileTypeFromUrl","fileName","getFileNameFromUrl","onMounted","_openBlock","_createElementBlock","_hoisted_1","_createElementVNode","_hoisted_2","_hoisted_3","_toDisplayString","_hoisted_4"],"mappings":";;;;;;;;;;;;;;AAKA,UAAMA,IAAQC,GAQRC,IAAOC,GAIPC,IAAgBC,EAAS,MAAM;AACnC,UAAIL,EAAM,MAAM;AACd,cAAMM,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