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.47 kB
Source Map (JSON)
{"version":3,"file":"index.vue2.mjs","sources":["../../../../../../packages/preview/supports/epub-preview/index.vue"],"sourcesContent":["<script lang='ts' setup>\nimport {ref, watch} from 'vue'\nimport ePub from 'epubjs'\nimport type {PreviewProps} from '../../preview.interface'\nimport {getFileRenderByFile} from '../../utils/utils'\n\nconst props = withDefaults(\n defineProps<PreviewProps & {\n width?: string\n height?: string\n }>(),\n {\n url: () => null,\n file: () => null,\n width: () => '100%',\n height: () => '100%',\n },\n)\n\nconst navigation = ref()\nconst locations = ref()\nconst currentPage = ref(1)\nconst totalPages = ref()\nconst bookAvailable = ref(false)\nconst book = ref()\nconst rendition = ref()\n\nfunction initEpub(): void {\n if (props.file) {\n getFileRenderByFile(props.file).then((render) => {\n book.value = ePub(render as ArrayBuffer)\n rendition.value = book.value.renderTo('epub-viewer', {\n // Scroll mode\n width: '100%',\n height: 'calc(100vh - 80x)',\n flow: 'scrolled',\n allowScriptedContent: true,\n })\n book.value.ready.then(() => {\n navigation.value = book.value.navigation\n locations.value = book.value.locations\n bookAvailable.value = true\n // Get the total number of pages\n totalPages.value = locations.value.length()\n rendition.value.display()\n })\n })\n }\n}\n\nwatch(\n () => props.file,\n () => {\n initEpub()\n },\n {immediate: true},\n)\n\n// epub\nfunction prevPage(): void {\n if (rendition.value) {\n rendition.value.prev()\n // Update when page forward currentPage\n currentPage.value--\n if (currentPage.value < 1) {\n currentPage.value = 1\n }\n }\n}\n\nfunction nextPage(): void {\n if (rendition.value) {\n rendition.value.next()\n // Update when turning back page currentPage\n currentPage.value++\n if (currentPage.value > totalPages.value) {\n currentPage.value = totalPages.value\n }\n }\n}\n\nfunction prevKeyDown(e): void {\n e.preventDefault()\n}\n\nfunction downKeyDown(e): void {\n e.preventDefault()\n}\n\nonKeyStroke('ArrowLeft', () => {\n prevPage()\n})\n\nonKeyStroke('ArrowRight', () => {\n nextPage()\n})\n</script>\n\n<template>\n <div class=\"epub-preview epub-box\" :style=\"{ width, height }\">\n <button class=\"btn\" style=\"display: none\" @keydown=\"prevKeyDown\">\n Prev\n </button>\n <div id=\"epub-viewer\" class=\"epub-viewer\"/>\n <button class=\"btn\" style=\"display: none\" @keydown=\"downKeyDown\">\n Next\n </button>\n </div>\n</template>\n\n<style scoped lang=\"scss\">\n.epub-box {\n height: 100vh;\n width: 100%;\n}\n\n.epub-viewer {\n padding: 10px;\n min-height: calc(100vh - 80px);\n max-height: calc(100vh - 80px);\n overflow: auto;\n}\n\n.footer {\n height: 24px;\n display: flex;\n justify-content: center;\n align-items: center;\n padding: 10px;\n}\n</style>\n"],"names":["props","__props","navigation","ref","locations","currentPage","totalPages","bookAvailable","book","rendition","initEpub","getFileRenderByFile","render","ePub","watch","prevPage","nextPage","prevKeyDown","downKeyDown","onKeyStroke"],"mappings":";;;;;;;;;;;;;;;;;;;;AAMA,UAAMA,IAAQC,GAaRC,IAAaC,EAAA,GACbC,IAAYD,EAAA,GACZE,IAAcF,EAAI,CAAC,GACnBG,IAAaH,EAAA,GACbI,IAAgBJ,EAAI,EAAK,GACzBK,IAAOL,EAAA,GACPM,IAAYN,EAAA;AAElB,aAASO,IAAiB;AACxB,MAAIV,EAAM,QACRW,EAAoBX,EAAM,IAAI,EAAE,KAAK,CAACY,MAAW;AAC/C,QAAAJ,EAAK,QAAQK,EAAKD,CAAqB,GACvCH,EAAU,QAAQD,EAAK,MAAM,SAAS,eAAe;AAAA;AAAA,UAEnD,OAAO;AAAA,UACP,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,sBAAsB;AAAA,QAAA,CACvB,GACDA,EAAK,MAAM,MAAM,KAAK,MAAM;AAC1B,UAAAN,EAAW,QAAQM,EAAK,MAAM,YAC9BJ,EAAU,QAAQI,EAAK,MAAM,WAC7BD,EAAc,QAAQ,IAEtBD,EAAW,QAAQF,EAAU,MAAM,OAAA,GACnCK,EAAU,MAAM,QAAA;AA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