Skip to content

Commit eaa8156

Browse files
committed
Update pdf.js to v4.10.38. Fix for warning: Setting up fake worker.
1 parent 318c773 commit eaa8156

File tree

10 files changed

+147
-78
lines changed

10 files changed

+147
-78
lines changed

bun.lockb

-72 Bytes
Binary file not shown.

docs/components/PdfViewer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const onPdfAppLoaded = () => {
6464
})
6565
}
6666
67-
const pdf = 'https://raw.githubusercontent.com/mozilla/pdf.js/v4.9.124/web/compressed.tracemonkey-pldi-09.pdf'
67+
const pdf = 'https://raw.githubusercontent.com/mozilla/pdf.js/v4.10.38/web/compressed.tracemonkey-pldi-09.pdf'
6868
</script>
6969

7070
<template>

packages/vue/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@tuttarealstep/vue-pdf.js",
33
"description": "A Vue component for displaying PDF files using the standard `pdf.js` viewer. This package provides a simple and powerful integration to embed PDF viewers in Vue applications.",
4-
"version": "1.0.7",
4+
"version": "1.0.8",
55
"private": false,
66
"type": "module",
77
"author": "Stefano Valenzano (https://github.com/tuttarealstep)",
@@ -36,7 +36,7 @@
3636
"@fluent/bundle": "^0.18.0",
3737
"@fluent/dom": "^0.10.0",
3838
"ajv": "^8.17.1",
39-
"pdf.js": "git://github.com/mozilla/pdf.js.git#v4.9.124"
39+
"pdf.js": "git://github.com/mozilla/pdf.js.git#v4.10.38"
4040
},
4141
"peerDependencies": {
4242
"vue": "^3.4.29"

packages/vue/src/composable/usePDF.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import * as PDFJS from 'pdf.js/src/pdf.js'
88
import { PDFJSWorker } from '../scripts/viewer'
99

1010
export default function usePDF(source: PDFSource | Ref<PDFSource>, options?: PDFSourceOptions) {
11-
if (!PDFJS.GlobalWorkerOptions?.workerSrc) PDFJS.GlobalWorkerOptions.workerSrc = PDFJSWorker
11+
if (!PDFJS.GlobalWorkerOptions?.workerPort)
12+
PDFJS.GlobalWorkerOptions.workerPort = new PDFJSWorker()
1213

1314
const pdf = shallowRef<PDFDocumentLoadingTask>()
1415
const pages = shallowRef(0)

packages/vue/src/global.dt.ts

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

packages/vue/src/scripts/viewer.ts

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
11
//@ts-ignore
2-
import { RenderingStates, ScrollMode, SpreadMode } from "pdf.js/web/ui_utils.js";
2+
import { RenderingStates, ScrollMode, SpreadMode } from 'pdf.js/web/ui_utils.js'
33
//@ts-ignore
4-
import { AppOptions } from "pdf.js/web/app_options.js";
4+
import { AppOptions } from 'pdf.js/web/app_options.js'
55
//@ts-ignore
6-
import { LinkTarget } from "pdf.js/web/pdf_link_service.js";
6+
import { LinkTarget } from 'pdf.js/web/pdf_link_service.js'
77
//@ts-ignore
8-
import { PDFViewerApplication } from "pdf.js/web/app.js";
8+
import { PDFViewerApplication } from 'pdf.js/web/app.js'
99
//@ts-ignore
1010
import * as PDFJS from 'pdf.js/src/pdf.js'
11-
import PDFViewerApplicationConfig from "./PDFViewerApplicationConfig";
12-
import PDFJSWorker from 'pdf.js/src/pdf.worker.js?worker&url'
11+
import PDFViewerApplicationConfig from './PDFViewerApplicationConfig'
12+
import PDFJSWorker from 'pdf.js/src/pdf.worker.js?worker&inline'
1313

14-
const AppConstants = { LinkTarget, RenderingStates, ScrollMode, SpreadMode };
14+
const AppConstants = { LinkTarget, RenderingStates, ScrollMode, SpreadMode }
1515

1616
async function initViewer(element: HTMLElement): Promise<typeof PDFViewerApplication> {
17-
if (!PDFJS.GlobalWorkerOptions?.workerSrc)
18-
PDFJS.GlobalWorkerOptions.workerSrc = PDFJSWorker
19-
20-
// @ts-ignore
21-
globalThis.PDFViewerApplication = PDFViewerApplication;
22-
// @ts-ignore
23-
globalThis.PDFViewerApplicationConstants = AppConstants;
24-
// @ts-ignore
25-
globalThis.PDFViewerApplicationOptions = AppOptions;
26-
27-
//AppOptions.set('lang', 'it');
28-
AppOptions.set('disablePreferences', true);
29-
AppOptions.set('defaultUrl', '');
30-
AppOptions.set('workerSrc', PDFJSWorker);
31-
32-
/*(globalThis as any)['__VUE_PDFJS__'] = {
17+
if (!PDFJS.GlobalWorkerOptions?.workerPort)
18+
PDFJS.GlobalWorkerOptions.workerPort = new PDFJSWorker()
19+
20+
// @ts-ignore
21+
globalThis.PDFViewerApplication = PDFViewerApplication
22+
// @ts-ignore
23+
globalThis.PDFViewerApplicationConstants = AppConstants
24+
// @ts-ignore
25+
globalThis.PDFViewerApplicationOptions = AppOptions
26+
27+
//AppOptions.set('lang', 'it');
28+
AppOptions.set('disablePreferences', true)
29+
AppOptions.set('defaultUrl', '')
30+
AppOptions.set('workerPort', new PDFJSWorker())
31+
32+
/*(globalThis as any)['__VUE_PDFJS__'] = {
3333
locale: testFtl
3434
}*/
3535

36-
await PDFViewerApplication.run(PDFViewerApplicationConfig(element.getRootNode() as ShadowRoot | Document));
36+
await PDFViewerApplication.run(
37+
PDFViewerApplicationConfig(element.getRootNode() as ShadowRoot | Document)
38+
)
3739

38-
return PDFViewerApplication;
40+
return PDFViewerApplication
3941
}
4042

4143
export {
42-
AppConstants as PDFViewerApplicationConstants,
43-
AppOptions as PDFViewerApplicationOptions,
44-
initViewer,
45-
PDFJSWorker,
46-
};
44+
AppConstants as PDFViewerApplicationConstants,
45+
AppOptions as PDFViewerApplicationOptions,
46+
initViewer,
47+
PDFJSWorker
48+
}

packages/vue/tests/mount.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const {
1010
info: pdfInfo,
1111
pages: pdfPages
1212
} = usePDF(
13-
'https://raw.githubusercontent.com/mozilla/pdf.js/v4.9.124/web/compressed.tracemonkey-pldi-09.pdf'
13+
'https://raw.githubusercontent.com/mozilla/pdf.js/v4.10.38/web/compressed.tracemonkey-pldi-09.pdf'
1414
)
1515

1616
beforeAll(async () => {

packages/vue/tests/options.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {
1111
info: pdfInfo,
1212
pages: pdfPages
1313
} = usePDF(
14-
'https://raw.githubusercontent.com/mozilla/pdf.js/v4.9.124/web/compressed.tracemonkey-pldi-09.pdf'
14+
'https://raw.githubusercontent.com/mozilla/pdf.js/v4.10.38/web/compressed.tracemonkey-pldi-09.pdf'
1515
)
1616

1717
beforeAll(async () => {

packages/vue/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"./src/*"
2525
]
2626
},
27+
"types": [
28+
"vite/client"
29+
]
2730
},
2831
"include": [
2932
"src/**/*.ts",

packages/vue/vite.config.ts

Lines changed: 105 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,59 +19,126 @@ export default defineConfig({
1919
}),
2020
dts()
2121
],
22+
css: {
23+
preprocessorOptions: {
24+
scss: {
25+
api: 'modern-compiler'
26+
}
27+
}
28+
},
2229
build: {
2330
lib: {
24-
entry: path.resolve(__dirname, "src/index.ts"),
25-
name: "VuePDFjs",
26-
fileName: "vue-pdfjs"
31+
entry: path.resolve(__dirname, 'src/index.ts'),
32+
name: 'VuePDFjs',
33+
fileName: 'vue-pdfjs'
2734
},
2835
rollupOptions: {
29-
external: ["vue"],
36+
external: ['vue'],
3037
output: {
3138
globals: {
32-
vue: "Vue"
33-
}
39+
vue: 'Vue'
40+
},
41+
exports: 'named'
3442
}
3543
},
3644
},
3745
resolve: {
3846
alias: {
3947
'@': fileURLToPath(new URL('./src', import.meta.url)),
40-
'pdfjs': fileURLToPath(new URL('../../node_modules/pdf.js/src', import.meta.url)),
48+
pdfjs: fileURLToPath(new URL('../../node_modules/pdf.js/src', import.meta.url)),
4149
'pdfjs-lib': fileURLToPath(new URL('../../node_modules/pdf.js/src/pdf.js', import.meta.url)),
4250
'pdfjs-web': fileURLToPath(new URL('../../node_modules/pdf.js/web', import.meta.url)),
4351

44-
'fluent-bundle': fileURLToPath(new URL('../../node_modules/@fluent/bundle/esm/index.js', import.meta.url)),
45-
'fluent-dom': fileURLToPath(new URL('../../node_modules/@fluent/dom/esm/index.js', import.meta.url)),
46-
'cached-iterable': fileURLToPath(new URL('../../node_modules/cached-iterable/src/index.mjs', import.meta.url)),
52+
'fluent-bundle': fileURLToPath(
53+
new URL('../../node_modules/@fluent/bundle/esm/index.js', import.meta.url)
54+
),
55+
'fluent-dom': fileURLToPath(
56+
new URL('../../node_modules/@fluent/dom/esm/index.js', import.meta.url)
57+
),
58+
'cached-iterable': fileURLToPath(
59+
new URL('../../node_modules/cached-iterable/src/index.mjs', import.meta.url)
60+
),
61+
62+
'display-cmap_reader_factory': fileURLToPath(
63+
new URL('../../node_modules/pdf.js/src/display/cmap_reader_factory.js', import.meta.url)
64+
),
65+
'display-standard_fontdata_factory': fileURLToPath(
66+
new URL(
67+
'../../node_modules/pdf.js/src/display/standard_fontdata_factory.js',
68+
import.meta.url
69+
)
70+
),
4771

48-
'display-cmap_reader_factory': fileURLToPath(new URL('../../node_modules/pdf.js/src/display/cmap_reader_factory.js', import.meta.url)),
49-
'display-standard_fontdata_factory': fileURLToPath(new URL('../../node_modules/pdf.js/src/display/standard_fontdata_factory.js', import.meta.url)),
50-
51-
'display-fetch_stream': fileURLToPath(new URL('../../node_modules/pdf.js/src/display/fetch_stream.js', import.meta.url)),
52-
'display-network': fileURLToPath(new URL('../../node_modules/pdf.js/src/display/network.js', import.meta.url)),
53-
'display-node_stream': fileURLToPath(new URL('../../node_modules/pdf.js/src/display/stubs.js', import.meta.url)),
54-
'display-node_utils': fileURLToPath(new URL('../../node_modules/pdf.js/src/display/stubs.js', import.meta.url)),
72+
'display-fetch_stream': fileURLToPath(
73+
new URL('../../node_modules/pdf.js/src/display/fetch_stream.js', import.meta.url)
74+
),
75+
'display-network': fileURLToPath(
76+
new URL('../../node_modules/pdf.js/src/display/network.js', import.meta.url)
77+
),
78+
'display-node_stream': fileURLToPath(
79+
new URL('../../node_modules/pdf.js/src/display/stubs.js', import.meta.url)
80+
),
81+
'display-node_utils': fileURLToPath(
82+
new URL('../../node_modules/pdf.js/src/display/stubs.js', import.meta.url)
83+
),
5584

56-
'web-alt_text_manager': fileURLToPath(new URL('../../node_modules/pdf.js/web/alt_text_manager.js', import.meta.url)),
57-
'web-annotation_editor_params': fileURLToPath(new URL('../../node_modules/pdf.js/web/annotation_editor_params.js', import.meta.url)),
58-
'web-download_manager': fileURLToPath(new URL('../../node_modules/pdf.js/web/download_manager.js', import.meta.url)),
59-
'web-external_services': fileURLToPath(new URL('../../node_modules/pdf.js/web/genericcom.js', import.meta.url)),
60-
'web-new_alt_text_manager': fileURLToPath(new URL('../../node_modules/pdf.js/web/new_alt_text_manager.js', import.meta.url)),
61-
'web-null_l10n': fileURLToPath(new URL('../../node_modules/pdf.js/web/genericl10n.js', import.meta.url)),
62-
'web-pdf_attachment_viewer': fileURLToPath(new URL('../../node_modules/pdf.js/web/pdf_attachment_viewer.js', import.meta.url)),
63-
'web-pdf_cursor_tools': fileURLToPath(new URL('../../node_modules/pdf.js/web/pdf_cursor_tools.js', import.meta.url)),
64-
'web-pdf_document_properties': fileURLToPath(new URL('../../node_modules/pdf.js/web/pdf_document_properties.js', import.meta.url)),
65-
'web-pdf_find_bar': fileURLToPath(new URL('../../node_modules/pdf.js/web/pdf_find_bar.js', import.meta.url)),
66-
'web-pdf_layer_viewer': fileURLToPath(new URL('../../node_modules/pdf.js/web/pdf_layer_viewer.js', import.meta.url)),
67-
'web-pdf_outline_viewer': fileURLToPath(new URL('../../node_modules/pdf.js/web/pdf_outline_viewer.js', import.meta.url)),
68-
'web-pdf_presentation_mode': fileURLToPath(new URL('../../node_modules/pdf.js/web/pdf_presentation_mode.js', import.meta.url)),
69-
'web-pdf_sidebar': fileURLToPath(new URL('../../node_modules/pdf.js/web/pdf_sidebar.js', import.meta.url)),
70-
'web-pdf_thumbnail_viewer': fileURLToPath(new URL('../../node_modules/pdf.js/web/pdf_thumbnail_viewer.js', import.meta.url)),
71-
'web-preferences': fileURLToPath(new URL('../../node_modules/pdf.js/web/genericcom.js', import.meta.url)),
72-
'web-print_service': fileURLToPath(new URL('../../node_modules/pdf.js/web/pdf_print_service.js', import.meta.url)),
73-
'web-secondary_toolbar': fileURLToPath(new URL('../../node_modules/pdf.js/web/secondary_toolbar.js', import.meta.url)),
74-
'web-toolbar': fileURLToPath(new URL('../../node_modules/pdf.js/web/toolbar.js', import.meta.url)),
85+
'web-alt_text_manager': fileURLToPath(
86+
new URL('../../node_modules/pdf.js/web/alt_text_manager.js', import.meta.url)
87+
),
88+
'web-annotation_editor_params': fileURLToPath(
89+
new URL('../../node_modules/pdf.js/web/annotation_editor_params.js', import.meta.url)
90+
),
91+
'web-download_manager': fileURLToPath(
92+
new URL('../../node_modules/pdf.js/web/download_manager.js', import.meta.url)
93+
),
94+
'web-external_services': fileURLToPath(
95+
new URL('../../node_modules/pdf.js/web/genericcom.js', import.meta.url)
96+
),
97+
'web-new_alt_text_manager': fileURLToPath(
98+
new URL('../../node_modules/pdf.js/web/new_alt_text_manager.js', import.meta.url)
99+
),
100+
'web-null_l10n': fileURLToPath(
101+
new URL('../../node_modules/pdf.js/web/genericl10n.js', import.meta.url)
102+
),
103+
'web-pdf_attachment_viewer': fileURLToPath(
104+
new URL('../../node_modules/pdf.js/web/pdf_attachment_viewer.js', import.meta.url)
105+
),
106+
'web-pdf_cursor_tools': fileURLToPath(
107+
new URL('../../node_modules/pdf.js/web/pdf_cursor_tools.js', import.meta.url)
108+
),
109+
'web-pdf_document_properties': fileURLToPath(
110+
new URL('../../node_modules/pdf.js/web/pdf_document_properties.js', import.meta.url)
111+
),
112+
'web-pdf_find_bar': fileURLToPath(
113+
new URL('../../node_modules/pdf.js/web/pdf_find_bar.js', import.meta.url)
114+
),
115+
'web-pdf_layer_viewer': fileURLToPath(
116+
new URL('../../node_modules/pdf.js/web/pdf_layer_viewer.js', import.meta.url)
117+
),
118+
'web-pdf_outline_viewer': fileURLToPath(
119+
new URL('../../node_modules/pdf.js/web/pdf_outline_viewer.js', import.meta.url)
120+
),
121+
'web-pdf_presentation_mode': fileURLToPath(
122+
new URL('../../node_modules/pdf.js/web/pdf_presentation_mode.js', import.meta.url)
123+
),
124+
'web-pdf_sidebar': fileURLToPath(
125+
new URL('../../node_modules/pdf.js/web/pdf_sidebar.js', import.meta.url)
126+
),
127+
'web-pdf_thumbnail_viewer': fileURLToPath(
128+
new URL('../../node_modules/pdf.js/web/pdf_thumbnail_viewer.js', import.meta.url)
129+
),
130+
'web-preferences': fileURLToPath(
131+
new URL('../../node_modules/pdf.js/web/genericcom.js', import.meta.url)
132+
),
133+
'web-print_service': fileURLToPath(
134+
new URL('../../node_modules/pdf.js/web/pdf_print_service.js', import.meta.url)
135+
),
136+
'web-secondary_toolbar': fileURLToPath(
137+
new URL('../../node_modules/pdf.js/web/secondary_toolbar.js', import.meta.url)
138+
),
139+
'web-toolbar': fileURLToPath(
140+
new URL('../../node_modules/pdf.js/web/toolbar.js', import.meta.url)
141+
)
75142
}
76-
},
77-
})
143+
}
144+
})

0 commit comments

Comments
 (0)