@profpowell/pdf-viewer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +6 -0
- package/custom-elements.json +316 -0
- package/dist/pdf-viewer.js +16042 -0
- package/package.json +70 -0
- package/pdf-viewer.d.ts +147 -0
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@profpowell/pdf-viewer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A PDF viewer web component wrapping PDF.js with navigation, zoom, search, thumbnails, and theme support",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/pdf-viewer.js",
|
|
7
|
+
"module": "dist/pdf-viewer.js",
|
|
8
|
+
"types": "pdf-viewer.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./pdf-viewer.d.ts",
|
|
12
|
+
"import": "./dist/pdf-viewer.js",
|
|
13
|
+
"default": "./dist/pdf-viewer.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"pdf-viewer.d.ts",
|
|
22
|
+
"custom-elements.json",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "vite",
|
|
28
|
+
"build": "vite build",
|
|
29
|
+
"preview": "vite preview",
|
|
30
|
+
"test": "playwright test",
|
|
31
|
+
"test:ui": "playwright test --ui",
|
|
32
|
+
"lint": "eslint src/",
|
|
33
|
+
"lint:fix": "eslint src/ --fix",
|
|
34
|
+
"format": "prettier --write \"src/**/*.js\"",
|
|
35
|
+
"format:check": "prettier --check \"src/**/*.js\"",
|
|
36
|
+
"analyze": "cem analyze",
|
|
37
|
+
"prepublishOnly": "npm run build && npm run analyze"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"web-components",
|
|
41
|
+
"custom-elements",
|
|
42
|
+
"vanilla-js",
|
|
43
|
+
"pdf-viewer",
|
|
44
|
+
"pdf",
|
|
45
|
+
"pdfjs",
|
|
46
|
+
"dark-mode",
|
|
47
|
+
"profpowell-web-components"
|
|
48
|
+
],
|
|
49
|
+
"author": "Prof Thomas Powell",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/ProfPowell/pdf-viewer.git"
|
|
54
|
+
},
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/ProfPowell/pdf-viewer/issues"
|
|
57
|
+
},
|
|
58
|
+
"homepage": "https://profpowell.github.io/pdf-viewer/",
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"pdfjs-dist": "^4.10.38"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@custom-elements-manifest/analyzer": "^0.11.0",
|
|
64
|
+
"@playwright/test": "^1.57.0",
|
|
65
|
+
"eslint": "^9.0.0",
|
|
66
|
+
"prettier": "^3.0.0",
|
|
67
|
+
"vite": "^6.0.0"
|
|
68
|
+
},
|
|
69
|
+
"customElements": "custom-elements.json"
|
|
70
|
+
}
|
package/pdf-viewer.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export interface PdfLoadedDetail {
|
|
2
|
+
url: string | null
|
|
3
|
+
pageCount: number
|
|
4
|
+
title: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface PdfLoadErrorDetail {
|
|
8
|
+
url: string | null
|
|
9
|
+
error: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface PageChangeDetail {
|
|
13
|
+
page: number
|
|
14
|
+
previousPage: number
|
|
15
|
+
pageCount: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ZoomChangeDetail {
|
|
19
|
+
zoom: string
|
|
20
|
+
previousZoom: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ViewChangeDetail {
|
|
24
|
+
view: 'single' | 'continuous'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface FileOpenedDetail {
|
|
28
|
+
name: string
|
|
29
|
+
size: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class PdfViewer extends HTMLElement {
|
|
33
|
+
/** URL of the PDF document to display */
|
|
34
|
+
src: string
|
|
35
|
+
|
|
36
|
+
/** Current page number (1-based) */
|
|
37
|
+
page: number
|
|
38
|
+
|
|
39
|
+
/** Zoom level: a number or mode string ("fit-width", "fit-page", "auto") */
|
|
40
|
+
zoom: string
|
|
41
|
+
|
|
42
|
+
/** Color scheme. Omit for auto-detection from page/system preference */
|
|
43
|
+
mode: 'light' | 'dark' | ''
|
|
44
|
+
|
|
45
|
+
/** View mode */
|
|
46
|
+
view: 'single' | 'continuous'
|
|
47
|
+
|
|
48
|
+
/** Whether the toolbar is shown */
|
|
49
|
+
readonly showToolbar: boolean
|
|
50
|
+
|
|
51
|
+
/** Whether the thumbnail sidebar is shown */
|
|
52
|
+
readonly showThumbnails: boolean
|
|
53
|
+
|
|
54
|
+
/** Whether the search bar is shown */
|
|
55
|
+
readonly showSearch: boolean
|
|
56
|
+
|
|
57
|
+
/** Whether the download button is hidden */
|
|
58
|
+
readonly noDownload: boolean
|
|
59
|
+
|
|
60
|
+
/** Whether the print button is hidden */
|
|
61
|
+
readonly noPrint: boolean
|
|
62
|
+
|
|
63
|
+
/** Title displayed in the toolbar */
|
|
64
|
+
readonly viewerTitle: string
|
|
65
|
+
|
|
66
|
+
/** Whether lazy loading is enabled */
|
|
67
|
+
readonly lazy: boolean
|
|
68
|
+
|
|
69
|
+
/** Navigate to the next page */
|
|
70
|
+
nextPage(): void
|
|
71
|
+
|
|
72
|
+
/** Navigate to the previous page */
|
|
73
|
+
prevPage(): void
|
|
74
|
+
|
|
75
|
+
/** Navigate to a specific page number */
|
|
76
|
+
goToPage(pageNumber: number): void
|
|
77
|
+
|
|
78
|
+
/** Get the total number of pages */
|
|
79
|
+
getPageCount(): number
|
|
80
|
+
|
|
81
|
+
/** Get the current page number */
|
|
82
|
+
getCurrentPage(): number
|
|
83
|
+
|
|
84
|
+
/** Zoom in one step */
|
|
85
|
+
zoomIn(): void
|
|
86
|
+
|
|
87
|
+
/** Zoom out one step */
|
|
88
|
+
zoomOut(): void
|
|
89
|
+
|
|
90
|
+
/** Set zoom to a specific level or mode */
|
|
91
|
+
setZoom(level: number | 'fit-width' | 'fit-page' | 'auto'): void
|
|
92
|
+
|
|
93
|
+
/** Load a PDF from an ArrayBuffer, Uint8Array, or File */
|
|
94
|
+
setData(source: ArrayBuffer | Uint8Array | File): Promise<void>
|
|
95
|
+
|
|
96
|
+
/** Open a file picker dialog to select a PDF */
|
|
97
|
+
openFile(): void
|
|
98
|
+
|
|
99
|
+
/** Download the current PDF */
|
|
100
|
+
download(): Promise<void>
|
|
101
|
+
|
|
102
|
+
/** Print the current PDF */
|
|
103
|
+
print(): Promise<void>
|
|
104
|
+
|
|
105
|
+
/** Search for text in the document */
|
|
106
|
+
search(query: string): Promise<void>
|
|
107
|
+
|
|
108
|
+
/** Clear the current search */
|
|
109
|
+
clearSearch(): void
|
|
110
|
+
|
|
111
|
+
/** Toggle fullscreen mode */
|
|
112
|
+
toggleFullscreen(): void
|
|
113
|
+
|
|
114
|
+
/** Toggle the thumbnail sidebar */
|
|
115
|
+
toggleThumbnails(): void
|
|
116
|
+
|
|
117
|
+
/** Toggle the search bar */
|
|
118
|
+
toggleSearch(): void
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declare global {
|
|
122
|
+
interface HTMLElementTagNameMap {
|
|
123
|
+
'pdf-viewer': PdfViewer
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
namespace JSX {
|
|
127
|
+
interface IntrinsicElements {
|
|
128
|
+
'pdf-viewer': React.DetailedHTMLProps<
|
|
129
|
+
React.HTMLAttributes<PdfViewer> & {
|
|
130
|
+
src?: string
|
|
131
|
+
page?: number | string
|
|
132
|
+
zoom?: string
|
|
133
|
+
mode?: 'light' | 'dark'
|
|
134
|
+
view?: 'single' | 'continuous'
|
|
135
|
+
'show-toolbar'?: boolean | string
|
|
136
|
+
'show-thumbnails'?: boolean | string
|
|
137
|
+
'show-search'?: boolean | string
|
|
138
|
+
'no-download'?: boolean | string
|
|
139
|
+
'no-print'?: boolean | string
|
|
140
|
+
title?: string
|
|
141
|
+
lazy?: boolean | string
|
|
142
|
+
},
|
|
143
|
+
PdfViewer
|
|
144
|
+
>
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|