@pdfme/converter 5.5.10 → 6.0.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.
Files changed (46) hide show
  1. package/package.json +30 -54
  2. package/src/index.browser.ts +33 -6
  3. package/src/index.node.ts +31 -19
  4. package/src/index.ts +1 -0
  5. package/src/pdf2img.ts +29 -20
  6. package/src/pdf2size.ts +14 -12
  7. package/src/pdfjs-dist-webpack.d.ts +20 -0
  8. package/src/pdfjs-worker-shim.ts +20 -0
  9. package/src/pdfjs-worker.js +2 -0
  10. package/src/pdfjs.node.ts +7 -0
  11. package/tsconfig.build.json +14 -0
  12. package/tsconfig.json +14 -4
  13. package/vite.config.mts +70 -0
  14. package/dist/cjs/__tests__/index.test.js +0 -189
  15. package/dist/cjs/__tests__/index.test.js.map +0 -1
  16. package/dist/cjs/src/img2pdf.js +0 -91
  17. package/dist/cjs/src/img2pdf.js.map +0 -1
  18. package/dist/cjs/src/index.browser.js +0 -80
  19. package/dist/cjs/src/index.browser.js.map +0 -1
  20. package/dist/cjs/src/index.node.js +0 -67
  21. package/dist/cjs/src/index.node.js.map +0 -1
  22. package/dist/cjs/src/pdf2img.js +0 -35
  23. package/dist/cjs/src/pdf2img.js.map +0 -1
  24. package/dist/cjs/src/pdf2size.js +0 -17
  25. package/dist/cjs/src/pdf2size.js.map +0 -1
  26. package/dist/esm/__tests__/index.test.js +0 -187
  27. package/dist/esm/__tests__/index.test.js.map +0 -1
  28. package/dist/esm/src/img2pdf.js +0 -88
  29. package/dist/esm/src/img2pdf.js.map +0 -1
  30. package/dist/esm/src/index.browser.js +0 -38
  31. package/dist/esm/src/index.browser.js.map +0 -1
  32. package/dist/esm/src/index.node.js +0 -25
  33. package/dist/esm/src/index.node.js.map +0 -1
  34. package/dist/esm/src/pdf2img.js +0 -32
  35. package/dist/esm/src/pdf2img.js.map +0 -1
  36. package/dist/esm/src/pdf2size.js +0 -14
  37. package/dist/esm/src/pdf2size.js.map +0 -1
  38. package/dist/types/__tests__/index.test.d.ts +0 -1
  39. package/dist/types/src/img2pdf.d.ts +0 -12
  40. package/dist/types/src/index.browser.d.ts +0 -8
  41. package/dist/types/src/index.node.d.ts +0 -8
  42. package/dist/types/src/pdf2img.d.ts +0 -17
  43. package/dist/types/src/pdf2size.d.ts +0 -10
  44. package/eslint.config.mjs +0 -22
  45. package/tsconfig.cjs.json +0 -10
  46. package/tsconfig.esm.json +0 -11
package/package.json CHANGED
@@ -1,80 +1,56 @@
1
1
  {
2
2
  "name": "@pdfme/converter",
3
- "version": "5.5.10",
4
- "sideEffects": false,
5
- "author": "hand-dot",
6
- "license": "MIT",
3
+ "version": "6.0.0",
4
+ "description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
7
5
  "keywords": [
8
6
  "pdf",
9
- "pdf-generation",
10
7
  "pdf-designer",
8
+ "pdf-generation",
11
9
  "pdf-viewer",
12
- "typescript",
13
- "react"
10
+ "react",
11
+ "typescript"
14
12
  ],
15
- "description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
16
13
  "homepage": "https://pdfme.com",
14
+ "bugs": {
15
+ "url": "https://github.com/pdfme/pdfme/issues"
16
+ },
17
+ "license": "MIT",
18
+ "author": "hand-dot",
17
19
  "repository": {
18
20
  "type": "git",
19
21
  "url": "git@github.com:pdfme/pdfme.git"
20
22
  },
21
- "bugs": {
22
- "url": "https://github.com/pdfme/pdfme/issues"
23
- },
24
- "main": "dist/cjs/src/index.js",
25
- "module": "dist/esm/src/index.js",
26
- "types": "dist/types/src/index.node.d.ts",
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "main": "./dist/index.js",
26
+ "module": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
27
28
  "exports": {
28
29
  ".": {
29
- "browser": "./dist/esm/src/index.browser.js",
30
- "node": "./dist/cjs/src/index.node.js",
31
- "default": "./dist/esm/src/index.browser.js",
32
- "types": "./dist/types/src/index.node.d.ts"
30
+ "types": "./dist/index.d.ts",
31
+ "browser": "./dist/index.js",
32
+ "node": "./dist/index.node.js",
33
+ "default": "./dist/index.js"
33
34
  }
34
35
  },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
35
39
  "scripts": {
36
- "dev": "tsc -p tsconfig.esm.json -w",
37
- "build": "run-p build:cjs build:esm",
38
- "build:cjs": "tsc -p tsconfig.cjs.json",
39
- "build:esm": "tsc -p tsconfig.esm.json",
40
+ "dev": "vite build --watch",
41
+ "build": "vite build && tsc -p tsconfig.build.json",
40
42
  "clean": "rimraf dist",
41
- "lint": "eslint --ext .ts src --config eslint.config.mjs",
42
- "test": "jest",
43
- "prune": "ts-prune src",
44
- "prettier": "prettier --write 'src/**/*.ts'"
43
+ "lint": "vp lint -c ../../.oxlintrc.json src",
44
+ "fmt": "vp fmt -c ../../.oxfmtrc.json src --write",
45
+ "test": "vitest run --config ../../vitest.config.ts"
45
46
  },
46
47
  "dependencies": {
48
+ "@napi-rs/canvas": "^0.1.97",
47
49
  "@pdfme/common": "*",
48
50
  "@pdfme/pdf-lib": "*",
49
- "pdfjs-dist": "^3.11.174"
51
+ "pdfjs-dist": "^5.5.207"
50
52
  },
51
53
  "devDependencies": {
52
- "@pdfme/generator": "*",
53
- "@types/estree": "^1.0.6",
54
- "canvas": "^2.11.2"
55
- },
56
- "optionalDependencies": {
57
- "canvas": "^2.11.0"
58
- },
59
- "jest": {
60
- "resolver": "ts-jest-resolver",
61
- "moduleFileExtensions": [
62
- "js",
63
- "ts"
64
- ],
65
- "transform": {
66
- "^.+\\.ts?$": [
67
- "ts-jest",
68
- {
69
- "tsconfig": "tsconfig.esm.json"
70
- }
71
- ]
72
- },
73
- "testMatch": [
74
- "**/*.test.ts"
75
- ]
76
- },
77
- "publishConfig": {
78
- "access": "public"
54
+ "@pdfme/generator": "*"
79
55
  }
80
56
  }
@@ -1,10 +1,35 @@
1
- import * as pdfjsLib from 'pdfjs-dist';
2
- // @ts-expect-error - PDFJSWorker import is not properly typed but required for functionality
3
- import PDFJSWorker from 'pdfjs-dist/build/pdf.worker.entry.js';
1
+ import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.mjs';
4
2
  import { pdf2img as _pdf2img, Pdf2ImgOptions } from './pdf2img.js';
5
3
  import { pdf2size as _pdf2size, Pdf2SizeOptions } from './pdf2size.js';
4
+ import workerSrc from './pdfjs-worker.js?worker&url';
6
5
 
7
- pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker as unknown as string;
6
+ const clonePdfData = (pdf: ArrayBuffer | Uint8Array) =>
7
+ pdf instanceof Uint8Array ? new Uint8Array(pdf) : new Uint8Array(pdf);
8
+
9
+ const loadingTaskMap = new WeakMap<object, { destroy: () => Promise<void> }>();
10
+
11
+ const getDocument = async (pdf: ArrayBuffer | Uint8Array) => {
12
+ if (
13
+ typeof Worker !== 'undefined' &&
14
+ pdfjsLib.GlobalWorkerOptions.workerSrc !== workerSrc
15
+ ) {
16
+ pdfjsLib.GlobalWorkerOptions.workerSrc = workerSrc;
17
+ }
18
+
19
+ const loadingTask = pdfjsLib.getDocument({
20
+ data: clonePdfData(pdf),
21
+ isEvalSupported: false,
22
+ });
23
+ const document = await loadingTask.promise;
24
+ loadingTaskMap.set(document, { destroy: () => loadingTask.destroy() });
25
+ return document;
26
+ };
27
+
28
+ const destroyDocument = async (document: object) => {
29
+ const loadingTask = loadingTaskMap.get(document);
30
+ loadingTaskMap.delete(document);
31
+ await loadingTask?.destroy();
32
+ };
8
33
 
9
34
  function dataURLToArrayBuffer(dataURL: string): ArrayBuffer {
10
35
  // Split out the actual base64 string from the data URL scheme
@@ -29,7 +54,8 @@ export const pdf2img = async (
29
54
  options: Pdf2ImgOptions = {},
30
55
  ): Promise<ArrayBuffer[]> =>
31
56
  _pdf2img(pdf, options, {
32
- getDocument: (pdf) => pdfjsLib.getDocument({ data: pdf, isEvalSupported: false }).promise,
57
+ getDocument,
58
+ destroyDocument,
33
59
  createCanvas: (width, height) => {
34
60
  const canvas = document.createElement('canvas');
35
61
  canvas.width = width;
@@ -45,7 +71,8 @@ export const pdf2img = async (
45
71
 
46
72
  export const pdf2size = async (pdf: ArrayBuffer | Uint8Array, options: Pdf2SizeOptions = {}) =>
47
73
  _pdf2size(pdf, options, {
48
- getDocument: (pdf) => pdfjsLib.getDocument({ data: pdf, isEvalSupported: false }).promise,
74
+ getDocument,
75
+ destroyDocument,
49
76
  });
50
77
 
51
78
  export { img2pdf } from './img2pdf.js';
package/src/index.node.ts CHANGED
@@ -1,33 +1,45 @@
1
- import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf';
2
- // @ts-expect-error - PDFJSWorker import is not properly typed but required for functionality
3
- import PDFJSWorker from 'pdfjs-dist/legacy/build/pdf.worker.js';
4
- import { createCanvas } from 'canvas';
1
+ import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.mjs';
2
+ import { Canvas, createCanvas } from '@napi-rs/canvas';
5
3
  import { pdf2img as _pdf2img, Pdf2ImgOptions } from './pdf2img.js';
6
4
  import { pdf2size as _pdf2size, Pdf2SizeOptions } from './pdf2size.js';
5
+ import { getPdfJsWasmUrl } from './pdfjs.node.js';
7
6
 
8
- pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker as unknown as string;
7
+ const clonePdfData = (pdf: ArrayBuffer | Uint8Array) =>
8
+ pdf instanceof Uint8Array ? new Uint8Array(pdf) : new Uint8Array(pdf);
9
+ const pdfJsWasmUrl = getPdfJsWasmUrl();
9
10
 
10
11
  export const pdf2img = async (
11
12
  pdf: ArrayBuffer | Uint8Array,
12
13
  options: Pdf2ImgOptions = {},
13
- ): Promise<ArrayBuffer[]> =>
14
- _pdf2img(pdf, options, {
15
- getDocument: (pdf) => pdfjsLib.getDocument({ data: pdf, isEvalSupported: false }).promise,
14
+ ): Promise<ArrayBuffer[]> => {
15
+ return _pdf2img(pdf, options, {
16
+ getDocument: (pdf) =>
17
+ pdfjsLib.getDocument({
18
+ data: clonePdfData(pdf),
19
+ isEvalSupported: false,
20
+ wasmUrl: pdfJsWasmUrl,
21
+ }).promise,
16
22
  createCanvas: (width, height) => createCanvas(width, height) as unknown as HTMLCanvasElement,
17
- canvasToArrayBuffer: (canvas) => {
18
- // Using a more specific type for the canvas from the 'canvas' package
19
- const nodeCanvas = canvas as unknown as import('canvas').Canvas;
20
- // Get buffer from the canvas - using the synchronous version without parameters
21
- // This will use the default PNG format
22
- const buffer = nodeCanvas.toBuffer();
23
- // Convert to ArrayBuffer
24
- return new Uint8Array(buffer).buffer;
23
+ canvasToArrayBuffer: (canvas, imageType) => {
24
+ const nodeCanvas = canvas as unknown as Canvas;
25
+ const buffer =
26
+ imageType === 'png' ? nodeCanvas.toBuffer('image/png') : nodeCanvas.toBuffer('image/jpeg');
27
+ const arrayBuffer = new ArrayBuffer(buffer.byteLength);
28
+ new Uint8Array(arrayBuffer).set(buffer);
29
+ return arrayBuffer;
25
30
  },
26
31
  });
32
+ };
27
33
 
28
- export const pdf2size = async (pdf: ArrayBuffer | Uint8Array, options: Pdf2SizeOptions = {}) =>
29
- _pdf2size(pdf, options, {
30
- getDocument: (pdf) => pdfjsLib.getDocument({ data: pdf, isEvalSupported: false }).promise,
34
+ export const pdf2size = async (pdf: ArrayBuffer | Uint8Array, options: Pdf2SizeOptions = {}) => {
35
+ return _pdf2size(pdf, options, {
36
+ getDocument: (pdf) =>
37
+ pdfjsLib.getDocument({
38
+ data: clonePdfData(pdf),
39
+ isEvalSupported: false,
40
+ wasmUrl: pdfJsWasmUrl,
41
+ }).promise,
31
42
  });
43
+ };
32
44
 
33
45
  export { img2pdf } from './img2pdf.js';
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './index.browser.js';
package/src/pdf2img.ts CHANGED
@@ -3,6 +3,7 @@ import type { ImageType } from './types.js';
3
3
 
4
4
  interface Environment {
5
5
  getDocument: (pdf: ArrayBuffer | Uint8Array) => Promise<PDFDocumentProxy>;
6
+ destroyDocument?: (pdfDoc: PDFDocumentProxy) => Promise<void>;
6
7
  createCanvas: (width: number, height: number) => HTMLCanvasElement | OffscreenCanvas;
7
8
  canvasToArrayBuffer: (
8
9
  canvas: HTMLCanvasElement | OffscreenCanvas,
@@ -28,36 +29,44 @@ export async function pdf2img(
28
29
  const { scale = 1, imageType = 'jpeg', range = {} } = options;
29
30
  const { start = 0, end = Infinity } = range;
30
31
 
31
- const { getDocument, createCanvas, canvasToArrayBuffer } = env;
32
+ const { getDocument, destroyDocument, createCanvas, canvasToArrayBuffer } = env;
32
33
 
33
34
  const pdfDoc = await getDocument(pdf);
34
- const numPages = pdfDoc.numPages;
35
+ try {
36
+ const numPages = pdfDoc.numPages;
35
37
 
36
- const startPage = Math.max(start + 1, 1);
37
- const endPage = Math.min(end + 1, numPages);
38
+ const startPage = Math.max(start + 1, 1);
39
+ const endPage = Math.min(end + 1, numPages);
38
40
 
39
- const results: ArrayBuffer[] = [];
41
+ const results: ArrayBuffer[] = [];
40
42
 
41
- for (let pageNum = startPage; pageNum <= endPage; pageNum++) {
42
- const page = await pdfDoc.getPage(pageNum);
43
- const viewport = page.getViewport({ scale });
43
+ for (let pageNum = startPage; pageNum <= endPage; pageNum++) {
44
+ const page = await pdfDoc.getPage(pageNum);
45
+ const viewport = page.getViewport({ scale });
44
46
 
45
- const canvas = createCanvas(viewport.width, viewport.height);
46
- if (!canvas) {
47
- throw new Error('Failed to create canvas');
48
- }
47
+ const canvas = createCanvas(viewport.width, viewport.height);
48
+ if (!canvas) {
49
+ throw new Error('Failed to create canvas');
50
+ }
51
+
52
+ const context = canvas.getContext('2d') as CanvasRenderingContext2D;
53
+ if (!context) {
54
+ throw new Error('Failed to get canvas context');
55
+ }
49
56
 
50
- const context = canvas.getContext('2d') as CanvasRenderingContext2D;
51
- if (!context) {
52
- throw new Error('Failed to get canvas context');
57
+ await page.render({
58
+ canvas: canvas as unknown as HTMLCanvasElement,
59
+ canvasContext: context,
60
+ viewport,
61
+ }).promise;
62
+ const arrayBuffer = canvasToArrayBuffer(canvas, imageType);
63
+ results.push(arrayBuffer);
53
64
  }
54
65
 
55
- await page.render({ canvasContext: context, viewport }).promise;
56
- const arrayBuffer = canvasToArrayBuffer(canvas, imageType);
57
- results.push(arrayBuffer);
66
+ return results;
67
+ } finally {
68
+ await destroyDocument?.(pdfDoc);
58
69
  }
59
-
60
- return results;
61
70
  } catch (error) {
62
71
  throw new Error(`[@pdfme/converter] pdf2img failed: ${(error as Error).message}`);
63
72
  }
package/src/pdf2size.ts CHANGED
@@ -3,6 +3,7 @@ import { Size, pt2mm } from '@pdfme/common';
3
3
 
4
4
  interface Environment {
5
5
  getDocument: (pdf: ArrayBuffer | Uint8Array) => Promise<PDFDocumentProxy>;
6
+ destroyDocument?: (pdfDoc: PDFDocumentProxy) => Promise<void>;
6
7
  }
7
8
 
8
9
  export interface Pdf2SizeOptions {
@@ -15,19 +16,20 @@ export async function pdf2size(
15
16
  env: Environment,
16
17
  ): Promise<Size[]> {
17
18
  const { scale = 1 } = options;
18
- const { getDocument } = env;
19
-
19
+ const { getDocument, destroyDocument } = env;
20
20
  const pdfDoc = await getDocument(pdf);
21
21
 
22
- const promises = Promise.all(
23
- new Array(pdfDoc.numPages).fill('').map(async (_, i) => {
24
- return await pdfDoc.getPage(i + 1).then((page) => {
25
- const { height, width } = page.getViewport({ scale, rotation: 0 });
26
-
27
- return { height: pt2mm(height), width: pt2mm(width) };
28
- });
29
- }),
30
- );
22
+ try {
23
+ return await Promise.all(
24
+ Array.from({ length: pdfDoc.numPages }, async (_, i) => {
25
+ return await pdfDoc.getPage(i + 1).then((page) => {
26
+ const { height, width } = page.getViewport({ scale, rotation: 0 });
31
27
 
32
- return promises;
28
+ return { height: pt2mm(height), width: pt2mm(width) };
29
+ });
30
+ }),
31
+ );
32
+ } finally {
33
+ await destroyDocument?.(pdfDoc);
34
+ }
33
35
  }
@@ -0,0 +1,20 @@
1
+ declare module 'pdfjs-dist/webpack.mjs' {
2
+ export * from 'pdfjs-dist';
3
+ }
4
+
5
+ declare module 'pdfjs-dist/build/pdf.mjs' {
6
+ export * from 'pdfjs-dist';
7
+ }
8
+
9
+ declare module 'pdfjs-dist/build/pdf.worker.mjs';
10
+
11
+ declare module 'pdfjs-dist/legacy/build/pdf.mjs' {
12
+ export * from 'pdfjs-dist';
13
+ }
14
+
15
+ declare module 'pdfjs-dist/legacy/build/pdf.worker.mjs';
16
+
17
+ declare module '*?worker&url' {
18
+ const workerUrl: string;
19
+ export default workerUrl;
20
+ }
@@ -0,0 +1,20 @@
1
+ const uint8ArrayPrototype = Uint8Array.prototype as Uint8Array & {
2
+ toHex?: () => string;
3
+ };
4
+
5
+ if (!uint8ArrayPrototype.toHex) {
6
+ Object.defineProperty(Uint8Array.prototype, 'toHex', {
7
+ configurable: true,
8
+ value(this: Uint8Array) {
9
+ let result = '';
10
+
11
+ for (let i = 0; i < this.length; i += 1) {
12
+ const hex = this[i].toString(16);
13
+ result += hex.length === 1 ? `0${hex}` : hex;
14
+ }
15
+
16
+ return result;
17
+ },
18
+ writable: true,
19
+ });
20
+ }
@@ -0,0 +1,2 @@
1
+ import './pdfjs-worker-shim.js';
2
+ import 'pdfjs-dist/legacy/build/pdf.worker.mjs';
@@ -0,0 +1,7 @@
1
+ import { createRequire } from 'node:module';
2
+ import { dirname, join } from 'node:path';
3
+
4
+ const require = createRequire(import.meta.url);
5
+ const pdfJsDistRoot = dirname(require.resolve('pdfjs-dist/package.json'));
6
+
7
+ export const getPdfJsWasmUrl = (): string => join(pdfJsDistRoot, 'wasm/');
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "../../tsconfig.build.base.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "declarationDir": "./dist",
6
+ "emitDeclarationOnly": true,
7
+ "module": "ESNext",
8
+ "moduleResolution": "bundler",
9
+ "outDir": "./dist",
10
+ "rootDir": "./src",
11
+ "skipLibCheck": true
12
+ },
13
+ "include": ["src/**/*.ts", "src/**/*.d.ts"]
14
+ }
package/tsconfig.json CHANGED
@@ -1,6 +1,16 @@
1
1
  {
2
- "extends": "./tsconfig.esm",
2
+ "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "outDir": "./dist",
5
- }
6
- }
4
+ "composite": true,
5
+ "declaration": true,
6
+ "declarationDir": "./dist/typecheck",
7
+ "emitDeclarationOnly": true,
8
+ "module": "ESNext",
9
+ "moduleResolution": "bundler",
10
+ "outDir": "./dist/typecheck",
11
+ "tsBuildInfoFile": "./dist/typecheck/tsconfig.tsbuildinfo",
12
+ "skipLibCheck": true
13
+ },
14
+ "include": ["src/**/*.ts", "src/**/*.d.ts"],
15
+ "references": [{ "path": "../common" }, { "path": "../pdf-lib" }]
16
+ }
@@ -0,0 +1,70 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { builtinModules } from 'node:module';
3
+ import { dirname, resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { defineConfig } from 'vite';
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const packageJson = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf8')) as {
9
+ dependencies?: Record<string, string>;
10
+ peerDependencies?: Record<string, string>;
11
+ };
12
+
13
+ const builtinModuleSet = new Set([
14
+ ...builtinModules,
15
+ ...builtinModules.map((moduleName) => `node:${moduleName}`),
16
+ ]);
17
+ const packageDependencies = [
18
+ ...Object.keys(packageJson.dependencies ?? {}),
19
+ ...Object.keys(packageJson.peerDependencies ?? {}),
20
+ ];
21
+ const pdfjsWorkerCompatBanner = [
22
+ 'const pdfmeUint8ArrayPrototype = Uint8Array.prototype;',
23
+ 'if (!pdfmeUint8ArrayPrototype.toHex) {',
24
+ " Object.defineProperty(Uint8Array.prototype, 'toHex', {",
25
+ ' configurable: true,',
26
+ ' value() {',
27
+ " let result = '';",
28
+ ' for (let i = 0; i < this.length; i += 1) {',
29
+ ' const hex = this[i].toString(16);',
30
+ ' result += hex.length === 1 ? `0${hex}` : hex;',
31
+ ' }',
32
+ ' return result;',
33
+ ' },',
34
+ ' writable: true,',
35
+ ' });',
36
+ '}',
37
+ ].join('\n');
38
+
39
+ const isExternal = (id: string) =>
40
+ builtinModuleSet.has(id) ||
41
+ packageDependencies.some((dependency) => id === dependency || id.startsWith(`${dependency}/`));
42
+
43
+ export default defineConfig(() => {
44
+ return {
45
+ base: './',
46
+ build: {
47
+ lib: {
48
+ entry: {
49
+ index: resolve(__dirname, 'src/index.browser.ts'),
50
+ 'index.node': resolve(__dirname, 'src/index.node.ts'),
51
+ },
52
+ fileName: (_, entryName) => `${entryName}.js`,
53
+ formats: ['es'],
54
+ },
55
+ minify: false,
56
+ outDir: 'dist',
57
+ rollupOptions: { external: isExternal },
58
+ sourcemap: true,
59
+ target: 'es2020',
60
+ },
61
+ worker: {
62
+ format: 'es',
63
+ rollupOptions: {
64
+ output: {
65
+ banner: pdfjsWorkerCompatBanner,
66
+ },
67
+ },
68
+ },
69
+ };
70
+ });