From 2a8743cb4864c35c800482f9d39bc93eba2eb7e2 Mon Sep 17 00:00:00 2001 From: Kyle Date: Fri, 7 Jun 2024 13:24:21 -0400 Subject: [PATCH] top-level await no longer needed --- example/example.ts | 2 +- package.json | 8 ++++---- src/base.ts | 11 ++--------- tsconfig.json | 8 ++++---- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/example/example.ts b/example/example.ts index 365ce9f..6b14448 100644 --- a/example/example.ts +++ b/example/example.ts @@ -1,3 +1,3 @@ -import { init } from '../dist/esnext'; +import { init } from '../dist/es2015'; init('http://localhost:8080/pdf.worker.min.mjs'); \ No newline at end of file diff --git a/package.json b/package.json index d324ffc..6a9dcca 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "version": "1.0.0-legacy", "description": "PDF and MS Doc viewer written in TypeScript for React and vanilla JavaScript", "main": "dist/lib/index.js", - "module": "dist/esnext/index.js", - "types": "dist/esnext/index.d.ts", + "module": "dist/es2015/index.js", + "types": "dist/es2015/index.d.ts", "engines": { "node": ">=18.15.0" }, @@ -13,8 +13,8 @@ "styles" ], "scripts": { - "build": "npm run build-esnext", - "build-esnext": "tsc -p tsconfig.json", + "build": "npm run build-es2015", + "build-es2015": "tsc -p tsconfig.json", "build-example": "npm run build && tsc -p tsconfig.example.json && webpack", "clean": "rimraf ./dist ./build", "lint:no-fix": "eslint --config='.eslintrc.js' './src/*.{ts,tsx}' './tests/*.{ts,tsx}'", diff --git a/src/base.ts b/src/base.ts index d2b6e43..5fa6f38 100644 --- a/src/base.ts +++ b/src/base.ts @@ -1,7 +1,6 @@ -import type { PDFDocumentProxy, PDFPageProxy, PageViewport } from 'pdfjs-dist/legacy/build/pdf.mjs'; +import { GlobalWorkerOptions, PDFDocumentProxy, PDFPageProxy, PageViewport, getDocument, renderTextLayer,} from 'pdfjs-dist/legacy/build/pdf.mjs'; import type { TextContent } from 'pdfjs-dist/types/src/display/api'; -const { GlobalWorkerOptions, getDocument, renderTextLayer } = await import('pdfjs-dist/legacy/build/pdf.mjs'); const chevronLeft = ` `; @@ -271,13 +270,7 @@ export const renderDocument = (workerSrc: string) => (containerDiv: Element) => try { (() => globalThis)(); new File([], 'test.txt'); - - if (typeof window !== 'undefined' && 'Worker' in window) { - GlobalWorkerOptions.workerPort = new Worker( - new URL(workerSrc, import.meta.url), - { type: 'module' } - ); - } + GlobalWorkerOptions.workerSrc = workerSrc; renderPDF(containerDiv, documentUrl); } catch (err) { diff --git a/tsconfig.json b/tsconfig.json index 2b9e567..fec37f1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,9 +8,9 @@ "jsx": "react", "lib": [ "dom", - "ESNext" + "es2015" ], - "module": "ESNext", + "module": "es2015", "moduleResolution": "node", "noEmitOnError": true, "noErrorTruncation": true, @@ -21,10 +21,10 @@ "noUnusedLocals": false, "noUnusedParameters": false, "pretty": true, - "outDir": "./dist/esnext", + "outDir": "./dist/es2015", "sourceMap": true, "strict": true, - "target": "ESNext" + "target": "es2015" }, "include": [ "src/*"