Skip to content

Commit 21cf7ed

Browse files
authored
Merge pull request #15 from privy-open-source/feat/pdf-navigation-slot
Feat: pdf navigation slot
2 parents 7bfca25 + 0e2520d commit 21cf7ed

File tree

7 files changed

+79
-260
lines changed

7 files changed

+79
-260
lines changed

demo/src/App.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ const object = reactive<IPdfObject>({
3131
src="https://via.placeholder.com/430x230/23B242/ffffff"
3232
/>
3333
</pdf-object>
34+
35+
<!-- <template #navigation="{ zoomIn, zoomOut, page, totalPage, next, prev }">
36+
<button @click="zoomOut">Zoom Out</button>
37+
<button @click="zoomIn">Zoom In</button>
38+
<div>
39+
Page <span>{{ page }}</span> / {{ totalPage }}
40+
</div>
41+
<button @click="prev">Prev</button>
42+
<button @click="next">Next</button>
43+
</template> -->
3444
</pdf-viewer>
3545
</div>
3646
</template>

demo/vite.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { fileURLToPath, URL } from 'node:url'
2+
3+
import { defineConfig } from 'vite'
4+
import vue from '@vitejs/plugin-vue'
5+
import Icons from 'unplugin-icons/vite'
6+
7+
// https://vitejs.dev/config/
8+
export default defineConfig({
9+
root: 'demo/',
10+
plugins: [vue(), Icons({ compiler: 'vue3' })],
11+
resolve: {
12+
alias: {
13+
'@': fileURLToPath(new URL('../src', import.meta.url))
14+
}
15+
},
16+
})

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "https://github.com/privy-open-source/pdf-ajaib.git"
99
},
1010
"scripts": {
11-
"dev": "vite",
11+
"dev": "vite --config=./demo/vite.config.ts",
1212
"build": "vite build && vue-tsc --emitDeclarationOnly",
1313
"preview": "vite preview",
1414
"test:unit": "vitest",
@@ -44,7 +44,6 @@
4444
"@iconify-json/carbon": "^1.1.16",
4545
"@interactjs/types": "^1.10.17",
4646
"@itsy/vite-css-inject": "^1.0.2",
47-
"@nuxt/kit": "^3.3.2",
4847
"@rollup/plugin-typescript": "^11.0.0",
4948
"@rushstack/eslint-patch": "^1.2.0",
5049
"@types/jest": "^29.5.0",
@@ -78,7 +77,6 @@
7877
"vue-tsc": "^1.2.0"
7978
},
8079
"peerDependencies": {
81-
"@nuxt/kit": "npm:@nuxt/kit-edge@latest",
8280
"@vue/compiler-sfc": "^3.2.47",
8381
"@vue/composition-api": "^1.4.1",
8482
"vue": "^2.0.0 || >=3.0.0-rc.0"

src/components/pdf-viewers/PdfNavigation.vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export default defineComponent({
9191
left: 0px;
9292
right: 0px;
9393
bottom: 2.5rem;
94-
z-index: 10;
9594
margin-left: auto;
9695
margin-right: auto;
9796
display: flex;
@@ -113,10 +112,6 @@ export default defineComponent({
113112
border-style: none;
114113
color: rgb(182, 184, 185);
115114
cursor: pointer;
116-
117-
&:hover {
118-
119-
}
120115
}
121116
122117
.pdf-zoom-out {

src/components/pdf-viewers/PdfViewer.vue

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script lang="ts">
2-
import type { PropType} from 'vue-demi';
2+
import type { PropType } from 'vue-demi'
33
import { computed, defineComponent, onMounted, provide, toRef, watch } from 'vue-demi'
44
import { pAspectRatio } from '@/directives/aspect-ratio'
55
import { templateRef, useToNumber, useVModel, watchDebounced, syncRef } from '@vueuse/core'
6-
import type { LayoutVariant} from './main';
6+
import type { LayoutVariant } from './main'
77
import { PDF_VIEWER_CONTEXT } from './main'
88
import { useSticky } from './utils/use-sticky'
99
import PdfNavigation from './PdfNavigation.vue'
@@ -133,6 +133,22 @@ export default defineComponent({
133133
syncRef(pdfPage, vPage)
134134
syncRef(pdfScale, vScale)
135135
136+
function pdfZoomIn() {
137+
pdfScale.value = Math.round(pdfScale.value / 0.1) * 0.1 + 0.1
138+
}
139+
140+
function pdfZoomOut() {
141+
pdfScale.value = Math.round(pdfScale.value / 0.1) * 0.1 - 0.1
142+
}
143+
144+
function pdfNextPage() {
145+
pdfPage.value++
146+
}
147+
148+
function pdfPrevPage() {
149+
pdfPage.value--
150+
}
151+
136152
return {
137153
pdfPage,
138154
pdfScale,
@@ -144,7 +160,11 @@ export default defineComponent({
144160
pdfJS,
145161
idle,
146162
loading,
147-
error
163+
error,
164+
pdfZoomIn,
165+
pdfZoomOut,
166+
pdfNextPage,
167+
pdfPrevPage
148168
}
149169
}
150170
})
@@ -181,7 +201,22 @@ export default defineComponent({
181201
/>
182202

183203
<transition name="slide-up">
184-
<pdf-navigation v-show="!idle" />
204+
<div class="pdf__navigation">
205+
<slot
206+
name="navigation"
207+
:idle="idle"
208+
:page="pdfPage"
209+
:scale="scale"
210+
:totalPage="totalPage"
211+
:zoom-in="pdfZoomIn"
212+
:zoom-out="pdfZoomOut"
213+
:next="pdfNextPage"
214+
:prev="pdfPrevPage"
215+
:doc="pdfDoc"
216+
>
217+
<pdf-navigation v-show="!idle" />
218+
</slot>
219+
</div>
185220
</transition>
186221

187222
<slot name="body" :page="pdfPage" :scale="pdfScale" :total-page="totalPage" :doc="pdfDoc" />
@@ -240,5 +275,9 @@ export default defineComponent({
240275
z-index: 1;
241276
background-color: white;
242277
}
278+
279+
&__navigation {
280+
z-index: 10;
281+
}
243282
}
244283
</style>

src/nuxt/module.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)