Skip to content

Commit 913b374

Browse files
committed
Introduce TypeScript
1 parent 4c0a6e7 commit 913b374

26 files changed

+1663
-645
lines changed

.eslintrc

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
{
2-
"extends": ["eslint:recommended", "plugin:vue/vue3-essential", "prettier"],
2+
"extends": [
3+
"eslint:recommended",
4+
"plugin:vue/vue3-recommended",
5+
"@vue/typescript/recommended",
6+
"prettier"
7+
],
8+
"parser": "vue-eslint-parser",
39
"parserOptions": {
10+
"parser": "@typescript-eslint/parser",
411
"ecmaVersion": "latest"
512
},
6-
"plugins": ["prettier"],
13+
"plugins": ["@typescript-eslint", "prettier"],
714
"rules": {
8-
"prettier/prettier": "warn"
15+
"@typescript-eslint/ban-types": "off",
16+
"prettier/prettier": "warn",
17+
"vue/require-default-prop": "off"
918
}
1019
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ pnpm-debug.log*
2020
*.njsproj
2121
*.sln
2222
*.sw?
23+
24+
# TypeScript
25+
*.tsbuildinfo

.lintstagedrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"*.{js,vue}": "eslint --fix",
2+
"*.{js,ts,vue}": "eslint --fix",
33
"*": "prettier --write"
44
}

README.md

-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ export default {
110110

111111
**Note:** Public methods can be accessed via a [template ref](https://vuejs.org/guide/essentials/template-refs.html).
112112

113-
### Static Methods
114-
115-
Besides the component itself, the module also includes a `getDocument` function for manual loading of PDF documents, which can then be used as the `source` prop of the component. In most cases it is sufficient to specify the `source` prop with a URL or typed array, while the result of the `getDocument` function can be used in special cases, such as sharing the source between multiple component instances. This is an advanced topic, so it is recommended to check the source code of the component before using this function.
116-
117113
## Common Issues
118114

119115
This is a client-side library, so it is important to keep this in mind when working with SSR (server-side rendering) frameworks such as Nuxt. Depending on the framework used, you may need to properly configure the library import or use a wrapper.

dev/App.vue

+19-32
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,26 @@
11
<template>
2-
<VuePdfEmbed
3-
:image-resources-path="annotationIconsPath"
4-
:source="pdfSource"
5-
/>
2+
<VuePdfEmbed :source="pdfSource" />
63
</template>
74

8-
<script>
9-
import VuePdfEmbed from '../src/vue-pdf-embed.vue'
5+
<script setup lang="ts">
6+
import VuePdfEmbed from '../src/index'
107
11-
export default {
12-
components: {
13-
VuePdfEmbed,
14-
},
15-
data() {
16-
return {
17-
annotationIconsPath: '../node_modules/pdfjs-dist/web/images/',
18-
pdfSource:
19-
'data:application/pdf;base64,' +
20-
'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxv' +
21-
'ZwogIC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFn' +
22-
'ZXMKICAvTWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBb' +
23-
'IDMgMCBSIF0KPj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFy' +
24-
'ZW50IDIgMCBSCiAgL1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQg' +
25-
'MCBSIAogICAgPj4KICA+PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBv' +
26-
'YmoKPDwKICAvVHlwZSAvRm9udAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAv' +
27-
'VGltZXMtUm9tYW4KPj4KZW5kb2JqCgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAog' +
28-
'IC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8s' +
29-
'IHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagoKeHJlZgowIDYKMDAwMDAwMDAw' +
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MDAwMDAwMDEwIDAwMDAwIG4gCjAwMDAwMDAwNzkgMDAwMDAgbiAK' +
21+
'MDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAwMDAwIG4gCjAwMDAwMDAzODAg' +
22+
'MDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9vdCAxIDAgUgo+PgpzdGFy' +
23+
'dHhyZWYKNDkyCiUlRU9G'
3724
</script>
3825

3926
<style lang="scss">

dev/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
</head>
88
<body>
99
<div id="app"></div>
10-
<script type="module" src="./main.js"></script>
10+
<script type="module" src="./main.ts"></script>
1111
</body>
1212
</html>

dev/main.js renamed to dev/main.ts

File renamed without changes.

env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

global.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare global {
2+
interface Window {
3+
Vue: unknown
4+
VuePdfEmbed: unknown
5+
}
6+
}
7+
8+
export {}

0 commit comments

Comments
 (0)