|
1 | 1 | <script setup lang="ts">
|
2 |
| -import { reactive, useTemplateRef, ref, watchEffect } from 'vue' |
3 |
| -import { VuePDFjs, usePDF } from '../packages/vue' |
4 |
| -import '../packages/vue/dist/style.css' |
5 |
| -import enUS_FTL from '../packages/vue/dist/l10n/en-US/viewer.ftl?raw' |
6 |
| -import type { VuePDFjsProps } from '../packages/vue/dist/src/components/VuePDFjs.vue'; |
| 2 | +import { defineClientComponent } from 'vitepress' |
7 | 3 |
|
8 |
| -const vuepdfjs = useTemplateRef<typeof VuePDFjs>('vuepdfjs') |
9 |
| - |
10 |
| -const pages = ref(0); |
11 |
| -const hideToolbar = ref(false); |
12 |
| -const hideSidebar = ref(false); |
13 |
| - |
14 |
| -const options = reactive<NonNullable<VuePDFjsProps['options']>>({ |
15 |
| - locale: { |
16 |
| - code: 'en-US', |
17 |
| - ftl: enUS_FTL |
18 |
| - }, |
19 |
| - toolbar: { |
20 |
| - visible: true, |
21 |
| - options: { |
22 |
| - sidebarToggle: true, |
23 |
| - } |
24 |
| - }, |
25 |
| - sidebar: { |
26 |
| - visible: true |
27 |
| - } |
28 |
| -}) |
29 |
| - |
30 |
| -watchEffect(() => { |
31 |
| - if(options.toolbar) { |
32 |
| - options.toolbar.visible = !hideToolbar.value |
33 |
| - options.toolbar.options = { |
34 |
| - ...options.toolbar.options, |
35 |
| - sidebarToggle: !hideSidebar.value |
36 |
| - } |
37 |
| - } |
38 |
| - |
39 |
| - if(options.sidebar) { |
40 |
| - options.sidebar.visible = !hideSidebar.value |
41 |
| - } |
| 4 | +const PdfComp = defineClientComponent(() => { |
| 5 | + return import("./components/PdfViewer.vue") |
42 | 6 | })
|
43 |
| - |
44 |
| -const onPdfAppLoaded = () => { |
45 |
| - console.log('pdf-app:loaded') |
46 |
| - console.log(vuepdfjs.value?.pdfApp) |
47 |
| - |
48 |
| - if (!vuepdfjs.value?.pdfApp) { |
49 |
| - return |
50 |
| - } |
51 |
| - |
52 |
| - vuepdfjs.value.pdfApp.eventBus.on('pagesloaded', (e: { |
53 |
| - source: PDFViewer, pagesCount: number |
54 |
| - }) => { |
55 |
| - vuepdfjs.value?.pdfApp.eventBus.dispatch('find', { |
56 |
| - query: ['Dynamic languages such as JavaScript are more difficult to compile than statically typed ones.'], |
57 |
| - caseSensitive: false, |
58 |
| - entireWord: false, |
59 |
| - highlightAll: true |
60 |
| - }) |
61 |
| - |
62 |
| - //Set the number of pages in the ref |
63 |
| - pages.value = e.pagesCount |
64 |
| - }) |
65 |
| -} |
66 |
| - |
67 |
| -const pdf = 'https://raw.githubusercontent.com/mozilla/pdf.js/v4.9.124/web/compressed.tracemonkey-pldi-09.pdf' |
68 | 7 | </script>
|
69 | 8 |
|
70 | 9 | # Playground
|
71 | 10 |
|
72 |
| -We have {{ pages }} pages in this document. |
73 |
| - |
74 |
| -<div> |
75 |
| - <input type="checkbox" v-model="hideToolbar" /> Hide Toolbar |
76 |
| - <input type="checkbox" v-model="hideSidebar" /> Hide Sidebar |
77 |
| -</div> |
78 |
| - |
79 | 11 | <div class="pdf_viewer">
|
80 |
| -<VuePDFjs ref="vuepdfjs" :source="pdf" :options="options" @pdf-app:loaded="onPdfAppLoaded" /> |
| 12 | + <PdfComp /> |
81 | 13 | </div>
|
82 | 14 |
|
83 | 15 | <style>
|
84 | 16 | ._vue-pdf_js_playground > div {
|
85 | 17 | width: 100%;
|
86 | 18 | }
|
87 |
| - |
88 |
| -.pdf_viewer { |
89 |
| - height: 650px; |
90 |
| - width: 100%; |
91 |
| - overflow: hidden; |
92 |
| -} |
93 | 19 | </style>
|
0 commit comments