Skip to content

Commit

Permalink
top-level await no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
SuttonKyle committed Jun 7, 2024
1 parent a84ccbd commit 2a8743c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion example/example.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { init } from '../dist/esnext';
import { init } from '../dist/es2015';

init('http://localhost:8080/pdf.worker.min.mjs');
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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}'",
Expand Down
11 changes: 2 additions & 9 deletions src/base.ts
Original file line number Diff line number Diff line change
@@ -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 = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-left" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"/>
</svg>`;
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"jsx": "react",
"lib": [
"dom",
"ESNext"
"es2015"
],
"module": "ESNext",
"module": "es2015",
"moduleResolution": "node",
"noEmitOnError": true,
"noErrorTruncation": true,
Expand All @@ -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/*"
Expand Down

0 comments on commit 2a8743c

Please sign in to comment.